PHP Throwdown - debriefing!
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
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*
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
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);Here's something I just knocked up now:
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;
}
}- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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"/>
Incidentally, I've written some replacement DOM objects that sort of bridge the gap towards simpleXML that look like this:
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>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Kieran, send away, looks very interesting
Hey Dave, if you are going to give me a hard time everytime I get something wrong then things aren't going to be as easy as they could be. All programmers make mistakes and bad decisions, maybe I make more than the average. But any programmer worth his salt has to be able to take and give criticism responsibly -- that means not make an issue out of it. You seem to be worried that I can't take criticism with your "</ runs>" and "do look at" but I assure you I have no problem with my mistakings being pointed out. I've got a problem with people rubbing them in my face.
My interest in continuing this project is threatened by your attitude. If that is what you want then just say so, I won't be mad, otherwise by all means mention my mistakes but not in a slandering or aggressive fashion. Is that ok?
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?
Hey Dave, if you are going to give me a hard time everytime I get something wrong then things aren't going to be as easy as they could be. All programmers make mistakes and bad decisions, maybe I make more than the average. But any programmer worth his salt has to be able to take and give criticism responsibly -- that means not make an issue out of it. You seem to be worried that I can't take criticism with your "</ runs>" and "do look at" but I assure you I have no problem with my mistakings being pointed out. I've got a problem with people rubbing them in my face.
My interest in continuing this project is threatened by your attitude. If that is what you want then just say so, I won't be mad, otherwise by all means mention my mistakes but not in a slandering or aggressive fashion. Is that ok?
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
OOohh guys look at this.
I'm literally just posting this in with only a glance at it so sorry if its no good.
This illustrates what it does a bit better.
I'm literally just posting this in with only a glance at it so sorry if its no good.
This illustrates what it does a bit better.
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
Hummmmmm... its been revision 263 for quite some time.... wonder if I should break the no-update-streak by building that DOM class i was talking about.... ether that or work on my proxy server today.
EDIT: Now that I look more closely I notice it handles XML too like that, if you want to use that for the site please feel free to show me a demo. If you want once i see the demo i can create the XML class for you or if you want i'm cool with that too. Nice find BTW.
EDIT: Now that I look more closely I notice it handles XML too like that, if you want to use that for the site please feel free to show me a demo. If you want once i see the demo i can create the XML class for you or if you want i'm cool with that too. Nice find BTW.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Guys - we weren't as original as we thought
: http://quizlet.com
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA