<?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>Digital Base - Blog &#187; Bart Vanderstukken</title>
	<atom:link href="http://www.digitalbase.eu/blog/author/bvanders/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitalbase.eu/blog</link>
	<description>A blog about webdesign, PHP, development and IT</description>
	<lastBuildDate>Wed, 10 Feb 2010 16:28:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to unsecure admin generated modules in Symfony</title>
		<link>http://www.digitalbase.eu/blog/how-to-unsecure-admin-generated-modules/</link>
		<comments>http://www.digitalbase.eu/blog/how-to-unsecure-admin-generated-modules/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 14:38:37 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.digitalbase.eu/blog/?p=245</guid>
		<description><![CDATA[You gotta love the admin generator&#8230; There&#8217;s only one problem: it&#8217;s secured by default (according to the symfony site).
But I want to use these modules in a non-secured environment.
Adding credentials: [] in the admin generator does not work&#8230; Why?
Look at your automoduleactions. You&#8217;ll find a preExecute function:

  public function preExecute&#40;&#41;
  &#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p>You gotta love the admin generator&#8230; There&#8217;s only one problem: it&#8217;s secured by default (according to the symfony site).<br />
But I want to use these modules in a non-secured environment.<br />
Adding credentials: [] in the admin generator does not work&#8230; Why?<br />
Look at your auto<em>module</em>actions. You&#8217;ll find a preExecute function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preExecute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> eventGeneratorConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCredentials</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forward</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_secure_module'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_secure_action'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatcher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">notify</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfEvent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin.pre_execute'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'configuration'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> eventGeneratorHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This code is always executed before any action.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCredentials</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>the getCredentials function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCredentials<span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">===</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'credentials'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'credentials'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The problem is that hasCredential(array()) returns false.<br />
My solution:<br />
Override the hasCredential function in myUser</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasCredential<span style="color: #009900;">&#40;</span><span style="color: #000088;">$credential</span><span style="color: #339933;">,</span> <span style="color: #000088;">$useAnd</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//for usage in generator =&gt; + as credential will return hasCredential=true (even if user has no credentials at all)</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$credential</span> <span style="color: #339933;">===</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//btw =&gt; you could have checked for an empty array of credentials which is what the generator is returning</span>
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">hasCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$credential</span><span style="color: #339933;">,</span> <span style="color: #000088;">$useAnd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now to make it work, put in generator.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">  config:
     actions:
        _delete:        { credentials: admin }
        _list:            { credentials: + }
        index:           { credentials: + }
#        _new:         { credentials: + }
#        _edit:         { credentials: + }</pre></div></div>

<p>Ps: You could also use false &#038; -</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/how-to-unsecure-admin-generated-modules/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Simplifying Queries: Using sum, count, etc in Propel 1.3</title>
		<link>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel-13/</link>
		<comments>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel-13/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 10:57:32 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://www.digitalbase.eu/blog/?p=228</guid>
		<description><![CDATA[My old post handled Propel 1.2.
This is the way to do it in Propel 1.3

1
2
3
4
5
6
7
    $c = new Criteria&#40;&#41;;
    $c-&#62;add&#40;FavoriteDatePeer::EVENTDATAPROPOSAL_ID, $this-&#62;getId&#40;&#41;&#41;;
    $c-&#62;addSelectColumn&#40;&#34;SUM(&#34;.FavoriteDatePeer::SCORE.&#34;) as rank&#34;&#41;;
&#160;
    $stmt = FavoriteDatePeer::doSelectStmt&#40;$c&#41;;
    $row = $stmt-&#62;fetch&#40;&#41;;
    return $row&#91;'rank'&#93;;

]]></description>
			<content:encoded><![CDATA[<p>My <a title="Sum, count, etc. in Propel 1.2" href="http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/">old post</a> handled Propel 1.2.</p>
<p>This is the way to do it in Propel 1.3</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span>FavoriteDatePeer<span style="color: #339933;">::</span><span style="color: #004000;">EVENTDATAPROPOSAL_ID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSelectColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SUM(&quot;</span><span style="color: #339933;">.</span>FavoriteDatePeer<span style="color: #339933;">::</span><span style="color: #004000;">SCORE</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) as rank&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> FavoriteDatePeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelectStmt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rank'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel-13/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FusionCharts Symfony Plugin: dbFusionChartsPlugin</title>
		<link>http://www.digitalbase.eu/blog/fusioncharts-symfony-plugin-dbfusionchartsplugin/</link>
		<comments>http://www.digitalbase.eu/blog/fusioncharts-symfony-plugin-dbfusionchartsplugin/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 11:00:00 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[dbFusionChart]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=70</guid>
		<description><![CDATA[We're creating an object oriented package to easily create FusionCharts charts.]]></description>
			<content:encoded><![CDATA[<p>
We&#39;re<br />
currently writing an OO class to create <a href="http://www.fusioncharts.com/" target="_blank" title="FusionCharts v3">FusionCharts</a><br />
quickly, easily &amp; intuitive, because the existing FusionCharts.php class is not OOP and, honestly, we thought we could do better&#8230;<br />
Our package is based on and tested against the <a href="http://www.fusioncharts.com/free/" target="_blank" title="Free Flash Charts">FusionCharts Free v2</a> package. It&#39;s written<br />
symfony independent, but we provide a helper, for easy use in symfony.
</p>
<p>
The symfony plugin, <a href="http://trac.symfony-project.com/wiki/dbFusionChartPlugin" target="_blank" title="SymfonyPlugins">dbFusionChartPlugin</a>, is<br />
in its alpha state now, because it only includes basic <a href="http://www.fusioncharts.com/free/docs/?gMenuItemId=19" target="_blank" title="FusionCharts Free Documentation">single</a>  &amp; <a href="http://www.fusioncharts.com/free/docs/?gMenuItemId=19" title="FusionCharts Free Documentation">multi-series</a>  chart support. Although the basic code is ready, it needs to be extended, to work with all chart types, but a mediocre programmer should be able to understand its structure and adapt/extend it to his needs. We deeply appreciate all <a href="/contact" target="_blank" title="Contact us">help and suggestions!</a>
</p>
<h3>
Symfony<br />
helper<br />
</h3>
<p>
[code]FC helper ex[/code]
</p>
<p>
This helper creates the necessary JavaScript.
</p>
<p>
[code]FC javaScript[/code]
</p>
<h3>Documentation</h3>
<p>
You can find the dbFusionChart <a href="http://www.phpdoc.org/" target="_blank" title="phpDoc">phpDoc</a> at <a href="/dbFusionChart/doc/index.html" target="_blank" title="dbFusionChart v0.0.1">digitalbase.eu/dbFusionChart/doc/index.html</a>
</p>
<h3>Logic</h3>
<p>
As you can see in the <a href="http://www.fusioncharts.com/free/docs/?gMenuItemId=19" target="_blank" title="FusionCharts Documentation">FusionCharts Documentation</a>, you need to define your chart&#39;s data in an XML file. Our dbFusionChartXML class uses the <a href="http://www.php.net/dom" target="_blank" title="DOM Functions">php DOM extension</a> to  encapsulate that XML logic by providing methods to add categories and (datasets with) sets. It has (for now) the descendants dbFC_Single &amp; dbFC_Multi. The latter will make sure there are always as many sets in each dataset as there are categories, when adding a dataset or category.
</p>
<h3>Stay tuned</h3>
<p>
We have recently added a check in the addCategory function so it<br />
wouldn&#39;t add the same category twice, no matter how many times it&#39;s<br />
being called, e.g. when looping <a href="http://propel.phpdb.org/trac/" target="_blank" title="Propel Documentation">Propel</a>   objects to init a dbFusionChartXML. It&#39;s checks like these that need to be added, among much much more&#8230; So <a href="/blog/tag/dbfusionchart/rss" target="_blank" title="RSS Feed">stay tuned!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/fusioncharts-symfony-plugin-dbfusionchartsplugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xajax driven CriteriaBuilder for Propel / php</title>
		<link>http://www.digitalbase.eu/blog/xajax-driven-criteriabuilder-for-propel-php/</link>
		<comments>http://www.digitalbase.eu/blog/xajax-driven-criteriabuilder-for-propel-php/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 11:00:00 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=58</guid>
		<description><![CDATA[The CriteriaBuilder is a GUI to create a <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a> (<a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a>), which then can be used by any php object implementing our CriteriaClient interface.
Here's how we use it in combination with our grid_propel.]]></description>
			<content:encoded><![CDATA[<p>Earlier this week, I talked about our custom datagrid for <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a> and<br />
how it was being rewritten to interact with our CriteriaBuilder (<a href="/blog/custom-propel-grid-update" target="_blank">read<br />
more</a>). Well, I&#8217;ll give you another glance into our coding<br />
efforts.</p>
<h4 class="green">Goal</h4>
<p>We wanted to make<br />
an object, which would manipulate the data being shown in our<br />
grid_propel. For normal people, this means: to filter the data.</p>
<p>Early on, we<br />
decided it had to &#8216;build a <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a>&#8216; (because <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a> rules!), which<br />
then could be used by our grid_propel.</p>
<h4 class="green">Structure</h4>
<p>The<br />
CriteriaBuilder is in essence nothing but an array of FilterData<br />
objects, which is indexed by the FilterColumn&#8217;s name (<a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a> peer<br />
constant), so there could only be one FilterData object per<br />
FilterColumn.<br />
Of course, there&#8217;s more to it, about a thousand<br />
lines of code actually (<a href="http://www.phpdoc.org/">phpDoc</a> included), but almost half of that are<br />
xajax functions for user interaction, and then there are methods like<br />
addAvailableColumn &amp; qAddAvailableColumn to initialize the<br />
CriteriaBuilder, and internal functions, which I&#8217;m not all going to<br />
explain here. I&#8217;ll touch some of them in the next section.</p>
<h4 class="green">Behind<br />
the scenes</h4>
<p>The __toString<br />
function, will loop all FilterData objects and create a selector,<br />
with their column name or with a more human readable alias, using our<br />
XHTML package, which I&#8217;ll perhaps tell you more about on a<br />
quite/rainy day. It&#8217;s an object-oriented package to quickly create<br />
readable and XHTML valid code, I can tell you that.</p>
<div style="text-align: center"><img title="CriteriaBuilder column selector" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/columns.png" border="0" alt="CriteriaBuilder column selector" width="450" height="295" /></div>
<p>The add filter<br />
button will trigger the xajax function addFilter, which adds a<br />
UserFilter to the FilterData object related to the selected/passed<br />
value and then updates the &#8216;criteriaform&#8217;.</p>
<div style="text-align: center"><img title="Filter Example" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/filter.png" border="0" alt="Criteriabuilder UserFilter example" width="445" height="113" /></div>
<p>This criteriaform<br />
shows for every UserFilter a &#8216;criteriaLine&#8217;, with a combination box<br />
(disabled if only one line present), a filter method selector and<br />
something to determine the search value.</p>
<p>Clicking &#8216;apply<br />
filters&#8217; will trigger another xajax function, which will build the<br />
<a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a> based on the current UserFilters, and pass it to all<br />
registered CriteriaClients through the CriteriaClient interface<br />
method processCriteria. This is an implementation of what Java<br />
programmers probably know as the Listener pattern, meaning that an<br />
object implementing the CriteriaClient interface registers itself as<br />
Listener/CriteriaClient, by calling<br />
CriteriaBuilder::addClient(CriteriaClient).<br />
<strong><br />
This means that the<br />
CriteriaBuilder can serve any (and more than one) object implementing<br />
the CriteriaClient interface, not just our grid_propel!</strong></p>
<p>The &#8216;remove this<br />
filter&#8217; button will trigger a xajax fuction, which will remove the<br />
UserFilter from the FilterColumn&#8217;s UserFilter array, reorder its<br />
keys, and update the criteriaform.<br />
The &#8216;clear all<br />
filters&#8217;-button, naturally, deletes all UserFilters and also updates<br />
the CriteriaForm. Because there are no filters left, the criteriaform<br />
will disappear again.<br />
Both functions will also immediately update<br />
the grid by calling buildCriteria (which calls processCriteria on its<br />
clients).</p>
<p>I&#8217;ve recently<br />
added a &#8217;save filter&#8217;-button, which makes this box appear,</p>
<div style="text-align: center"><img title="save filter combination" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/save_filter.png" border="0" alt="CriteriaBuilder save filter combination" width="443" height="144" /></div>
<p>giving the user<br />
the option to save his filter combination. Which is then linked to<br />
the CriteriaBuilder&#8217;s name and saved in our database. When a<br />
CriteriaBuilder is &#8216;__tostringed&#8217;, it will search for these filters,<br />
and if one&#8217;s found, you&#8217;ll get something like this.</p>
<div style="text-align: center"><img title="load filter combination" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/load_filter.png" border="0" alt="CriteriaBuilder load saved UserFilter" width="444" height="72" /></div>
<p>Selecting a saved<br />
filter will once again trigger a xajax function, which will load the<br />
filter (update criteriaform and build <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a>, and thus updating the<br />
grid).<br />
For now, these are personal filters, because they&#8217;re linked<br />
to the user who&#8217;s created them. Later, we could easily extend the<br />
code, so they can be shared, or something like that&#8230;<br />
Note that<br />
by linking the saved filters to the CriteriaBuilder&#8217;s name, we&#8217;re<br />
able to use the same filters on different pages, by naming the<br />
CriteriaBuilders the same.</p>
<h4 class="green">Everything<br />
configurable!</h4>
<p>Now, you know<br />
what&#8217;s happening behind the scenes when a user uses our<br />
CriteriaBuilder, but that&#8217;s not even half the story. Still using our<br />
user grid, I&#8217;ll explain how the CriteriaBuilder&#8217;s FilterData objects<br />
are being initialized.</p>
<p>We<br />
use this code on our page (FYI: our pages are also created using an<br />
object-oriented framework)</p>
<p>[code]CB_pageContent[/code]</p>
<p style="margin-top: 0.2cm; margin-bottom: 0.2cm">So&#8230;<br />
We initialize our grid_propel, grid_users (<a href="/blog/custom-propel-grid-update">see this post</a>), and<br />
specify its starting <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a>. You can also neglect this, then a new<br />
(empty) <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a> will be used. Next, we use the CiteriaBuilder&#8217;s<br />
constructor to pass the grid as CriteriaClient, set its name, and set<br />
the original <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a>, which is used to restore the grid to its<br />
original state.</p>
<p>Now,<br />
that I come to think of it, this should be stored in the grid_propel,<br />
not in the CriteriaBuilder, because the original <a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a> can be<br />
different per client!<br />
You see this is code in progress&#8230; We<br />
actually don&#8217;t use multiple CriteriaBuilders nor CriteriaClients<br />
ourselves, yet&#8230; <img src='http://www.digitalbase.eu/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I simply added the method getOriginalCriteria<br />
to the interface class CriteriaClient. CriteriaBuilder::buildCriteria<br />
now retrieves its &#8216;<a href="http://propel.phpdb.org/trac/wiki/Development/Criteria" target="_blank">Criteria</a> to work with&#8217; via that method, thus from<br />
the grid_propel, which of course has an extra variable<br />
originalCriteria now. Grid_propel::setCriteria is now</p>
<p>[code]CB_setCriteria[/code]</p>
<p>Voila,<br />
solved!</p>
<p>Ok,<br />
to continue&#8230; $cb-&gt;qAddUserColumnSet<br />
is a convenience method.<br />
Admitted, these functions should better<br />
be in an extending class, but nobody&#8217;s perfect <img src='http://www.digitalbase.eu/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
And since we&#8217;re<br />
the only ones using it&#8230;</p>
<p>[code]CB_qAddUserColumnSet[/code]</p>
<p>As<br />
you can see, this method adds the columns we say the grid can be<br />
filtered on. These could also be columns which aren&#8217;t shown in the grid_propel.</p>
<p>[code]CB_qAddAvailableColumn[/code]</p>
<p style="margin-top: 0.2cm; margin-bottom: 0.2cm">So&#8230;<br />
In our case, we use the CriteriaBuilder&#8217;s constants, for example<br />
CriteriaBuilder::FILTERSET_TEXT<br />
stands for the array</p>
<p>[code]CB_ex_array[/code]</p>
<h4 class="green">UserFilter<br />
types</h4>
<p>This<br />
defines which &#8216;type&#8217; of UserFilter will be used. For each constant,<br />
there&#8217;s a descendant of UserFilter. They complete UserFilter by<br />
defining the abstract __toString function. So each descendant will be<br />
shown different.</p>
<h5 class="green">TYPE_TEXT</h5>
<p>simple inputfield</p>
<div style="text-align: center"><img title="UserFilter type text" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/type_text.png" border="0" alt="UserFilter type text" width="444" height="44" /></div>
<h5 class="green">TYPE_BOOLEAN</h5>
<p>simple select</p>
<div style="text-align: center"><img title="UserFilter type boolean" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/type_boolean.png" border="0" alt="UserFilter type boolean" width="446" height="113" /></div>
<h5 class="green">TYPE_DATE</h5>
<p>JavaScript calendar widget</p>
<div style="text-align: center"><img title="UserFilter type date" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/type_date.png" border="0" alt="UserFilter type date" /></div>
<h5 class="green">TYPE_SPECIFIC</h5>
<p>selector with values available in database for that column (=<br />
dynamic)</p>
<div style="text-align: center"><img title="UserFilter type specific" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/type_specific.png" border="0" alt="UserFilter type specific" /></div>
<h5 class="green">TYPE_SPECIFIC_SWITCH</h5>
<p>special specific, it has extra filtermethods &#8216;contains&#8217; &amp; &#8216;does<br />
not contain&#8217;. When this filter is selected the search value<br />
determinator, will change into an inputfield.</p>
<p>First</p>
<div style="text-align: center"><img title="UserFilter type specific_switch normal" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/type_specific_switch.png" border="0" alt="UserFilter type specific_switch normal" /></div>
<p>Then</p>
<div style="text-align: center"><img title="UserFilter type specific_switch for (does not) contains" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/type_specific_switch_after.png" border="0" alt="UserFilter type specific_switch for (does not) contains" /></div>
<h5 class="green">Of course, you can combine as many filters as you want.</h5>
<div style="text-align: center"><img title="use as many filters as you want" src="/uploads/assets//blog/Tutorials/CriteriaBuilder/combination.png" border="0" alt="combination of multiple UserFilters" width="445" height="255" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/xajax-driven-criteriabuilder-for-propel-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony / Propel &#8211; Subquerys</title>
		<link>http://www.digitalbase.eu/blog/symfony-propel-subquerys/</link>
		<comments>http://www.digitalbase.eu/blog/symfony-propel-subquerys/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 17:47:12 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=30</guid>
		<description><![CDATA[To reduce the query count in your web application, you might consider using subqueries. Propel has a way to do that.]]></description>
			<content:encoded><![CDATA[<p>
To reduce the query count in your web application, you might consider using subqueries. I&#39;ll show you howto do that in propel/symfony :
</p>
<p>[code]propel - subqueries[/code]</p>
<p>
It&#39;s that easy <img src='http://www.digitalbase.eu/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/symfony-propel-subquerys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplifying Queries: Using sum, count, etc in Propel</title>
		<link>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/</link>
		<comments>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 17:43:59 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=21</guid>
		<description><![CDATA[Using database functions like sum, count, etc in propel. A small explanation.]]></description>
			<content:encoded><![CDATA[<p>Simplifying Queries: Using sum, count, etc in Propel</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>addSelectColumn<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sum('</span><span style="color: #339933;">.</span>dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TOTAL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') as total'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelectRS</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rs</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getInt<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, simply use addSelectColumn. You have to work with the ResultSet offcourse, since you won&#8217;t be able to populateObjects.</p>
<p>In this case you can simply use &#8216;1&#8242; in getInt(column index), since we&#8217;re sure only one column is being fetched. Note that the index starts at 1 and not at 0.</p>
<p>Now, imagine a case where you are not sure what the index is (it could also change in the project&#8217;s life cycle). Then you can use, dbTimeBlockPeer::translateFieldName(dbTimeBlockPeer::TOTAL, BasePeer::TYPE_COLNAME, BasePeer::TYPE_NUM)), which will return the position of column &#8216;total&#8217;.</p>
<p>This needs no explanation, but I&#8217;ll give it anyway: translateFieldName accepts as first argument a string (source), the source type name and the destination type name. You can go and look in the basePeer which type you need.</p>
<p>basedbTimeBlockPeer (generated by Propel)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #990000;">static</span> <span style="color: #000088;">$fieldNames</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_PHPNAME</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UserId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ProjectId'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ticketnr'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Changeset'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'TimeIn'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'TimeOut'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Total'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_COLNAME</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">USER_ID</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">PROJECT_ID</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TICKETNR</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">CHANGESET</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">DESCRIPTION</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TIME_IN</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TIME_OUT</span><span style="color: #339933;">,</span> dbTimeBlockPeer<span style="color: #339933;">::</span><span style="color: #004000;">TOTAL</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_FIELDNAME</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'user_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'project_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ticketnr'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'changeset'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'time_in'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'time_out'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'total'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> BasePeer<span style="color: #339933;">::</span><span style="color: #004000;">TYPE_NUM</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/simplifying-queries-using-sum-count-etc-in-propel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Custom Propel Grid Update</title>
		<link>http://www.digitalbase.eu/blog/custom-propel-grid-update/</link>
		<comments>http://www.digitalbase.eu/blog/custom-propel-grid-update/#comments</comments>
		<pubDate>Sun, 25 Feb 2007 11:00:00 +0000</pubDate>
		<dc:creator>Bart Vanderstukken</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[propel]]></category>

		<guid isPermaLink="false">http://dibav3.gnelisse.desktop01/blog/?p=54</guid>
		<description><![CDATA[Our custom <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a> driven data grid has been refactored to separate the code for a basic html grid. The grid has been extended to export its data to excel. Due to several questions about releasing this code, hereâ€™s some insight in how the code is structured.]]></description>
			<content:encoded><![CDATA[<p>As you can read on <a title="Lifelog - Life as a young web developer" href="http://www.lifelog.be" target="_blank">Gijs&#8217; Lifelog</a>, he started developing a custom datagrid a while ago. The idea was to create some kind of module/object, which would be used for generating datagrids fast, easy and intuitive, without too much code.</p>
<p>Over time, it has been extended and rewritten to interact with our CriteriaBuilder (<a href="/blog/xajax-driven-criteriabuilder-for-propel-php">read blog</a>).</p>
<p>This week, I&#8217;ve been refactoring/cleaning the code to clearly separate the code for our <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a> driven datagrid from the basic html grid whose data could come from anywhere.</p>
<h2 class="green">Underlying code</h2>
<p>Due to several questions about releasing this code, here is some insight in how the code is structured, at this moment. Perhaps it will be released in the future, perhaps even as a symfony plugin, but we&#8217;re still indecisive about that.</p>
<p>So, we have an abstract grid class which contains all code needed to generate a basic html table. It has an array $columns, which holds grid_columns, and an $options array to manipulate its behaviour. One of them is the option â &#8220;pagable&#8221;, and if enabled the grid has to have a grid_pager set.</p>
<p>Grid_pager is an interface which defines what methods a pager (at least) should have and our grid_propel_pager implements that interface.</p>
<p>On __toString, the abstract function initfirstload is called. Its purpose is to set all columns and options, i.e. to define the grid. Then it calls display, which calls initdisplay. This function will do everything that has to be done before actually displaying the grid. The difference is that tostring is called once, and thus initfirstload too, while display &amp; initdisplay are called multiple times through xajax.</p>
<p>The displayHeader function calls displayHeaderon each column. The displayRows method is abstract. For a very simple grid it could call displayContent on each column.A grid_column holds all data for showing an html column, like its header name, alignment, whether it&#8217;s shown, sortable, etc&#8230; It has the following display methods (among others): displayHeader &amp; displayContent, which obviously return th and td strings.</p>
<h3 class="green">Now that&#8217;s all pretty abstract !</h3>
<p>Here&#8217;s how we use all of that in our grid_propel class, which uses grid_column_propels. The idea is that we could represent a table&#8217;s data fetched via <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a>.</p>
<p>Grid_propel extends the grid_paged class (containing the code for a grid to be paged via xajax), which extends the abstract grid class. Some display methods are overridden and the abstract displayRows method is implemented. It loops all objects we retrieve from the grid_propel_pager (which implements the grid_pager interface, remember). In the loop, displayContent is called on eachcolumn and the object is passed.</p>
<p>Grid_column_propel extends grid_column_method which extends grid_column. In grid_column_propel::displayContent, we use call_user_func_array to retrieve the content to be shown. It also has a guessGetter method which guesses the method based on the column&#8217;s peer constant name, so you don&#8217;t <span style="text-decoration: underline;">have</span> to provide it!</p>
<p>And voila, we have a fully <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3" target="_blank">Propel</a> driven html table, which is sorted and paged via xajax.</p>
<h3 class="green">Put it to work!</h3>
<p>If that&#8217;s Chinese to you, don&#8217;t worry because of the great principle of encapsulation:</p>
<p style="text-align: center;"><strong>YOU DON&#8217;T HAVE TO UNDERSTAND IT!</strong></p>
<p>Or to quote the textbook</p>
<blockquote><p>You don&#8217;t have know how a car works to drive it!</p></blockquote>
<p>Simply define your object class and columns that need to be shown. That&#8217;s all! Grid_propel will do the work for you!</p>
<p>Here&#8217;s an example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> grid_users <span style="color: #000000; font-weight: bold;">extends</span> grid_propel <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;_User&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init_firstload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">option_enable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sortable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$gridcontent</span> <span style="color: #339933;">=</span>  page_minimal<span style="color: #339933;">::</span><span style="color: #004000;">get_grid_contentobject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$bid</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">,</span>_UserPeer<span style="color: #339933;">::</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$bid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gridcontent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Login&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _UserPeer<span style="color: #339933;">::</span><span style="color: #004000;">LOGIN</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gridcontent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;First Name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _UserPeer<span style="color: #339933;">::</span><span style="color: #004000;">NAME_FIRST</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gridcontent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Family Name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _UserPeer<span style="color: #339933;">::</span><span style="color: #004000;">NAME_FAMILY</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gridcontent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _UserPeer<span style="color: #339933;">::</span><span style="color: #004000;">EMAIL</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gridcontent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Country&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _CountryPeer<span style="color: #339933;">::</span><span style="color: #004000;">COUNTRY</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;get_Country&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;getCountryShort&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When we use this in a page (and register the necessary xajax functions), this will result in:</p>
<div style="text-align: center"><img title="simple custom propel grid" src="/uploads/assets//blog/Tutorials/grid_propel/simple_grid_small.png" border="0" alt="simple custom propel grid" width="478" height="406" /></div>
<p class="green"><strong>You can also use your own methods (not propel-generated)!</strong></p>
<p>This really blows the grid wide open. You can call any method for the grid&#8217;s object class. You can even pass an array of methods. Every method is called on the result for the last call. The last method should of course return a string.</p>
<p>For example, adding</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> grid_column_method<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;getLink&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setArgs</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>will result in a clickable image that will pop up an information window:</p>
<div style="text-align: center"><img title="custom propel grid with own methods" src="/uploads/assets//blog/Tutorials/grid_propel/simple_grid2_small.png" border="0" alt="custom propel grid with own methods" width="591" height="333" /></div>
<p>Note that you can now use grid_column_method, the parent class of grid_column_propel. But, TIMTOWTDI, you could also use grid_column_propel, with an empty peer constant name.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;getLink&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you provide a name for such a non-propel column, you should also disable sorting for that column, since it has no peer constant name.</p>
<p class="green"><strong>Foreign key values</strong></p>
<p>Our user grid also contains a special column, Country. It&#8217;s actually a foreign key for the _user table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">column_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_column_propel<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gridcontent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Country&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _CountryPeer<span style="color: #339933;">::</span><span style="color: #004000;">COUNTRY</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;get_Country&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;getCountryShort&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We provide _CountryPeer::COUNTRY, the column used for sorting, so the results would be alphabetically sorted instead of being sorted by the foreign key. Our grid_propel takes care of the necessary joins.</p>
<p>We also provide an alternative method array, otherwise the getter is guessed by grid_column_propel, which would result in the methodarray(-&gt;get_Country-&gt;getCountry).</p>
<p><strong>O</strong><strong>ther descendants of grid_column</strong></p>
<p>We have also created a special grid_column, grid_action, which almost does the same as the information image. But again, it groups code.Grid_action_url extends this class and its goal is to easy generate such images.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_action_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application_edit.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;/userid/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Will produce an image linked to /userid/$id</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action_add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_action_js_delete<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_User&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Delete&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Will produce a &#8220;stop&#8221;-image which calls _User::Delete, via xajax, on the object related to the row.</p>
<h5 class="green">That&#8217;s all pretty neat, isn&#8217;t it? But, of course, that ain&#8217;t enough !</h5>
<p>Last week I&#8217;ve added some functionality to export the datagrid to an excel workbook using the Spreadsheet_Excel_Writer class. Grid_column_propel accepts extra arguments</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$excelwidth</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$excelname</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exportmethod</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exportargs</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$export</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #0000ff;">&quot;));</span></pre></td></tr></table></div>

<p>By default all columns will be exported. But if you want the export button to be shown, you need to enable the boolean export for the grid_propel.</p>
<p>You could also add columns (propel or method) to the grid which will only appear in the excel file, by simply disabling display for that column. Soon, I&#8217;ll add an extra argument $format, to control the layout in excel, column per column. And some constants to represent often used formatting.</p>
<p>All together, our user grid looks like this</p>
<div style="text-align: center"><img title="Our user grid" src="/uploads/assets//blog/Tutorials/grid_propel/grid_user_small.png" border="0" alt="Our user grid" width="592" height="335" /></div>
<p class="green"><strong>If that still isn&#8217;t enough for you&#8230;</strong></p>
<p>There&#8217;s also a class called grid_hook, which uses a grid_column_checkbox. Without going into details, this code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHook</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> grid_hook<span style="color: #009900;">&#40;</span>page_minimal<span style="color: #339933;">::</span><span style="color: #004000;">get_grid_contentobject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;edit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;multiEdit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>generates the edit hook on the bottom of this grid</p>
<div style="text-align: center"><img title="full option grid with hooks" src="/uploads/assets//blog/Tutorials/grid_propel/grid_waste_small.png" border="0" alt="full option grid with hooks" width="590" height="369" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalbase.eu/blog/custom-propel-grid-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
