Posted: Mon Jan 29, 2007 8:52 pm
Wow, it looks like you guys had a blast doing the throw-down. Congrats to you all for slugging it out for those 24 hours. Looks like I missed it. :-/ Maybe I could still help out with the app...
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
If it was so "SIMPLE" why did you hard code the sql? Why didn't you do it the more robust way and load from an external SQL file? Now we have extra work to do every time we change/alter the DB and it don't support the installing of exported SQL data... I wasn't gonna say anything and was just gonna reprogram it myself but since I'm just a little smurf (thats how you spell it right?) I thought I'd post it.ole wrote:Adding the SQL was relatively simple....yes that's right 'was'. I've commited an update. I haven't tested it though. I found a couple of good chunks of duplication in my code whilst I was in there, clearly shows I wasn't thinking very well at all.
I hope you're happy now you little f...No comment. *cough* Still don't handle SQL Installations *cough*
Yeah you did but I wanted to do it anyway. I didn't have anything to do tonight.um... perhaps I should have told you that we don't need a installation script anymore. The software has now found a permanent residence on flashcardr.com.
Nah I called you a little <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>, I think we're even now.Please don't kill me. <runs />
Meh, I'll do a bit every now and then. Right now I'm having a think about this DOM code we seem to have lots of. This isn't at all refactored on many levels. Firstly we have blocks like this appearing in multiple controller actionssweet! Let's not let this project fade into obscurity!
Code: Select all
$user = Zend::Registry('stateMain')->getUser();
$doc = new DOMDocument();
$root = $doc->createElement('root');
$doc->appendChild($root);
$indexElement = $root->appendChild($doc->createElement('indexElement'));
$indexElement->setAttribute('msg', 'Welcome back, ' . $user['user_name'] . '!');
$indexElement->setAttribute('calledFrom', 'IndexController::portalAction()');
$outputElement = $root->appendChild($doc->createElement('output'));
$action = $outputElement->appendChild($doc->createElement('action', 'index'));
$card = $outputElement->appendChild($doc->createElement('debug', 'true'));
echo Zend::registry('transformer')->transformFromDom($doc);Code: Select all
<!-- want to generate this -->
<inventory>
<book title="MySQL Cookbook" author="Paul DuBois"/>
<book title="Essential PHP Security" author="Chris Shifflet"/>
<tool type="wrench" weight="8543g" bloodstained="true"/>
<person gender="m" name="ole" state="gah" />
</inventory>Code: Select all
// From this
$books = array(
array(
'title' => 'MySQL Cookbook',
'author' => 'Paul DuBois',
),
array(
'title' => 'Essential PHP Security',
'author' => 'Chris Shifflet',
),
);
$tools = array(
array(
'type' => 'wrench',
'weight' => '8543g',
'bloodstained' => 'true'
)
);
$persons = array(
array(
'gender' => 'm',
'name' => 'ole',
'state' => 'gah',
)
);Code: Select all
// So we do this, nice and concise
$doc = new oleDomDocument();
$doc->appendChild($root = $doc->createElement('inventory'));
$mapping = array('book' => $books, 'tool' => $tools, 'person' => $persons);
$numRows = 0;
foreach ($mapping as $elementName => $data) {
$numRows+= $doc->appendAttributedElementsTo($elementName, $data, $root);
}
$root->setAttribute('rows', $numRows);
echo $doc->saveXML();Code: Select all
// With the help of this
class oleDomDocument extends DOMDocument
{
public function createAttributedElement($element, array $attributes, $value = null)
{
$element = $this->createElement($element, $value);
foreach ($attributes as $name => $value) {
$element->setAttribute($name, $value);
}
return $element;
}
public function appendAttributedElementsTo($element, array $attributeSets, DOMNode $toAppend)
{
for ($i = 0, $j = count($attributeSets); $i < $j; ++$i) {
$toAppend->appendChild(
$this->createAttributedElement($element, $attributeSets[$i])
);
}
return $i;
}
}My head!!!! I thought you said you weren't mad about the SQL thing!!! What's the number to 911!ole wrote: <tool type="wrench" weight="8543g" bloodstained="true"/>
You guys crack me upDaveTheAve wrote:My head!!!! I thought you said you weren't mad about the SQL thing!!! What's the number to 911!ole wrote:<tool type="wrench" weight="8543g" bloodstained="true"/>
Code: Select all
$doc = new Document;
$o = new Test;
$o->bob='frank';
$o->bob='joe';
$o->something='bob';
$o->something=array('else',array('id'=>'5'),true);
$o->save();Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<xml>
<test thing_id="3" node_id="8">
<bob node_id="9">joe</bob>
<something node_id="10">bob</something>
<something id="5" node_id="11">else</something>
</test>
</xml>Because that is how I always envisaged it. So I didn't really give it any thought. I've fixed that now.If it was so "SIMPLE" why did you hard code the sql?
I'm not going to do that.Feel free to do it back to me if you wish
Thanks Dave. Lets try and avoid these things in future.i'll stop bothering you about it, promise