<?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>Dave Rowe's Blog &#187; php</title>
	<atom:link href="http://blog.roweware.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.roweware.com</link>
	<description>Ramblings about things I think I know...</description>
	<lastBuildDate>Tue, 18 Jan 2011 21:28:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ChartDirector with PHP</title>
		<link>http://blog.roweware.com/2010/03/02/chartdirector-with-php/</link>
		<comments>http://blog.roweware.com/2010/03/02/chartdirector-with-php/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:30:11 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[chartdirector]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=189</guid>
		<description><![CDATA[For a project, we have the need to create charts dynamically from data.  In another project, we&#8217;ve used ChartDirector for this.  It has worked great there, so we pulled it into this project as well.  Now, the type of charts I was working with in particular is a stacked percentage chart, which is kind of [...]]]></description>
			<content:encoded><![CDATA[<p>For a project, we have the need to create charts dynamically from data.  In another project, we&#8217;ve used <a href="http://www.advsofteng.com/">ChartDirector</a> for this.  It has worked great there, so we pulled it into this project as well.  Now, the type of charts I was working with in particular is a stacked percentage chart, which is kind of like a mash between a pie chart and a traditional bar chart.  An example:</p>
<p><a href="http://blog.roweware.com/wp-content/uploads/2010/03/percentbar.png"><img class="alignnone size-full wp-image-191" title="percentbar" src="http://blog.roweware.com/wp-content/uploads/2010/03/percentbar.png" alt="Percentage Bar" width="510" height="330" /></a></p>
<p>Now, with dynamic data, you can&#8217;t predict what your data will look like, and your code needs to be flexible enough to handle any situation without causing headaches for the user.  With ChartDirector, you pass in datasets via arrays across the chart, so for example the above datasets would be created by:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1893"><td class="code" id="p189code3"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data0</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">245</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">67</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">156</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">179</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">211</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">87</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">56</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Such that, the numbers line up in the arrays (vertically) in how they correspond to the resulting chart.  In my situation and test data, I found I had a situation like the following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p189code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1894"><td class="code" id="p189code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data0</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">147</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">67</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data1</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">156</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">211</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">123</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data2</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">87</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">267</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So, the bar for the 3rd item in the chart would be distributed equally as 33.33% when, in fact, there was no data.  I assumed the chart would display a blank spot for that bar.  After searching the less than optimal support forums (to no fault of the creators / maintainers), I found I needed to instead use a constant defined in the ChartDirector code &#8211; &#8216;NoValue&#8217;, where I had&#8230;wait for it&#8230;.no value.  Putting a small check in my code to replace zeros with &#8216;NoValue&#8217; proved to produce the results I was after.</p>
<p>Note to fellow developers: If you&#8217;re posting in a forum for assistance, please be more verbose in your subject line.  It <em>really</em> helps with searching if the subject can provide some bit of context around what the problem is.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2010/03/02/chartdirector-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>External Login to phpBB</title>
		<link>http://blog.roweware.com/2010/01/26/external-login-to-phpbb/</link>
		<comments>http://blog.roweware.com/2010/01/26/external-login-to-phpbb/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 22:29:55 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpBB]]></category>
		<category><![CDATA[single-sign-on]]></category>
		<category><![CDATA[sso]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=172</guid>
		<description><![CDATA[Recently, I was tasked with creating a single-sign-on solution for phpBB, where the user would login to our application, and when clicking a link to take them to a support forum, they&#8217;d already be logged in. phpBB isn&#8217;t known for having a great API with which to integrate, but the code works, and the product [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was tasked with creating a single-sign-on solution for phpBB, where the user would login to our application, and when clicking a link to take them to a support forum, they&#8217;d already be logged in.  phpBB isn&#8217;t known for having a great API with which to integrate, but the code works, and the product works.  The authentication works on the premise of providing credentials, logging in, which creates a session in the phpBB database.  A cookie value is set, which ties the user to the server-side session.  When you have the 2 disparate systems, the domains might be different, but on the same top-level domain.  This means if we could get the session ID and set a cookie on the next domain level up, we could be logged in.</p>
<p>The implementation is fairly simple, upon login, we use cURL or something similar and generate a POST request, using the username and password.  The remote script grabs the session ID and user ID and returns the values to the originating server.  We then, set the cookie values.</p>
<p>Now, the interesting bit.  phpBB has multiple layers by which it validates the session.  Since our remote server is originating the request, we don&#8217;t have the same IP as the user.  Second, it uses the User-Agent string of the browser to validate the session.  Using cURL, we don&#8217;t have a browser.  Now, with cURL, you can set various settings (User-Agent string, X-Forwarded-For header, etc) &#8211; but if you&#8217;d rather not depend on that, you can simply un-check those settings in phpBB.</p>
<p>Of course, I&#8217;d recommend using the cURL settings, but to get you started and ensure the connectivity is working.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2010/01/26/external-login-to-phpbb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZFDataGrid &#8211; Enabling Export</title>
		<link>http://blog.roweware.com/2009/12/29/zfdatagrid-enabling-export/</link>
		<comments>http://blog.roweware.com/2009/12/29/zfdatagrid-enabling-export/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 22:41:33 +0000</pubDate>
		<dc:creator>Dave Rowe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zfdatagrid]]></category>

		<guid isPermaLink="false">http://blog.roweware.com/?p=159</guid>
		<description><![CDATA[I&#8217;m evaluating a DataGrid for use in a project which is using the Zend Framework, and I came across the ZFDataGrid project.  Fantastic work, and the grid works wonderfully.  It enables you to filter your data and export it in various formats (PDF, Doc, Docx, OpenOffice, etc).  The sample on the site works exactly like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m evaluating a DataGrid for use in a project which is using the <a href="http://framework.zend.com/">Zend Framework</a>, and I came across the <a href="http://code.google.com/p/zfdatagrid/">ZFDataGrid</a> project.  Fantastic work, and the grid works wonderfully.  It enables you to filter your data and export it in various formats (PDF, Doc, Docx, <a href="http://www.openoffice.org/">OpenOffice</a>, etc).  The <a href="http://www.petala-azul.com/grid/">sample</a> on the site works exactly like this.  The only issue is the manual doesn&#8217;t exactly explain how to enable the export functionality.  It doesn&#8217;t &#8216;just work&#8217;, but it was reasonably easy to find since the code for the sample site is in <a href="http://code.google.com/">Google Code</a>.  But, it isn&#8217;t in an intuitive place like the manual or on the site itself.  So, to hopefully save someone else some time, I&#8217;ll post the code here &#8211; it is from the sample <a href="http://code.google.com/p/zfdatagrid/source/browse/trunk/application/controllers/SiteController.php">SiteController</a>, and not originally written by me.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p159code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1596"><td class="code" id="p159code6"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$export</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'export'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$export</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'odt'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Odt&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'ods'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Ods&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'xml'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Xml&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'csv'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Csv&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'excel'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Excel&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'word'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Word&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'wordx'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Wordx&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'pdf'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Pdf&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'print'</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Print&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">default</span> <span style="color: #339933;">:</span>
        <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Bvb_Grid_Deploy_Table&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$grid</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'DataGrid Example'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/tmp'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'download'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDataFromCsv</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/Detail_Limited.csv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imagesUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/images/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">grid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$grid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deploy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The code at the end is mine, which basically tells the DataGrid where to render/save the exported file, which is then immediately sent for download.  I also am not using the Zend_Db stuff for the data.  As a proof-of-concept, I&#8217;m using a simple dataset in CSV, which works amazingly well.  The filters, sorting, and pagination still work with CSV.</p>
<p>I&#8217;m thinking about writing an adapter for <a href="http://www.doctrine-project.org/">Doctrine</a>, such that one could construct a Doctrine query object, pass it into the DataGrid, and everything would work, as it does with the Zend_Db counterparts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.roweware.com/2009/12/29/zfdatagrid-enabling-export/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

