Page 2 of 3

Posted: Mon Jan 29, 2007 8:52 pm
by Ambush Commander
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...

Posted: Mon Jan 29, 2007 9:30 pm
by DaveTheAve
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.
No comment. *cough* Still don't handle SQL Installations *cough*
I hope you're happy now you little f... :P
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.

Posted: Mon Jan 29, 2007 9:36 pm
by Ollie Saunders
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.
Yeah you did but I wanted to do it anyway. I didn't have anything to do tonight.
Please don't kill me. <runs />
Nah I called you a little <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>, I think we're even now. :)
sweet! Let's not let this project fade into obscurity!
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 actions

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);
I recon we need one level above DOM for mapping arrays and database output to the DOM easily and a level above that for prefabricated structures etc. Such as this output element which appears in every single action.

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;
    }
}
This isn't perfect by any means, for example: This couldn't cope with making 'title' a value instead of an attribute for example. But this just shows how a level above DOM could really help clean this stuff up. Also we don't have to be as wary of over-generalization as in other scenarios because this stuff is going to XSLT which can pretty much cope with any structure at all.

Posted: Mon Jan 29, 2007 9:44 pm
by DaveTheAve
ole wrote: <tool type="wrench" weight="8543g" bloodstained="true"/>
My head!!!! I thought you said you weren't mad about the SQL thing!!! What's the number to 911!

Posted: Tue Jan 30, 2007 12:21 am
by Kieran Huggins
DaveTheAve wrote:
ole wrote:<tool type="wrench" weight="8543g" bloodstained="true"/>
My head!!!! I thought you said you weren't mad about the SQL thing!!! What's the number to 911!
You guys crack me up :rofl: I totally missed that in the example code :-)

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();
Producing:

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>
I'll send you the classes if you're interested - I'd love to have your input.

Posted: Tue Jan 30, 2007 3:32 am
by Ollie Saunders
Kieran, send away, looks very interesting
If it was so "SIMPLE" why did you hard code the sql?
Because that is how I always envisaged it. So I didn't really give it any thought. I've fixed that now.

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?

Posted: Tue Jan 30, 2007 7:09 am
by DaveTheAve
My mistake Ole, I didn't mean to insult you in any-way. I'll stop promise, I thought thought it was funny and you'd get a kick out of it. Feel free to do it back to me if you wish; however, i'll stop bothering you about it, promise.

Posted: Tue Jan 30, 2007 7:15 am
by Ollie Saunders
Feel free to do it back to me if you wish
I'm not going to do that.
i'll stop bothering you about it, promise
Thanks Dave. Lets try and avoid these things in future.

Posted: Sat Feb 03, 2007 6:31 am
by Ollie Saunders
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.

Posted: Sat Feb 03, 2007 9:34 am
by DaveTheAve
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.

Posted: Tue Feb 06, 2007 1:31 am
by Kieran Huggins
Coool! I knew I should have searched PEAR before writing my own...

Posted: Tue Feb 06, 2007 2:35 am
by Christopher
When do they announce the Throwdown results?

Posted: Tue Feb 06, 2007 3:56 am
by Ollie Saunders
What, do you think we could win or something? lol
Sorry.

It'll be a while because a lot of teams competedm they have to judge many factors and there is only 5 judges or so.

Posted: Tue Feb 27, 2007 1:43 pm
by Kieran Huggins
Guys - we weren't as original as we thought :-) : http://quizlet.com

Posted: Tue Feb 27, 2007 2:42 pm
by RobertGonzalez
Dayum that is a clean web site!