<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Weblog van Paul de Raaij &#187; Webdevelopment</title>
	<atom:link href="http://www.paulderaaij.nl/category/webdevelopment/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paulderaaij.nl</link>
	<description>Algemeen weblog van Paul de Raaij</description>
	<lastBuildDate>Fri, 03 Feb 2012 11:19:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Valideren elfproef met jquery.validate</title>
		<link>http://www.paulderaaij.nl/2011/06/10/valideren-elfproef-met-jquery-validate/</link>
		<comments>http://www.paulderaaij.nl/2011/06/10/valideren-elfproef-met-jquery-validate/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 09:39:18 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[elfproef]]></category>
		<category><![CDATA[jquery.vlidate]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=230</guid>
		<description><![CDATA[Aangezien ik iedere keer weer een custom validatie op bankrekeningnummers moest schrijven, werd het maar eens tijd om het in het digitale archief te plaatsen. Wellicht heeft iemand er nog wat aan&#8230; jQuery.validator.addMethod("elfproef", function(value, element) { var sum=0; for (i=1; i]]></description>
			<content:encoded><![CDATA[<p>Aangezien ik iedere keer weer een custom validatie op bankrekeningnummers moest schrijven, werd het maar eens tijd om het in het digitale archief te plaatsen. Wellicht heeft iemand er nog wat aan&#8230;</p>
<p><code><br />
jQuery.validator.addMethod("elfproef", function(value, element) {<br />
	var sum=0;<br />
	for (i=1; i<10; i++) {<br />
		amount=value.charAt(i-1);<br />
		sum+=amount*(10-i);<br />
	} </p>
<p>	if (sum % 11==0 &#038;&#038; value.length==9) {<br />
		return true<br />
	} else {<br />
		return false<br />
	}<br />
}, "Vul hier een geldige bankrekeningnummer in.");<br />
</code></p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2011%2F06%2F10%2Fvalideren-elfproef-met-jquery-validate%2F&amp;title=Valideren%20elfproef%20met%20jquery.validate"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2011/06/10/valideren-elfproef-met-jquery-validate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Doctrine in Joomla</title>
		<link>http://www.paulderaaij.nl/2011/03/05/using-doctrine-in-joomla/</link>
		<comments>http://www.paulderaaij.nl/2011/03/05/using-doctrine-in-joomla/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 14:44:19 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[joomla]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=213</guid>
		<description><![CDATA[Joomla is a decent CMS with very nice features. It works great for the end user and has many components ready to use from the online world. What I don&#8217;t like personally, as a developer, is the model implementation in Joomla. For me the way &#8216; model and table&#8217; classes are implemented, just doesn&#8217;t feel [...]]]></description>
			<content:encoded><![CDATA[<p>Joomla is a decent CMS with very nice features. It works great for the end user and has many components ready to use from the online world. What I don&#8217;t like personally, as a developer, is the model implementation in Joomla. For me the way &#8216; model and table&#8217; classes are implemented, just doesn&#8217;t feel right to me. Also it is very difficult to get other models in a controller or an other model class.</p>
<p><span id="more-213"></span></p>
<p>With Symfony I have worked with Doctrine regularly and in this blog I&#8217;ll show you how to use Doctrine for your own component in Joomla. Doctrine is an Object Relational  Mapping framework and offers you a persistence library. This not the holy grail and you should determine  if you need the extra overhead and if you are comfortable with it.</p>
<h2>The first step</h2>
<p>I&#8217;ll start with an clean Joomla 1.6 install from the Joomla website. Also I installed <a href="http://www.doctrine-project.org/projects/orm/download">Doctrine ORM</a> from the Doctrine website. I unpacked the archive in  a new folder in the Joomla folder libraries.The structure in this new folder would be the same as the archive, so you get a Doctrine folder and a bin folder in the libraries/doctrine folder.</p>
<p>By the way, we live in 2011 and the current release of PHP is 5.3.5. Doctrine and the implementation I show you here assumes you use PHP 5.3. If you still use PHP 5.2 you seriously need to work on the upgrade of that projects.</p>
<h2>The example</h2>
<p>I&#8217;m going to provide you a very simple example. The most important thing I want to show you is how to implement Doctrine in your Joomla project, not how to use Doctrine. The documentation on the Doctrine website is of high quality and should give you enough information to get going.</p>
<p>We are writing a new component called Bugs end hold one entity called &#8216;Bug&#8217;. It has five attributes. ID, title, description, notificationDate and solvedDate. In the controller I&#8217;ll show you some examples how to use it.</p>
<h2>Setting up the defaults</h2>
<p>It is possible that you want to use Doctrine on multiple components you are going to write. This is the reason why I choose to add Doctrine to the libraries folder. In this folder we are going to add two files. One is an interface to provide a generic interface, the other is a bootstrapper to get Doctrine going. First the easy stuff, the interface.</p>
<p>The interface looks like this:</p>
<pre class="brush: php; title: ;">

&lt;?php

interface JoomlaDoctrineController {
public function setEntityManager(Doctrine\ORM\EntityManager $entityManager);
}

?&gt;
</pre>
<p>Nothing spectacular  here, lets move on.</p>
<p>Doctrine needs to have some basic configuration to get going. We need to tell Doctrine where it can find the entities and where it needs to place the generated proxies. Here is the implementation of JoomlaDoctrineBootstrapper:</p>
<pre class="brush: php; title: ;">
&lt;?php
/**
 * Configuration class to integrate Doctrine into Joomla.
 *
 * @author pderaaij &lt;paul@paulderaaij.nl&gt;
 */

use Doctrine\Common\ClassLoader,
    Doctrine\ORM\EntityManager,
    Doctrine\ORM\Configuration,
   Doctrine\Common\Cache\ArrayCache;

if( !class_exists('\Doctrine\Common\Classloader')) {
    require_once dirname(__FILE__) . '/../doctrine/Doctrine/Common/ClassLoader.php';
}

class JoomlaDoctrineBootstrapper {

    const APP_MODE_DEVELOPMENT = 1;
    const APP_MODE_PRODUCTION  = 2;

    private $applicationMode;
    private $cache;
    private $entityLibrary;
    private $proxyLibrary;
    private $proxyNamespace;
    private $entityManager;
    private $connectionOptions;

    public function __construct($applicationMode) {
        $this-&gt;applicationMode = $applicationMode;
    }

    public function getConnectionOptions() {
        return $this-&gt;connectionOptions;
    }

    public function setConnectionOptions($connectionOptions) {
        $this-&gt;connectionOptions = $connectionOptions;
    }

    public function getProxyLibrary() {
        return $this-&gt;proxyLibrary;
    }

    public function setProxyLibrary($proxyLibrary) {
        $this-&gt;proxyLibrary = $proxyLibrary;
    }

    public function getProxyNamespace() {
        return $this-&gt;proxyNamespace;
    }

    public function setProxyNamespace($proxyNamespace) {
        $this-&gt;proxyNamespace = $proxyNamespace;
    }

    public function getCache() {
        return $this-&gt;cache;
    }

    public function setCache($cache) {
        $this-&gt;cache = $cache;
    }

    public function getEntityLibrary() {
        return $this-&gt;entityLibrary;
    }

    public function setEntityLibrary($entityLibrary) {
        $this-&gt;entityLibrary = $entityLibrary;
    }

    public function getApplicationMode() {
        return $this-&gt;applicationMode;
    }

    public function setApplicationMode($applicationMode) {
        $this-&gt;applicationMode = $applicationMode;
    }

    public function getEntityManager() {
        return $this-&gt;entityManager;
    }

    public function setEntityManager($entityManager) {
        $this-&gt;entityManager = $entityManager;
    }

    /**
     * Bootstrap Doctrine, setting the libraries and namespaces and creating
     * the entitymanager
     */
    public function bootstrap() {
        $this-&gt;registerClassLoader();

        // Load cache
        if ($this-&gt;getApplicationMode() == self::APP_MODE_DEVELOPMENT) {
            $this-&gt;cache = new ArrayCache;
        } else {
            $this-&gt;cache = new ApcCache;
        }

        /** @var $config Doctrine\ORM\Configuration */
        $config = new Configuration;
        $config-&gt;setMetadataCacheImpl($this-&gt;cache);
        $driverImpl = $config-&gt;newDefaultAnnotationDriver($this-&gt;getEntityLibrary());

        $config-&gt;setMetadataDriverImpl($driverImpl);
        $config-&gt;setQueryCacheImpl($this-&gt;cache);
        $config-&gt;setProxyDir($this-&gt;getProxyLibrary());
        $config-&gt;setProxyNamespace($this-&gt;getProxyNamespace());

        if ($this-&gt;applicationMode == self::APP_MODE_DEVELOPMENT) {
            $config-&gt;setAutoGenerateProxyClasses(true);
        } else {
            $config-&gt;setAutoGenerateProxyClasses(false);
        }

        $this-&gt;entityManager = EntityManager::create($this-&gt;getConnectionOptions(), $config);
    }

    /**
     * Register the different classloaders for each type.
     */
    private function registerClassLoader() {
        // Autoloader for all the Doctrine library files
        $classLoader = new ClassLoader('Doctrine', dirname(__FILE__) . '/');
        $classLoader-&gt;register();

        // Autoloader for all Entities
        $modelLoader = new ClassLoader('Entities', $this-&gt;getEntityLibrary());
        $modelLoader-&gt;register();

        // Autoloader for all Proxies
        $proxiesClassLoader = new ClassLoader('Proxies', $this-&gt;getProxyLibrary());
        $proxiesClassLoader-&gt;register();
    }

}
?&gt;</pre>
<div>Okay, what&#8217;s going on here. As said earlier we are expecting an PHP 5.3 application, so we are making a lot of use of namespaces here. We are loading some base classes of Doctrine so we can bootstrap it.</div>
<div>You see two constants in this class. These constants are flags you can use to set the environment the application is in. Is the application is used in a production environment it will make use of the APC cache. In development it will use a simple ArrayCache which is volatile.</div>
<div>If we skip the getters and setters we see two interesting functions. The first one is registerClassLoader. Here we register three classloaders. The first one is used to auto load all Doctrine classes. The second one we use for the entities we created. The proxies are auto loaded by the third class loader. The argument the last two classloaders receive are just absolute paths to the folder containing the belonging files.</div>
<div>In the bootstrap function we define the configuration for Doctrine. We define the cache it needs to use, the AnnotationDriver and the folders where Doctrine can find proxies and entities. To learn more about this configuration you should read the Doctrine manual. What we do here is a standard configuration, setting the right locations.</div>
<h2>Creating the component</h2>
<p>Now we can start with setting up our component. Create a com_bugs folder in components with a models folder in it. In the models folder you should create an Entities folder (mind the capital, it&#8217;s important!).</p>
<p>Create the &#8216;Bug&#8217; entity next. Copy the text below and place it in Bug.php in the models/Entities folder. Do not forget to set the namespace it is essential. If you forget it the entity can&#8217;t be found by the classloader. This is also the reason why the capitalization is so important.</p>
<pre class="brush: php; title: ;">

&lt;?php

namespace Entities;

/**

* @Entity @Table(name=&quot;bugs&quot;)

*/

class Bug {

/** @Id @Column(type=&quot;integer&quot;) @GeneratedValue */

private $id;

/** @Column(type=&quot;string&quot;) */

private $title;

/** @Column(type=&quot;string&quot;) */

private $description;

/** @Column(type=&quot;datetime&quot;) */

private $notificationDate;

/** @Column(type=&quot;datetime&quot;) */

private $solvedDate;

public function getId() {

return $this-&gt;id;

}

public function setId($id) {

$this-&gt;id = $id;

}

public function getTitle() {

return $this-&gt;title;

}

public function setTitle($title) {

$this-&gt;title = $title;

}

public function getDescription() {

return $this-&gt;description;

}

public function setDescription($description) {

$this-&gt;description = $description;

}

public function getNotificationDate() {

return $this-&gt;notificationDate;

}

public function setNotificationDate($notificationDate) {

$this-&gt;notificationDate = $notificationDate;

}

public function getSolvedDate() {

return $this-&gt;solvedDate;

}

public function setSolvedDate($solvedDate) {

$this-&gt;solvedDate = $solvedDate;

}

}

?&gt;
</pre>
<p>There is our entity! Now we need a way to get that entity definition in our database. Doctrine has command-line tools for us to do that, but they need the same configuration as we give to our controller in the front-end. So, lets set-up that configuration and use it on the command line.</p>
<h2>The configuration</h2>
<p>In order to use Doctrine within our controllers we have to create the configuration and use our created bootstrapper to get Doctrine going. At the moment I chose the component initialization file for our initialization work on Doctrine. I&#8217;m looking for a way to extract this initialization in to a nicer place, but the options I&#8217;ve tried didn&#8217;t made me happy at all.</p>
<p>What do we need to do? Well, we need to tell where our entities are stored on the file system and where we want to store our proxy files. also we need to pass our database parameters to Doctrine so it has authorization to the database. Here is my init file (bugs.php) of the component:</p>
<pre class="brush: php; title: ;">
&lt;?php
// no direct access
defined('_JEXEC') or die;

// Include dependancies
jimport('joomla.application.component.controller');

require_once(JPATH_LIBRARIES . '/doctrine/bootstrap.php');

$controller = JController::getInstance('Bugs');
// configure Doctrine thru the bootstrapper
$controller-&gt;setEntityManager(bootstrapDoctrine());
$controller-&gt;execute(JRequest::getCmd('task', 'index'));
$controller-&gt;redirect();

/**
 * Initialize doctrine by setting the entities and proxies locaties. Also define
 * a default namespace for the proxies.
 */
function bootstrapDoctrine() {
    $doctrineProxy = new JoomlaDoctrineBootstrapper( JoomlaDoctrineBootstrapper::APP_MODE_DEVELOPMENT );
    $doctrineProxy-&gt;setEntityLibrary(dirname(__FILE__) . '/models');
    $doctrineProxy-&gt;setProxyLibrary(dirname(__FILE__) . '/proxies');
    $doctrineProxy-&gt;setProxyNamespace('Joomla\Proxies');
    $doctrineProxy-&gt;setConnectionOptions(getConfigurationOptions());
    $doctrineProxy-&gt;bootstrap();

    return $doctrineProxy-&gt;getEntityManager();
}

function getConfigurationOptions() {
     // Define database configuration options
    $joomlaConfig = JFactory::getConfig();
    return array(
        'driver' =&gt; 'pdo_mysql',
        'path' =&gt; 'database.mysql',
        'dbname' =&gt; $joomlaConfig-&gt;get('db'),
        'user' =&gt;  $joomlaConfig-&gt;get('user'),
        'password' =&gt;  $joomlaConfig-&gt;get('password')
    );
}
</pre>
<p>What do we do here. We retrieve an instance of our controller and our going to inject an EntityManager to this controller. In order to this we are going to call the JoomlaDoctrineBootstrapper, set the configuration parameters and it will return us the EntityManager. To make the configuration and use a little easier we are using the database credentials from the Joomla configuration.</p>
<p>That&#8217;s nice for the front-end, but how about that command line tool? Well Doctrine will search for a file called &#8216;cli-config.php&#8217; on the location you call the doctrine command line tool. The file &#8216;cli-config.php&#8217; will return an EntityManager using the configuration we set from our bootstrap file.</p>
<p>Before we start sorting out this file, a little notice. This file is somewhat strange. We have to perform a number of tricks so we can make use of the Joomla framework on the command line. The way we do use led to the fact we need a separate configuration file containing the database credentials and other configuration options. I&#8217;m sure that a number of trick I use here aren&#8217;t necessary, but I just can&#8217;t find a better way to do this. If you know the trick, please let me know. I, for sure, don&#8217;t like the way this file has been built up and would love to improve it.</p>
<p>Now with that out, I&#8217;ll show you the file.</p>
<pre class="brush: php; title: ;">
&lt;?php
// We are a valid Joomla entry point.
define('_JEXEC', 1);

// Setup the path related constants.
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', __DIR__ . '/../../');
define('JPATH_ROOT', JPATH_BASE);
define('JPATH_CONFIGURATION', JPATH_BASE);
define('JPATH_LIBRARIES', JPATH_BASE.DS.'libraries');
define('JPATH_METHODS', JPATH_ROOT.DS.'methods');

// Load the library importer.
require_once (JPATH_LIBRARIES.'/joomla/import.php');
require_once (JPATH_CONFIGURATION.'/configuration.php');

// Import library dependencies.
jimport('joomla.application.application');
jimport('joomla.utilities.utility');
jimport('joomla.language.language');
jimport('joomla.utilities.string');
jimport('joomla.factory');

require_once __DIR__ . '/../../libraries/doctrine/bootstrap.php';

/**
 * Initialize doctrine by setting the entities and proxies locaties. Also define
 * a default namespace for the proxies.
 */
function bootstrapDoctrine() {
    $doctrineProxy = new JoomlaDoctrineBootstrapper( JoomlaDoctrineBootstrapper::APP_MODE_DEVELOPMENT );
    $doctrineProxy-&gt;setEntityLibrary(dirname(__FILE__) . '/models');
    $doctrineProxy-&gt;setProxyLibrary(dirname(__FILE__) . '/proxies');
    $doctrineProxy-&gt;setProxyNamespace('Joomla\Proxies');
    $doctrineProxy-&gt;setConnectionOptions(getConfigurationOptions());
    $doctrineProxy-&gt;bootstrap();

    return $doctrineProxy-&gt;getEntityManager();
}

function getConfigurationOptions() {
     // Define database configuration options
    $joomlaConfig = JFactory::getConfig(JPATH_BASE . '/cli-configuration.php');
    return array(
        'driver' =&gt; 'pdo_mysql',
        'path' =&gt; 'database.mysql',
        'dbname' =&gt; $joomlaConfig-&gt;get('db'),
        'user' =&gt;  $joomlaConfig-&gt;get('user'),
        'password' =&gt;  $joomlaConfig-&gt;get('password')
    );
}

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'em' =&gt; new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper(bootstrapDoctrine())
));
</pre>
<p>The first part of the file is just bootstrapping of the Joomla framework. We determine the location of some core folders, we import core classes and all that will bootstrap the Joomla Framework. Then two function follow that we have seen before. The only difference is that we can&#8217;t use the default configuration, which will give us an blank configuration class, but an alternative file. Why not the default file? Well the default file is of the type JConfig and the factory expects an JFrameworkConfig to import.</p>
<p>The bottom three lines are the default code of Doctrine to get the command line tools going. You see, the only thing we do here is setting the EntityManager. More information about this file can be found on the Doctrine website.</p>
<h2>The last mile</h2>
<p>It has been a long way already, but we are getting there.The last thing I&#8217;m going to show you is how to make use of the Doctrine. If you remember we have created an interface earlier in this blog. Just implement this on your controller and implement the setEntityManager() method as required by the interface.</p>
<p>If you look back in the init file of the component we are using this method to set the EntityManager on the controller. We use the interface to make sure we use an generic method on all the controllers. In the example below you see how I created a simple example which makes use of Doctrine and outputs some basic information.</p>
<pre class="brush: php; title: ;">
&lt;?php

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.controller');
require_once(JPATH_LIBRARIES . '/doctrine/JoomlaDoctrineController.php');

/**
 * Description of BugsController
 *
 * @author pderaaij
 */
class BugsController extends JController implements JoomlaDoctrineController {

    /**
     *
     * @var Doctrine\ORM\EntityManager
     */
    private $em;

    public function setEntityManager(Doctrine\ORM\EntityManager $entityManager) {
        $this-&gt;em = $entityManager;
    }

    public function index() {
        // add a default bug every refresh
        $newBug = new Entities\Bug();
        $newBug-&gt;setTitle('Doctrine Test');
        $newBug-&gt;setDescription('test');
        $newBug-&gt;setNotificationDate(new DateTime());
        $newBug-&gt;setSolvedDate(new DateTime());
        $this-&gt;em-&gt;persist($newBug);
        $this-&gt;em-&gt;flush();

        $dql = &quot;SELECT b FROM Entities\Bug b&quot;;
        $query = $this-&gt;em-&gt;createQuery($dql);
        $query-&gt;setMaxResults(30);
        $bugs = $query-&gt;getResult();

        echo '&lt;h1&gt;Bug overview&lt;/h1&gt;';
        echo '&lt;table width=&quot;100%&quot;&gt;';
        echo '&lt;tr&gt;';
            echo '&lt;th&gt;#&lt;/th&gt;';
            echo '&lt;th&gt;Title&lt;/th&gt;';
            echo '&lt;th&gt;Notification date&lt;/th&gt;';
            echo '&lt;th&gt;Date solved&lt;/th&gt;';
        echo '&lt;/tr&gt;';

        foreach( $bugs as $bug ) {
            /* @var $bug Bug */
            echo '&lt;tr&gt;';
                echo '&lt;td&gt;' . $bug-&gt;getId() . '&lt;/td&gt;';
                echo '&lt;td&gt;' . $bug-&gt;getTitle() . '&lt;/td&gt;';
                echo '&lt;td&gt;' . $bug-&gt;getNotificationDate()-&gt;format(&quot;Y-m-d H:i:s&quot;) . '&lt;/td&gt;';
                echo '&lt;td&gt;' . $bug-&gt;getSolvedDate()-&gt;format(&quot;Y-m-d H:i:s&quot;) . '&lt;/td&gt;';
            echo '&lt;/tr&gt;';
        }

        echo '&lt;/table&gt;';

        echo '&lt;h1&gt;Bug #1&lt;/h1&gt;';
        $bug = $this-&gt;em-&gt;find(&quot;Entities\Bug&quot;, 1);
        echo '&lt;pre&gt;';
            var_dump($bug);
        echo '&lt;/pre&gt;';
    }

}
?&gt;
</pre>
<h2>It&#8217;s a wrap</h2>
<p>That&#8217;s it, now you can make use of Doctrine within your component. It was a long blog post, but I hope I&#8217;ve shown you an easy way to get going with Doctrine within Joomla.</p>
<p>I hope you liked this article. You can leave your feedback behind on this blog, since I&#8217;m always interested in new insights which I can use to learn and grow as an developer.</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2011%2F03%2F05%2Fusing-doctrine-in-joomla%2F&amp;title=Using%20Doctrine%20in%20Joomla"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2011/03/05/using-doctrine-in-joomla/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A way to implement unit testing in Joomla!</title>
		<link>http://www.paulderaaij.nl/2010/07/31/a-way-to-implement-unit-testing-in-joomla/</link>
		<comments>http://www.paulderaaij.nl/2010/07/31/a-way-to-implement-unit-testing-in-joomla/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 12:21:28 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=203</guid>
		<description><![CDATA[Since a couple of months I&#8217;m not anymore self-employed and am I working for a company who develops for ActiveCollab, Magento and Joomla!. While developing I&#8217;m trying to work according the TDD paradigm. So you write your tests first and then you develop the business logic to succeed the failing test. I&#8217;d have to admit that Joomla! [...]]]></description>
			<content:encoded><![CDATA[<p>Since a couple of months I&#8217;m not anymore self-employed and am I working for a company who develops for ActiveCollab, Magento and Joomla!. While developing I&#8217;m trying to work according the TDD paradigm. So you write your tests first and then you develop the business logic to succeed the failing test. I&#8217;d have to admit that Joomla! never will be my first choice to develop on, but it isn&#8217;t as bad some are preaching.</p>
<p><span id="more-203"></span></p>
<p>While getting my way around the Joomla! framework I have a big problem getting the checked in unit tests to run. If you do a checkout of the unit tests from the svn you&#8217;ll see there are about 960 tests and about 600 fails straight out of the box. Pretty annoying and unusable to write your own tests against.</p>
<p>So I&#8217;ve been working on a test runner of my own. The test runner tries to use the most of the Joomla! framework, but some things it just have to do itself. It consists of 2 files. One file is the testloader which is setup as an autoloader using the JLoad class. The second class sets some configuration files and kickstarts the Joomla! framework.</p>
<p><strong>Here&#8217;s the code for the testloader</strong></p>
<pre class="brush: php; title: ;">

&lt;?php

/**

* Testloader class

*

* This class strips the requested class and passes it thru

* to the Joomla autoload function

*

* @author Paul de Raaij &lt;paul@paulderaaij.nl&gt;

*/

// Preload the model so we can add paths to the inlude path of JLoader

jimport( 'joomla.application.component.model' );

class TestLoader {

/**

* Strip the given class and pass it to the

* Joomla autoloader.

*

* If it's a component add the path to the

* include path of the loader

*

* @param String $classname

* @return bool Has the inclusion succeeded

*/

static public function load( $classname ) {

$explodedPath = self::explodeClassname( $classname );

if( $explodedPath == null ) {

return self::loadJoomlaClass( $classname );

}

// Add the folder to the loader include path

JModel::addIncludePath('../components/com_' . $explodedPath['component'] . '/' . $explodedPath['type'] . 's');

return self::loadJoomlaClass( $classname );

}

/**

* Explode the classname and strip component name,

* type and type name

*

* @param string $classname

* @return mixed Returns null when it's a core file. Returns an array with data if it's a component data

*/

static protected function explodeClassname( $classname ) {

$types = array('model', 'controller', 'helper', 'view');

$classname = strtolower($classname);

if( $classname == 'jmodel' ) {

return null;

}

$fileInfo = array();

foreach( $types as $type ) {

if( false !== strpos($classname, $type) ) {

$fileInfo['type']       = $type;

}

}

if( isset( $fileInfo['type'] ) ) {

$fileInfo['component']  = substr($classname, 0, strpos($classname, $fileInfo['type'] ) );

$fileInfo['name']       = substr($classname, ( strpos($classname, $fileInfo['type'] ) + strlen($fileInfo['type']) ) );

return $fileInfo;

}

return null;

}

/**

* Simple pass thru function to the Joomla autoloader

*

* @param string $class

* @return bool Has inclusion succeeded?

*/

static public function loadJoomlaClass( $class ) {

return JLoader::load( $class );

}

}

?&gt;
</pre>
<p>And this is the TestCase class which is required by each unit test file:</p>
<pre class="brush: php; title: ;">

&lt;?php

require_once 'PHPUnit/Framework.php';

// We are a valid Joomla entry point.

define('_JEXEC', 1);

// Setup the path related constants.

define('DS', DIRECTORY_SEPARATOR);

define('JPATH_BASE', dirname( __FILE__ ) . '\..');

define('JPATH_ROOT', JPATH_BASE);

define('JPATH_CONFIGURATION', JPATH_BASE);

define('JPATH_LIBRARIES', JPATH_BASE.DS.'libraries');

define('JPATH_METHODS', JPATH_ROOT.DS.'methods');

// Load the library importer, datbase class and configuration

require_once (JPATH_LIBRARIES.'/joomla/import.php');

require_once (JPATH_LIBRARIES.'/joomla/database/database.php');

// Load the TestLoader

require_once dirname(__FILE__) . '\lib\TestLoader.php';

// register specific test autloader

if( !defined('LOADED_AUTOLOADER') ) {

spl_autoload_register( array('TestLoader', 'load') );

define('LOADED_AUTOLOADER', true);

}

// Define configuration

jimport( 'joomla.registry.registry' );

require_once( JPATH_CONFIGURATION.'/configuration.php' );

// Create the JConfig object

$config = new JConfig();

// Get the global configuration object

$registry =&amp; JFactory::getConfig();

// Load the configuration values into the registry

$registry-&gt;loadObject($config);

$options = array ('driver' =&gt; $config-&gt;driver,

'host' =&gt; $config-&gt;host,

'user' =&gt; $config-&gt;user,

'password' =&gt; $config-&gt;password,

'database' =&gt; $config-&gt;database,

'prefix' =&gt; $config-&gt;prefix );

// Preload database with configuration

$db = JDatabase::getInstance( $options );

?&gt;
</pre>
<p>An example unit test looks like this:</p>
<pre class="brush: php; title: ;">

&lt;?php

require_once dirname(__FILE__) . '\..\..\..\TestCase.php';

class Model_Test_Base extends PHPUnit_Framework_TestCase {

protected $model = null;

public function setUp() {

$this-&gt;model = JModel::getInstance('&lt;modelname&gt;', '&lt;componentname&gt;Model');

}

public function testSimpleAssertion() {

$this-&gt;assertTrue( $this-&gt;model-&gt;test() );

}

}

?&gt;
</pre>
<p>Perhaps this isn&#8217;t the best way to use unit testing in Joomla! But at the moment this is the only thing I got working. If you&#8217;ve got some suggestions your glad to leave it behind as a reaction!</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2010%2F07%2F31%2Fa-way-to-implement-unit-testing-in-joomla%2F&amp;title=A%20way%20to%20implement%20unit%20testing%20in%20Joomla%21"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2010/07/31/a-way-to-implement-unit-testing-in-joomla/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Custom symfony filters to filter model relations</title>
		<link>http://www.paulderaaij.nl/2010/04/21/custom-symfony-filters-to-filter-model-relations/</link>
		<comments>http://www.paulderaaij.nl/2010/04/21/custom-symfony-filters-to-filter-model-relations/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 10:17:21 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=186</guid>
		<description><![CDATA[For an application I was looking for a way to add filters in the generated admin application. We&#8217;de like to filter clients based on the articles or orders they have.  Lets take a look at the (simplified) schema: Account: columns: id:             { type: integer, primary: true, autoincrement: true, notnull: [...]]]></description>
			<content:encoded><![CDATA[<p>For an application I was looking for a way to add filters in the generated admin application. We&#8217;de like to filter clients based on the articles or orders they have.  Lets take a look at the (simplified) schema:</p>
<p><span id="more-186"></span></p>
<pre class="brush: php; title: ;">

Account:
columns:
id:             { type: integer, primary: true, autoincrement: true, notnull: true }
accountNumber:  { type: integer, notnull: true }
accountName:    { type: string(255), notnull: true }

Order:
columns:
id:             { type: integer, primary: true, autoincrement: true, notnull: true }
internID:       { type: string(20) }
accountID:      { type: integer, notnull: true }
locationID:    { type: integer }
orderDate:      { type: timestamp }
orderedBy:      { type: integer, notnull: true }
remarks:        { type: string(3000) }
orderDelivered: { type: boolean }
placedOrder:    { type: boolean }
relations:
Account:        { onDelete: CASCADE, local: accountID, foreign: id, foreignAlias: accountOrders }

Article:

columns:

id:            { type: integer, primary: true, autoincrement: true, notnull: true }
accountID:     { type: integer, notnull: true }

articleNumber: { type: string(15) }

description:   { type: string(255) }

currentStock:  { type: integer }

minimumStock:  { type: integer }

packageAmount: { type: integer }

previewFile:   { type: string( 255 ) }

remarks:       { type: string( 3000 ) }

internRemarks: { type: string( 5000 ) }

image:         { type: string( 255 ) }

relations:

Account:       { onDelete: CASCADE, local: accountID, foreign: id, foreignAlias: articleAccount }
</pre>
<p>In short. We have an account and each account has it own articles. The can order these articles and this is stored in the Order model ( and a bunch of others, which aren&#8217;t relevant for this post).</p>
<p>What we want to achieve is that we can filter the client list based on a article number or order id.</p>
<p>To do this I extended the generator.yml to add the two new fields.</p>
<pre class="brush: php; title: ;">
config:

fields:
articleNumber:     {label: Artikel nummer, type: string }
orderNumber:     {label: Order nummer, type: string }
</pre>
<p>Next thing to do is to modify the filter form of the account model. Here we&#8217;re going to add the two new fields to the filter form and give them a simple validator.</p>
<pre class="brush: php; title: ;">

public function configure()

{

parent::configure();

$this-&gt;widgetSchema['articleNumber'] = new sfWidgetFormInputText();

$this-&gt;validatorSchema['articleNumber'] = new sfValidatorPass(array('required'=&gt;'false'));

$this-&gt;widgetSchema['orderNumber'] = new sfWidgetFormInputText();

$this-&gt;validatorSchema['orderNumber'] = new sfValidatorPass(array('required'=&gt;'false'));

}
</pre>
<p>Now we want to add the filter values to the query so that the list actually gets filtered by the given values. Therefore were going to add a function for each of the filter fields. The function has one purpose and that is to add a where to the doctrine query.</p>
<pre class="brush: php; title: ;">

protected function addArticleNumberColumnQuery( Doctrine_Query $query, $field, $values) {

$rootAlias = $query-&gt;getRootAlias();

$fieldName = 'articleNumber';

$query-&gt;addWhere( sprintf('%s.articleAccount.%s = ?', $rootAlias, $fieldName), $values );

}

protected function addOrderNumberColumnQuery( Doctrine_Query $query, $field, $values) {

$rootAlias = $query-&gt;getRootAlias();

$fieldName = 'id';

$query-&gt;addWhere( sprintf('%s.accountOrders.%s = ?', $rootAlias, $fieldName), $values );

}
</pre>
<p>The name of the function is specific and has to match the format add%fieldname%ColumnQuery. The code in the functions are pretty self-explanatory. Somethings are hard coded and could be a  nicer. For example you could name the field accountOrders instead of orderNumber so that you can use the value of $field.</p>
<p>This is the simplest solution I could find for filtering a model based on its relations. If someone knows a better way I&#8217;d love to hear about it.</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2010%2F04%2F21%2Fcustom-symfony-filters-to-filter-model-relations%2F&amp;title=Custom%20symfony%20filters%20to%20filter%20model%20relations"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2010/04/21/custom-symfony-filters-to-filter-model-relations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symfony: Multiple embedded forms in a specific layout</title>
		<link>http://www.paulderaaij.nl/2010/02/27/symfony-multiple-embedded-forms-layout/</link>
		<comments>http://www.paulderaaij.nl/2010/02/27/symfony-multiple-embedded-forms-layout/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 11:42:01 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[ontwikkeling]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=162</guid>
		<description><![CDATA[First of all I want to state that I&#8217;m quite new to the Symfony Framework and that my English does not compare with a native, but hey, I&#8217;ll do my best. At the moment I&#8217;m working on my first Symfony application what will be a toto for the upcoming World Championship soccer. A quite challenging [...]]]></description>
			<content:encoded><![CDATA[<p>First of all I want to state that I&#8217;m quite new to the Symfony Framework and that my English does not compare with a native, but hey, I&#8217;ll do my best.</p>
<p>At the moment I&#8217;m working on my first Symfony application what will be a toto for the upcoming World Championship soccer. A quite challenging application but fun and instructive.</p>
<p><a href="http://www.paulderaaij.nl/wp-content/uploads/2010/02/toto-design.jpg" rel="lightbox[162]" rel="lightbox[162]" title="toto-design"><img title="toto-design" src="http://www.paulderaaij.nl/wp-content/uploads/2010/02/toto-design.jpg" alt="" width="854" height="229" /></a></p>
<p>The design presented me with a great challenge. As you can see in the picture above (which is in Dutch, sorry), we want multiple rows containing the matches of that group per row,  where you can fill in your prediction of the result of that match.</p>
<p>The schema I&#8217;ve figured out is this one (just the relevant part) :</p>
<pre class="brush: php; title: ;">

Groups:

columns:

id: { type: integer, primary: true, autoincrement: true }

name: { type: string(100) }

Team:

columns:

id: { type: integer, primary: true, autoincrement: true }

group_id: { type: integer, notnull: true }

name: { type: string(255) }

flag: { type: string(255) }

desription: { type: string(4000) }

biography: { type: string(4000) }

points: { type: integer(2) }

relations:

Groups: { local: group_id, foreign: id }

Games:

columns:

id: { type: integer, primary: true, autoincrement: true }

home_team_id: { type: integer, notnull: true }

away_team_id: { type: integer, notnull: true }

stadium_id: { type: integer }

playing_time: { type: timestamp }

desription: { type: string(3000) }

relations:

Stadium: { local: stadium_id, foreign: id, foreignAlias: Stadium }

HomeTeam: { class: Team, local: home_team_id, foreign: id, foreignAlias: homeTeam }

AwayTeam: { class: Team, local: away_team_id, foreign: id, foreignAlias: awayTeam }

Predictions:

actAs: [Timestampable]

columns:

id: { type: integer, primary: true, autoincrement: true }

user_id: { type: integer(4) }

game_id: { type: integer }

home_score: { type: integer(2) }

away_score: { type: integer(2) }

real_home_score: { type: integer(2) }

real_away_score: { type: integer(2) }

relations:

Profile: { local: user_id, foreign: user_id, foreignAlias: User }

Games: { local: game_id, foreign: id, foreignAlias: Game }
</pre>
<p>Okay, now I&#8217;ve shown you the design we wanted and the schema I&#8217;ve used. Let me show the implementation I&#8217;ve used and the steps how I got to the result.</p>
<p>We want the user to predict the matches that are in the system so I want to show all the games with an embedded form of Prediction. But the problem here is that the 1:n relation is sorted out via the Predictions model, which to me is logical as you have one match with multiple predictions. Here the difficulty came. How do you couple a game to a prediction when there isn&#8217;t a relation yet, which is the case in a first prediction.</p>
<p>This is my solution:</p>
<p>I&#8217;ve created a new action in the Games controller called executePredict:</p>
<pre class="brush: php; title: ;">

public function executePredict( sfWebRequest $request ) {
$this-&gt;form = new GamesCollectionForm( );
}</pre>
<p>Here we call GamesCollectionForm which collects all games in the system and creates a form for them.</p>
<pre class="brush: php; title: ;">

class GamesCollectionForm extends BaseGamesForm

{

public function configure()

{

$this-&gt;useFields(array());

$q = Doctrine_Query::create()-&gt;from('Games');

$aGames = $q-&gt;execute();

$wrapperForm = new sfForm();

foreach( $aGames as $index =&gt; $game ) {

$gameForm = new GamesPredictionForm( $game );

$gameForm-&gt;widgetSchema-&gt;setNameFormat('games[predictions][game_' . $index . '][%s]');

$wrapperForm-&gt;embedForm('game_' . $index, $gameForm);

}

$this-&gt;embedForm('predictions', $wrapperForm);

}

}
</pre>
<p>Okay, here I ran into multiple problems. The first one being that the collection form is an child of BaseGamesForm and therefore contains form widgets for adding a game, something I don&#8217;t want. So clean them all out by stating that we aren&#8217;t going to use any fields.</p>
<p>Next we collect all the games in the system and create an empty sfForm as wrapperform. In this wrapperform we&#8217;re going to embed instances of the GamePredictionForm. So for every game we create a GamesPredictionForm and set the right name format. This name format we need for the rendering and saving the forms.</p>
<p>Each form is embedded to the wrapper by setting its index prefixed with &#8220;game_&#8221;. Eventually the wrapperform gets embedded to the collection form.</p>
<p>The GamesPredictionForm looks like this:</p>
<pre class="brush: php; title: ;">

class GamesPredictionForm extends BaseGamesForm

{

public function configure( )

{

$q = Doctrine_Query::create()-&gt;from('Predictions')-&gt;where('user_id = ? ', sfContext::getInstance()-&gt;getUser()-&gt;getProfile()-&gt;getUserID())-&gt;andWhere('game_id = ?', $this-&gt;getObject()-&gt;getID());

$oPred = $q-&gt;fetchOne();

if(! $oPred instanceof Predictions ) {

$oPred = new Predictions();

$this-&gt;getObject()-&gt;Game[] = $oPred;

}

$this-&gt;embedRelation('Game', 'PredictionsForm', array('user_id' =&gt; sfContext::getInstance()-&gt;getUser()-&gt;getProfile()-&gt;getUserID()));

$this-&gt;widgetSchema['home_team_id'] = new sfWidgetFormInputHidden();

$this-&gt;widgetSchema['away_team_id'] = new sfWidgetFormInputHidden();

}

}
</pre>
<p>What this class does is checking if there is a prediction of the user for this game. If this isn&#8217;t the case we create an empty Predictions object so the form renders a Prediction form. The Predictions model gets embedded with the game form and the id widgets are set hidden. This configuration of hidden inputs is needed for the customized rendering as I going to show later.</p>
<p>If we now render our form we got the result like below.</p>
<p><a href="http://www.paulderaaij.nl/wp-content/uploads/2010/02/toto-default-rendering.jpg" rel="lightbox[162]" rel="lightbox[162]" title="toto-default-rendering"><img class="aligncenter size-full wp-image-168" title="toto-default-rendering" src="http://www.paulderaaij.nl/wp-content/uploads/2010/02/toto-default-rendering.jpg" alt="" width="565" height="648" /></a></p>
<p>Nice, but not quite what we wanted. Besides that, any user now can edit the stadium, playing time or description. That&#8217;s not want we&#8217;d like to see, so lets start change the rendering of this form.</p>
<p>Before we change the rendering of the form I&#8217;d like to mention that at this moment it isn&#8217;t possible to save the form. If you&#8217;ll try to save now a database error is thrown stating that you try to enter null values in the games table. Which is correct, we&#8217;ve said that we don&#8217;t want to use any fields in the GamesCollectionForm. That works for the widgets, not for the save function. We need to modify that. My solution to this problem took me ages to find and I doubt that this is the best way to handle this.</p>
<p>What I&#8217;ve done is to override the doSave function of the GamesCollectionForm and checked if there&#8217;s any home_team_id been set. If not, the form is used for prediction by a user and we only want to save the embedded forms. In code it looks like this:</p>
<pre class="brush: php; title: ;">

public function doSave( $con = null ) {

if( $this-&gt;getObject()-&gt;getHomeTeamId() != null ) {

} else {

$this-&gt;updateObjectEmbeddedForms($this-&gt;taintedValues);

$this-&gt;saveEmbeddedForms($con);

return;

}

}
</pre>
<p>What took me so long to figure out is the updateObjectEmbeddedForms. It seems this just don&#8217;t happens with the bind function of the form which is called in the action. By that it mean, if the parent values are all null, the embedded forms doesn&#8217;t get bound to the form values. I did not tested this so it&#8217;s an assumption and not a fact.</p>
<pre class="brush: php; title: ;">

public function executePredict( sfWebRequest $request ) {

if($request-&gt;isMethod(sfRequest::POST) || $request-&gt;isMethod(sfRequest::PUT)) {

$games = Doctrine::getTable('Games')-&gt;find(array($request-&gt;getParameter('id')));

$this-&gt;form = new GamesCollectionForm($games);

$this-&gt;processForm($request, $this-&gt;form);

} else {

$this-&gt;form = new GamesCollectionForm( );

}

}

protected function processForm(sfWebRequest $request, sfForm $form)

{

$form-&gt;bind($request-&gt;getParameter($form-&gt;getName()), $request-&gt;getFiles($form-&gt;getName()));

if ($form-&gt;isValid())

{

$form-&gt;save();

$this-&gt;redirect('games/predict');

}

}
</pre>
<p>Well, now we can save our form whether its new or just an update, it works and that&#8217;s a victory on its own.</p>
<p>Now the rendering of the form. Our goal is to get the rendering as suggested by the designers. Well I can tell a lot about this, but lets just start by showing the code and the end result of that code. This is the code of the template rendering:</p>
<pre class="brush: php; title: ;">

&lt;?php use_helper('Date'); ?&gt;

&lt;h1&gt;Voorspel de wedstrijden&lt;/h1&gt;

&lt;form action=&quot;&lt;?php echo url_for('games/predict') ?&gt;&quot; method=&quot;POST&quot;&gt;

&lt;table width=&quot;100%&quot;&gt;

&lt;?php echo $form['id'];?&gt;

&lt;?php echo $form[$form-&gt;getCSRFFieldName() ]-&gt;render(); ?&gt;

&lt;?php foreach( $form-&gt;getEmbeddedForm('predictions')-&gt;getEmbeddedForms() as $pred): ?&gt;

&lt;tr&gt;

&lt;td&gt;&lt;?php echo format_datetime($pred-&gt;getObject()-&gt;getPlayingTime(), 'dd-MM-yyyy HH:mm'); ?&gt;&lt;/td&gt;

&lt;td&gt;&lt;?php echo &quot;&lt;img src='/uploads/flags/&quot; . $pred-&gt;getObject()-&gt;getHomeTeam()-&gt;getFlag() . &quot;' width=15 height=10/&gt;&quot;;

echo $pred-&gt;getObject()-&gt;getHomeTeam(); ?&gt;&lt;/td&gt;

&lt;td&gt; - &lt;/td&gt;

&lt;td&gt;&lt;?php echo &quot;&lt;img src='/uploads/flags/&quot; . $pred-&gt;getObject()-&gt;getAwayTeam()-&gt;getFlag() . &quot;' width=15 height=10/&gt;&quot;;

echo $pred-&gt;getObject()-&gt;getAwayTeam(); ?&gt;&lt;/td&gt;

&lt;td&gt;&lt;?php echo $pred-&gt;getObject()-&gt;getStadium()-&gt;getName(); ?&gt;&lt;/td&gt;

&lt;td&gt;&lt;?php echo $pred-&gt;getObject()-&gt;getStadium()-&gt;getCity(); ?&gt;&lt;/td&gt;

&lt;td&gt;&lt;?php echo $pred['Game'][0]['home_score']; ?&gt;&lt;/td&gt;

&lt;td&gt; - &lt;/td&gt;

&lt;td&gt;&lt;?php echo $pred['Game'][0]['away_score']; ?&gt;&lt;/td&gt;

&lt;?php echo $pred['Game'][0]['id']; ?&gt;

&lt;?php echo $pred['Game'][0]['user_id']; ?&gt;

&lt;?php echo $pred['Game'][0]['game_id']; ?&gt;

&lt;?php echo $pred['home_team_id']; ?&gt;

&lt;?php echo $pred['away_team_id']; ?&gt;

&lt;/tr&gt;

&lt;?php endforeach; ?&gt;

&lt;tr&gt;

&lt;td colspan=&quot;2&quot;&gt;

&lt;input type=&quot;submit&quot; /&gt;

&lt;/td&gt;

&lt;/tr&gt;

&lt;/table&gt;

&lt;/form&gt;
</pre>
<p>Which leads us to&#8230;</p>
<p><a href="http://www.paulderaaij.nl/wp-content/uploads/2010/02/toto-rendering-result.jpg" rel="lightbox[162]" rel="lightbox[162]" title="toto-rendering-result"><img class="aligncenter size-full wp-image-173" title="toto-rendering-result" src="http://www.paulderaaij.nl/wp-content/uploads/2010/02/toto-rendering-result.jpg" alt="" width="832" height="147" /></a></p>
<p>Hey! It looks like we&#8217;ve got it right. In essence this is just like the designers wishes. Well, what&#8217;s up with this form rendering&#8230;</p>
<p>First of all I start with rendering the hidden form ID tag and the hidden CSFR field. We need this for the binding and security of the form (I&#8217;m not sure of the binding part).</p>
<p>Then I want the embedded Predictions form which is the wrapperform containing all forms per match as an embedded form. Hence, the double getEmbeddedForms call. The $pred variable now holds an instance of the GamesPredictionForm class.</p>
<p>Per row we first render all the static match information by retrieving the object and outputting them. After that we render the prediction form elements which are stored in the Game property of the GamesPredictionForm. The game[0] holds the Predictions form which needs to be editable for the user.</p>
<p>That are all the visible fields, they are followed by a bunch of hidden fields so that the objects can be stored right. This information is processed by the bind and updateObject function and are mandatory.</p>
<p>This rendering will be done for every Game stored in the system. And the best thing is that it works!</p>
<p>But there&#8217;s a catch. It works and I&#8217;m glad with that, but I&#8217;m not happy with this solution. I can&#8217;t figure out if the model design is incorrect, if I use Symfony wrong or just do something other totally the wrong way around. Therefore I need you! If you got to here you probably have the same problem or a huge interest in Symfony ( or just me, but I&#8217;ll let that idea go by ).</p>
<p>Perhaps you can tell me what I can do better to prevent these kind of &#8216;hacks&#8217; and adjustments. Help me to grow as developer and give your feedback. I appreciate it big time!</p>
<p>Thanks for your time so far!</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2010%2F02%2F27%2Fsymfony-multiple-embedded-forms-layout%2F&amp;title=Symfony%3A%20Multiple%20embedded%20forms%20in%20a%20specific%20layout"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2010/02/27/symfony-multiple-embedded-forms-layout/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Als tinyMCE niet in één keer laad</title>
		<link>http://www.paulderaaij.nl/2010/02/26/als-tinymce-niet-in-een-keer-laad/</link>
		<comments>http://www.paulderaaij.nl/2010/02/26/als-tinymce-niet-in-een-keer-laad/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 09:14:05 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Tiny-MCE]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=159</guid>
		<description><![CDATA[Het wil bij tinyMCE in bepaalde browsers nog wel eens gebeuren dat de editor niet gelijk geladen word. Pas bij een refresh verschijnt de editor. Voornamelijk Safari en google Chrome vertonen dit gedrag. De oplossing is echter simpel. Controleer of alle plugins die je in de configuratie opgeeft wel bestaan en geladen kunnen worden. Dus [...]]]></description>
			<content:encoded><![CDATA[<p>Het wil bij tinyMCE in bepaalde browsers nog wel eens gebeuren dat de editor niet gelijk geladen word. Pas bij een refresh verschijnt de editor. Voornamelijk Safari en google Chrome vertonen dit gedrag.</p>
<p>De oplossing is echter simpel. Controleer of alle plugins die je in de configuratie opgeeft wel bestaan en geladen kunnen worden. Dus deze regel:</p>
<p>plugins : &#8216;table,advimage,archvr,paste&#8217;,</p>
<p>Moet wel over plugins beschikken die bestaan en bereikbaar zijn.</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2010%2F02%2F26%2Fals-tinymce-niet-in-een-keer-laad%2F&amp;title=Als%20tinyMCE%20niet%20in%20%C3%A9%C3%A9n%20keer%20laad"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2010/02/26/als-tinymce-niet-in-een-keer-laad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dit wil ik in 2010 doen</title>
		<link>http://www.paulderaaij.nl/2010/01/15/dit-wil-ik-in-2010-doen/</link>
		<comments>http://www.paulderaaij.nl/2010/01/15/dit-wil-ik-in-2010-doen/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 13:39:10 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[Algemeen]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[ontwikkeling]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=143</guid>
		<description><![CDATA[Ok, we zijn al even in 2010 en het is al zeker niet meer de juiste tijd om de &#8220;Beste wensen!&#8221; te roepen. Overigens toch al een rare zijn.. wat wens je iemand die andere 350 dagen toen dan? Toch wil ik in dit blog vertellen wat ik dit jaar wil gaan doen op het [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, we zijn al even in 2010 en het is al zeker niet meer de juiste tijd om de &#8220;Beste wensen!&#8221; te roepen. Overigens toch al een rare zijn.. wat wens je iemand die andere 350 dagen toen dan?</p>
<p>Toch wil ik in dit blog vertellen wat ik dit jaar wil gaan doen op het gebied software engineering, ondernemen en persoonlijk ondernemen. Door het op te schrijven in dit blog kan ik wat feedback van lezers krijgen op de dingen die ik wil gaan doen en ik kan mezelf er ook wat beter aan houden <img src='http://www.paulderaaij.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Algemene software ontwikkeling</strong></p>
<p>Dit ga ik voornamelijk behalen via het werk wat ik voor school moet doen. Door nu niet alleen maar te lezen over ontwikkelmethodes en software concepten, maar ook verplicht en gestimuleerd te worden door ze te gebruiken hoop ik dat ik dat vrij goed onder de knie krijg.</p>
<p><strong>PHP<br />
</strong></p>
<p>Aan het eind van vorig jaar al lichtelijk verdiept in het <a href="http://www.symfony-project.org/" target="_blank">Symfony framework</a> en dat wil ik zeker nog verder uitbreiden. Symfony biedt interessante mogelijkheden en zorgt voor een stukje zekerheid tijdens het ontwikkelen. Daarnaast helpt het mijn ontwikkeling als programmeur ontzettend. Voornamelijk omdat je gedwongen word op de ´juiste manier´ te programmeren zodat je van alle voordeeltjes gebruik kan maken.</p>
<p>Overigens wil ik niet alleen met symfony werken. Op den duur wil ik ook kennis hebben van andere frameworks zodat je leert te kiezen welk framework je kan gebruiken voor een probleem.</p>
<p><strong>Project methode</strong></p>
<p>Met <a href="http://www.mediactief.nl" target="_blank">mijn bedrijf</a> werken voornamelijk aan kleine projectjes van 3 weken. Ik wil op zoek naar een project/ontwikkelingsmethode die ons echt kan helpen om gestructureerd te werken zonder te verzanden in bergen extra werk. Als iemand tips heeft dan lees ik ze graag!</p>
<p><strong>Regular expressions &amp; wiskunde</strong></p>
<p>Dit jaar wil ik erg graag mijn kennis van regexs en wiskunde in zijn algemeenheid verbeteren. Ik merk dat mijn kennis over deze onderwerpen niet optimaal is. Vooral door regex beter onder de knie te krijgen hoop ik wat smerige hacks achterwege te kunnen laten in de toekomst.</p>
<p>Wat betreft Wiskunde heb ik al een boek van <a href="http://www.headfirstlabs.com/books/hfalg/" target="_blank">Head First</a> gekocht. Dit is voornamelijk bedoeld om te leren sommen te optimaliseren. Soms denk ik gewoon veels te moeilijk.</p>
<p><strong>En verder&#8230;<br />
</strong></p>
<p>Meer conferenties bezoeken is een belangrijk doel dit jaar en we beginnen goed. Eind januari ga ik naar de <a href="http://conference.phpbenelux.eu/" target="_blank">conference </a>van <a href="http://phpbenelux.eu/" target="_blank">PHP Benelux</a>, in april help ik tijdens het<a href="http://www.pfcongres.nl" target="_blank"> pfcongres</a> en de <a href="http://phpconference.nl/" target="_blank">dutch php conference </a>staat ook op het wensenlijstje.</p>
<p>Alhoewel ik niet veel tijd heb lijkt het me erg leuk en zinvol om dit jaar betrokken te raken bij een open source project wat mij aanspreekt. Door met meerdere developers aan een project te werken kan ik een heleboel leren en terug te geven aan de open source community. Dus als iemand een leuk project voor ogen heeft <img src='http://www.paulderaaij.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>In ieder geval wil ik nog een heleboel, pas aan het eind van het jaar gaan we zien of het allemaal gelukt is. Heb je nog tips of tricks? Ik hoor ze graag!</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2010%2F01%2F15%2Fdit-wil-ik-in-2010-doen%2F&amp;title=Dit%20wil%20ik%20in%202010%20doen"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2010/01/15/dit-wil-ik-in-2010-doen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Operator Overloading in PHP</title>
		<link>http://www.paulderaaij.nl/2009/05/11/operator-overloading-in-php/</link>
		<comments>http://www.paulderaaij.nl/2009/05/11/operator-overloading-in-php/#comments</comments>
		<pubDate>Mon, 11 May 2009 14:17:13 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=66</guid>
		<description><![CDATA[Vandaag een groot deel van de dag bezig geweest met het schrijven van een eigen Time class. Dit vanwege een nieuwe applicatie waar ik mee bezig en ik veel calculaties met tijd moet uitvoeren. De class zelf is dus aardig functioneel geworden en met functies als add((), subtract() komt ik al een heel eind, maar [...]]]></description>
			<content:encoded><![CDATA[<p>Vandaag een groot deel van de dag bezig geweest met het schrijven van een eigen Time class. Dit vanwege een nieuwe applicatie waar ik mee bezig en ik veel calculaties met tijd moet uitvoeren. De class zelf is dus aardig functioneel geworden en met functies als add((), subtract() komt ik al een heel eind, maar wat mij nou mooi leek is dat je $oTime1 &#8211; $oTime2 kan doen. Echter dat kan dus niet met PHP.</p>
<p>Na wat onderzoek waarom niet, blijkt dat men dit doet om de leercurve van PHP zo laag mogelijk te houden. Wat mij betreft een wat vreemde uitleg, want volgens mij kan de dynamiek van de taal er juist groter van worden. Is het niet zo dat de verantwoordelijkheid van het gebruik van een functionaliteit bij een gebruiker ligt? Tot hoever moet je als ontwikkelaar van een programmeertaal je gebruikers beschermen tegen fout gebruik van het één en ander. OOP word nu ook genoeg vallen misbruikt, maar dat gaat toch ook niet dicht gezet worden?</p>
<p>Nu ben ik wel benieuwd wat de meningen van anderen hierover zijn.</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2009%2F05%2F11%2Foperator-overloading-in-php%2F&amp;title=Operator%20Overloading%20in%20PHP"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2009/05/11/operator-overloading-in-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Opzetten van phpUnderControl op een Windows machine</title>
		<link>http://www.paulderaaij.nl/2009/04/25/opzetten-van-phpundercontrol-op-een-windows-machine/</link>
		<comments>http://www.paulderaaij.nl/2009/04/25/opzetten-van-phpundercontrol-op-een-windows-machine/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 07:27:39 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[phpUnderControl]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=57</guid>
		<description><![CDATA[Deze week ben ik aan het stoeien geweest met het opzetten van phpUnderControl. Het is een mooi pakket wat vrij makkelijk te installeren is, zeker op een linux bak. Op Windows zijn er een aantal aandachtspunten waar je rekening mee moet houden. Allereerst voor mijn installatie heb ik het volgende artikel van techPortal gevolgd: http://techportal.ibuildings.com/2009/03/03/getting-started-with-phpundercontrol/ [...]]]></description>
			<content:encoded><![CDATA[<p>Deze week ben ik aan het stoeien geweest met het opzetten van phpUnderControl. Het is een mooi pakket wat vrij makkelijk te installeren is, zeker op een linux bak. Op Windows zijn er een aantal aandachtspunten waar je rekening mee moet houden.</p>
<p>Allereerst voor mijn installatie heb ik het volgende artikel van techPortal gevolgd: <a href="http://techportal.ibuildings.com/2009/03/03/getting-started-with-phpundercontrol/" target="_blank">http://techportal.ibuildings.com/2009/03/03/getting-started-with-phpundercontrol/</a></p>
<p>Waar je op moet letten</p>
<ul>
<li>De cli commando&#8217;s phpdoc, phpcs en phpunit moet je voorzien van .bat anders kan Ant de programma&#8217;s niet vinden</li>
<li>Alle bestanden omringen door quotes zodat het pad goed gaat</li>
<li>Ik heb al mijn svn tags voorzien van &#8211;username en -password omdat Ant bij mij wat problemen gaf met het inloggen op de SVN server</li>
</ul>
<p>Dit zijn mijn aandachtspunten voor het opzetten van phpUnderControl op een Windows bak. Met bovenstaande in gdachten draait het bij mij als een zonnetje inmiddels! Marc Veldman bedankt voor het artikel met heldere uitleg!</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2009%2F04%2F25%2Fopzetten-van-phpundercontrol-op-een-windows-machine%2F&amp;title=Opzetten%20van%20phpUnderControl%20op%20een%20Windows%20machine"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2009/04/25/opzetten-van-phpundercontrol-op-een-windows-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eindelijk, een goede tiny-mce plugin voor word formatting</title>
		<link>http://www.paulderaaij.nl/2009/03/17/goede-tiny-mce-plugin-word-formatting/</link>
		<comments>http://www.paulderaaij.nl/2009/03/17/goede-tiny-mce-plugin-word-formatting/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 15:18:30 +0000</pubDate>
		<dc:creator>Paul de Raaij</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tiny-MCE]]></category>

		<guid isPermaLink="false">http://www.paulderaaij.nl/?p=37</guid>
		<description><![CDATA[Al jaren gebruik ik tinyMCE in mijn webapplicaties als Rich Text Editor. Ongeveer dezelfde tijd loop ik tegen het probleem aan dat het voor geen meter met Word formatting om kan gaan. Had ik in de eerste versie nog wel wat regex geplaatst voor Word 2003, vanaf de 2007 versie was dat ook een hopeloos [...]]]></description>
			<content:encoded><![CDATA[<p>Al jaren gebruik ik tinyMCE in mijn webapplicaties als Rich Text Editor. Ongeveer dezelfde tijd loop ik tegen het probleem aan dat het voor geen meter met Word formatting om kan gaan. Had ik in de eerste versie nog wel wat regex geplaatst voor Word 2003, vanaf de 2007 versie was dat ook een hopeloos verhaal.</p>
<p>Vandaag toch maar eens tijd gemaakt om op zoek te gaan naar een goede plugin hiervoor en inmiddels ook gevonden!<a title="Plugin Paste2 websites" href="http://wiki.moxiecode.com/index.php/Paste2" target="_blank"> Paste2</a> is de verlossende redder en verwijdert ook echt alles zonder de semantiek te verliezen! Kudo&#8217;s voor de makers van dit project! Nu weer tijd voor eigen ontwikkelingen&#8230;</p>
<!-- PHP 5.x --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.paulderaaij.nl%2F2009%2F03%2F17%2Fgoede-tiny-mce-plugin-word-formatting%2F&amp;title=Eindelijk%2C%20een%20goede%20tiny-mce%20plugin%20voor%20word%20formatting"><img src="http://www.paulderaaij.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.paulderaaij.nl/2009/03/17/goede-tiny-mce-plugin-word-formatting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
