<?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>CodeBlog.ch &#187; JavaScript</title>
	<atom:link href="http://www.codeblog.ch/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeblog.ch</link>
	<description>Coding and more - Concrete5, Flex, JavaScript</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:10:29 +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>concrete5 SooperFish drop down navigation</title>
		<link>http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navigation/</link>
		<comments>http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navigation/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 16:09:26 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=539</guid>
		<description><![CDATA[Creating a drop down navigation is an old technique by now but it&#8217;s still used in a lot of cases to hide parts of a navigation. In addition to the plain CSS menu I wrote more than 2 years ago, I decided to write a new tutorial which uses JavaScript as well. You might ask [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a drop down navigation is an old technique by now but it&#8217;s still used in a lot of cases to hide parts of a navigation. In addition to the plain CSS menu I wrote more than 2 years ago, I decided to write a new tutorial which uses JavaScript as well. You might ask why: Avoiding JavaScript is nice but creating something as complex as a drop down navigation without any JavaScript leads to a few ugly work arounds. You&#8217;ll also have some difficulties to add a fade out and fade in effect unless you&#8217;re using CSS3 which isn&#8217;t well supported yet.</p>
<p>But at the end it&#8217;s up to you, both solutions can work just fine! </p>
<p>Using SooperFish is also a bit easier for us, you&#8217;ll see at the end of the tutorial how little code you needed.<br />
At the end your navigation can look like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/12/drop-down.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/12/drop-down.png" alt="" title="drop-down" width="445" height="145" class="alignnone size-full wp-image-540" /></a></p>
<p><span id="more-539"></span></p>
<h2>Prerequisite to create your drop down menu</h2>
<p>It&#8217;s rather simple, the only thing you need is the jQuery drop down plugin called SooperFish. You can find a link to download it on this page: <a href="http://www.sooperthemes.com/open-source/jquery/jquery-sooperfish-dropdown-menus" target="_blank">http://www.sooperthemes.com/open-source/jquery/jquery-sooperfish-dropdown-menus</a>.</p>
<p>Once you&#8217;ve got the ZIP file, extract all the files into a folder of your choice, we&#8217;ll later use some (not all) files from it.</p>
<h2>Creating a new block template</h2>
<p>If you worked with concrete5 before you&#8217;ll probably know that you should never modify any files located in the &#8220;concrete&#8221; directory. It&#8217;s part of the CMS core which gets overwritten whenever you update to a newer version of concrete5. Luckily this isn&#8217;t necessary for lots of things! We can easily create an addon, or a block template in this case, without touching the core at all.</p>
<p>In the root of your website, open the folder called &#8220;blocks&#8221; and go though these steps:</p>
<ul>
<li>Create a folder called &#8220;autonav&#8221;</li>
<li>Within &#8220;autonav&#8221;, create a folder called &#8220;templates&#8221;</li>
<li>Within &#8220;templates&#8221;, create a folder called &#8220;sooperfish&#8221;</li>
<li>In the last directory you created, &#8220;sooperfish&#8221;, create a file called &#8220;view.php&#8221; and put the following content in it:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</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: #000088;">$bvt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BlockViewTemplate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$bvt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBlockCustomTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> callback<span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class=&quot;nav&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class=&quot;sf-menu&quot; id=&quot;nav&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$buffer</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: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;callback&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bvt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTemplate</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: #990000;">ob_end_flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<blockquote>
<h3>Background information about the autonav template view.php</h3>
<p> What does this template do?</p>
<p>Since the HTML structure needed by SooperFish is almost identical with the default autonav template, we don&#8217;t copy the whole template which would create a lot of redundant information. Instead we include the default template in our new template. However, there are still a few things we modified. The original template has an element like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nav&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>but we want this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf-menu&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nav&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>Having this element allows us to use the default CSS files shipped with the Sooperfish plugin. You could modify the CSS files as well and remove all the output buffering functions in the code above.
</p></blockquote>
<ul>
<li>Create another file in the same directory called &#8220;view.js&#8221; and put this content in it:</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.sf-menu'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">sooperfish</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;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<ul>
<li>In the directory where you created &#8220;view.php&#8221; and &#8220;view.js&#8221;, create another directory called &#8220;js&#8221;</li>
<li>From the SooperFish ZIP, copy &#8220;jquery.sooperfish.min.js&#8221; and &#8220;jquery.easing-sooper.js&#8221; into the &#8220;js&#8221; directory.</li>
<li>On the same level as &#8220;js&#8221;, create another directory called &#8220;css&#8221;</li>
<li>From the Sooperfish ZIP, copy &#8220;sooperfish.css&#8221; and &#8220;sooperfish-theme-black.css&#8221; into the directory called &#8220;css&#8221;</li>
</ul>
<p>We&#8217;ve already created and copied all the files we need, the only thing we have to do is to make sure our new template is used. Your file structure should look like this now:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2011/12/file-structure.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/12/file-structure.png" alt="" title="file-structure" width="131" height="129" class="alignnone size-full wp-image-545" /></a></p>
<p>Go to your page and start editing the page and modify the autonav block to make these settings:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/12/autonav-settings.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/12/autonav-settings-470x400.png" alt="" title="autonav-settings" width="470" height="400" class="alignnone size-medium wp-image-544" /></a></p>
<p>It&#8217;s important that you select &#8220;Display all&#8221; in both &#8220;Sub Pages To Display&#8221; and &#8220;Sub-Page Levels&#8221;. When you work with a JavaScript based navigation you usually print all the items into the HTML output, but hide some of them using JavaScript. Click on Update when you&#8217;re done and click on the block you modified again, but this time select &#8220;Custom Template&#8221; and select &#8220;Sooperfish&#8221; and click on &#8220;Update&#8221; again.</p>
<p>Publish the changes and you&#8217;ll see your new drop down navigation!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=539&amp;md5=efd57ee1e4b77af4c9788a0487dceb10" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2011/12/concrete5-sooperfish-drop-down-navigation/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>concrete5 &#8211; AJAX Add-on to display File Download Statistics</title>
		<link>http://www.codeblog.ch/2011/06/concrete5-ajax-add-on-to-display-file-download-statistics/</link>
		<comments>http://www.codeblog.ch/2011/06/concrete5-ajax-add-on-to-display-file-download-statistics/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 14:53:15 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Concrete5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=504</guid>
		<description><![CDATA[Today&#8217;s article is about concrete5 again after a long time without anything about concrete5 on codeblog.ch. The example we&#8217;re going to look at takes a few ideas and code snippets from my book about concrete5. If you ever had a closer look at the file manager you&#8217;ve probably seen that if you open the file [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s article is about concrete5 again after a long time without anything about concrete5 on codeblog.ch. The example we&#8217;re going to look at takes a few ideas and code snippets from <a href="http://bit.ly/huEpPo">my book about concrete5</a>.</p>
<p>If you ever had a closer look at the file manager you&#8217;ve probably seen that if you open the file properties, you can see a small statistics about the downloads of a file. This is quite nice but what if you wanted to see how many file downloads there are in total? Right now, there&#8217;s no such report available in concrete5 which is why we&#8217;re going to build the first part of such an addon.</p>
<p>It will use some AJAX to switch between different views, allowing us to extend it even further in the future. At the end you&#8217;ll have an additional page in the reports section like this:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2011/06/file_download_statistics.png"><img src="http://www.codeblog.ch/wp-content/uploads/2011/06/file_download_statistics-500x256.png" alt="" title="file_download_statistics" width="500" height="256" class="alignnone size-medium wp-image-505" /></a></p>
<p><span id="more-504"></span></p>
<p>This article uses a few different elements of concrete5, having some experience with blocks, templates, themes and packages is highly recommended. I&#8217;m not going to explain every detail but I&#8217;m happy to answer questions in case something&#8217;s missing.</p>
<p>First, let&#8217;s have a look at the package installer:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>    
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>_<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportPackage <span style="color: #000000; font-weight: bold;">extends</span> Package <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$pkgHandle</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'remo_file_report'</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$appVersionRequired</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'5.4'</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$pkgVersion</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPackageDescription<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Adds a file download statistic report&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> getPackageName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;File Report&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> install<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$pkg</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">install</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      Loader<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'single_page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$sp</span> <span style="color: #339933;">=</span> SinglePage<span style="color: #339933;">::</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dashboard/reports/remo_file_report'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pkg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$sp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'File Report'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cDescription'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'File Download Statistic'</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: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see, the package controller is pretty small. Beside the usual package information fields and methods, we only override the install method to add a custom page located at /dashboard/reports/remo_file_report. By adding out page beneath the dashboard reports, we&#8217;ll automatically see our new page as a new register in the dashboard. Nothing else has to be done in order to make sure the page appears where it should.</p>
<h2>Page controller &#038; view</h2>
<p>Since we&#8217;re adding a new page, we&#8217;ll have to add a controller as well as a file for the single page output. First, we create a file in packages/remo_file_report/controllers/dashboard/reports/remo_file_report.php with this content:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DashboardReportsRemoFileReportController <span style="color: #000000; font-weight: bold;">extends</span> Controller <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> view<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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> on_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</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;">addHeaderItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">css</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remo.filereport.css'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remo_file_report'</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;">addHeaderItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">javascript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'remo.filereport.js'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remo_file_report'</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>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Again, this file is small, we only make sure that our CSS and JavaScript file are properly included in the head of the page. If you&#8217;ve created single pages before, you&#8217;ve probably added some code to the view method in order to pass some data to the output of the single page. In our case, this is not necessary since we load our content with the help of AJAX.</p>
<p>Next, create a file for our output packages/remo_file_report/single_pages/dashboard/reports/remo_file_report.php and put this content in it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;h1&gt;&lt;span&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File Download Statistics'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt;&lt;/h1&gt;
&nbsp;
&lt;div class=&quot;ccm-dashboard-inner&quot;&gt;
      &lt;div id=&quot;remo-file-report-links-1&quot;&gt;
      &lt;a href=&quot;#&quot; data-action=&quot;day&quot;   class=&quot;remo-file-report-link&quot; id=&quot;remo-file-report-week&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Day'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
      &lt;a href=&quot;#&quot; data-action=&quot;week&quot;  class=&quot;remo-file-report-link&quot; id=&quot;remo-file-report-week&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Week'</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
   &lt;/div&gt;
&nbsp;
   &lt;div id=&quot;remo-file-report-content&quot;&gt;
&nbsp;
   &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Besides a caption and two links to switch between the two views &#8220;day&#8221; and &#8220;week&#8221;, there&#8217;s only an empty DIV element with the id &#8220;remo-file-report-content&#8221; where we&#8217;re going to add some content with the help of a little JavaScript.</p>
<h2>CSS to format File Report</h2>
<p>In the page controller, we&#8217;ve included two files, one for a few basic styles and one for the AJAX logic. Let&#8217;s create the CSS file first at this location packages/remo_file_report/css/remo.filereport.css:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#remo-file-report-links-1</span> a <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#remo-file-report-</span><span style="color: #000000; font-weight: bold;">content</span> table <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#remo-file-report-</span><span style="color: #000000; font-weight: bold;">content</span> th <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2>JavaScript and PHP backend file to handle the AJAX procedures</h2>
<p>The next file is the one which holds all the JavaScript and thus the AJAX magic. It has to be created here packages/remo_file_report/js/remo.filereport.js:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.remo-file-report-link&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>CCM_TOOLS_PATH <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/../packages/remo_file_report/get_data/&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>action<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data-action&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #006600; font-style: italic;">// select the correct renderer to print the data</span>
         <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">data</span>.<span style="color: #660066;">renderer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #339933;">:</span>
               <span style="color: #003366; font-weight: bold;">var</span> rowHeader <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> tableBody <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> rowHeaderPrinted <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// loop through all rows</span>
               <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> rowKey <span style="color: #000066; font-weight: bold;">in</span> data.<span style="color: #660066;">data</span>.<span style="color: #660066;">tableData</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  <span style="color: #003366; font-weight: bold;">var</span> rowData <span style="color: #339933;">=</span> data.<span style="color: #660066;">data</span>.<span style="color: #660066;">tableData</span><span style="color: #009900;">&#91;</span>rowKey<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
                  tableBody <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;tr&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                  <span style="color: #006600; font-style: italic;">// loop through all columns</span>
                  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> colKey <span style="color: #000066; font-weight: bold;">in</span> rowData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>rowHeaderPrinted<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        rowHeader <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;th&gt;&quot;</span> <span style="color: #339933;">+</span> colKey.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'_'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/th&gt;&quot;</span><span style="color: #339933;">;</span> 
                     <span style="color: #009900;">&#125;</span>
&nbsp;
                     tableBody <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;td&gt;&quot;</span> <span style="color: #339933;">+</span> rowData<span style="color: #009900;">&#91;</span>colKey<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
                  <span style="color: #009900;">&#125;</span>
                  tableBody <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                  rowHeaderPrinted <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
&nbsp;
               <span style="color: #006600; font-style: italic;">// put generated markup in DIV</span>
               $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#remo-file-report-content&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;table&gt;&lt;tr&gt;&quot;</span> <span style="color: #339933;">+</span> rowHeader <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/tr&gt;&quot;</span> <span style="color: #339933;">+</span> tableBody <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/table&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
               <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
               <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Unsupported rendered: &quot;</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">data</span>.<span style="color: #660066;">renderer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this file we&#8217;re doing the following things:</p>
<ul>
<li>Set an event which is executed when the user clicks on the links (day or week)</li>
<li>Execute an AJAX call by using <a href="http://api.jquery.com/jQuery.post/" target="_blank">$.post</a></li>
<li>Once we get the result back, we&#8217;re detected the correct rendered. Right now, there&#8217;s just &#8220;table&#8221; but this could be extended to create a different output type like a chart</li>
<li>We then loop though all the data we&#8217;ve gotten from the AJAX tool</li>
<li>Last, we&#8217;re going to add the generated content to our DIV element with the ID remo-file-report-content</li>
</ul>
<p>Our AJAX call uses a file which we&#8217;re accessing using this URL: CCM_TOOLS_PATH + &#8220;/../packages/remo_file_report/get_data/&#8221;. This file is located in the tools folder of our package which is probably the most common way in concrete5 to generate data for an AJAX script. Create a new file at this location packages/remo_file_report/tools/get_data.php and put this content in it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
try <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$jh</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   Loader<span style="color: #339933;">::</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;remo_file_report&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;remo_file_report&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// make sure the user is allowed to access the file download statistic.</span>
   <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Permissions<span style="color: #009900;">&#40;</span>Page<span style="color: #339933;">::</span><span style="color: #004000;">getByPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/dashboard/reports/remo_file_report'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canRead</span><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: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Not allowed to access the JSON tools to fetch the file statistics.'</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: #666666; font-style: italic;">// execute action to get the file download data</span>
   <span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$actionObject</span> <span style="color: #339933;">=</span> RemoFileReportModel<span style="color: #339933;">::</span><span style="color: #004000;">getActionInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$actionObject</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$jh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>What&#8217;s in this file?</p>
<ul>
<li>We load two elements, the <a href="http://www.concrete5.org/api/Helpers/JsonHelper.html">JSON helper</a> because we&#8217;re going to return our data in this format,</li>
<li>the remo_file_report model which is where we put all the database logic</li>
<li>We also make sure that only users who are allowed to access the dashboard page are allowed to use this file. Without this check it would be possible to access our download statistics by using a direct URL, even if one doesn&#8217;t have the permission to do so.</li>
<li>Next, we&#8217;re going to call a method from our model from which we&#8217;ll get all the data</li>
<li>Most of the file has been wrapped in a try&#8230;catch block. This is helpful because if you format data in JSON you won&#8217;t be able to parse the output in your JavaScript if there&#8217;s a PHP error message. By using a try and catch block, we can handle all the possible errors and pass them on to our JavaScript where we can show them to the user</li>
<li>At the end we&#8217;re going to use the JSON helper from concrete5 to return the data echo $jh->encode($ret);</li>
</ul>
<h2>Model to fetch Download Statistics from the database</h2>
<p>The only file that&#8217;s missing now, is the model which we&#8217;re calling from the &#8220;tool&#8221; to get our download statistics out of the database. Create this file packages/remo_file_report/models/remo_file_report.php with this content:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'C5_EXECUTE'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Access Denied.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportModel <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getActionInstance<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;">switch</span> <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;">case</span> <span style="color: #0000ff;">'day'</span><span style="color: #339933;">:</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> RemoFileReportDay<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">'week'</span><span style="color: #339933;">:</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> RemoFileReportWeek<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Unsupported action in model remo_file_report.php.'</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>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> IRemoFileReport <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</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;">class</span> RemoFileReportDay implements IRemoFileReport <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">db</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'renderer'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'table'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tableData'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT fv.fvFilename Filename,count(*) Download_Count
         FROM DownloadStatistics ds INNER JOIN FileVersions fv ON ds.fID=fv.fID AND ds.fvID=fv.fvID
         WHERE date(timestamp) = CURRENT_DATE
         GROUP BY fv.fID, fv.fvID, fv.fvFilename
         ORDER BY count(*) DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RemoFileReportWeek implements IRemoFileReport <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Loader<span style="color: #339933;">::</span><span style="color: #004000;">db</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'renderer'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'table'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tableData'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT fv.fvFilename Filename,count(*) Download_Count
         FROM DownloadStatistics ds INNER JOIN FileVersions fv ON ds.fID=fv.fID AND ds.fvID=fv.fvID
         WHERE YEARWEEK(timestamp) = YEARWEEK(CURRENT_DATE) 
         GROUP BY fv.fID, fv.fvID, fv.fvFilename
         ORDER BY count(*) DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This file is a bit bigger but doesn&#8217;t do a lot at all, what&#8217;s in it?</p>
<ul>
<li>The getActionInstance method in the RemoFileReportModel class simply returns the proper class matching the requested action. Splitting every action into a different class isn&#8217;t necessary but could be helpful once we add more parts to our report</li>
<li>Since we&#8217;ve splitted our actions into classes, we also define an interface to assure that action classes implement the necessary getData method</li>
<li>The two classes RemoFileReportDay and RemoFileReportWeek are almost identical, the just execute a simple SQL command to fetch the data and return it as an array</li>
</ul>
<h2>Download and next steps</h2>
<p>After all these words, you can download the code and extract it to the &#8220;packages&#8221; directory of your concrete5 site and install it by using the &#8220;Add Functionality&#8221; section in the dashboard&#8221;.</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2011/06/remo_file_report.zip'>Download File Report Add-On</a></p>
<p>This Add-on isn&#8217;t complete, as you&#8217;ve seen on the screenshot at the beginning of this post, you can&#8217;t find a lot of information in the output. A few things which are missing:</p>
<ul>
<li>Pictures are often helpful to get a first and quick impression, some charts would be nice</li>
<li>Different sections to split information into different parts of the report</li>
<li>Automatically display a statistic, right now you have to click on day or week in order to see something</li>
<li>An export which produces an XLS(X) or PDF report</li>
<li>Some information about the file types maybe</li>
</ul>
<p>And a lot more! I&#8217;m you have a lot of ideas yourself, if you want to add something or have any questions about this code / tutorials, don&#8217;t hesitate to leave a comment!</p>
 <p><a href="http://www.codeblog.ch/?flattrss_redirect&amp;id=504&amp;md5=73871456bfab164a212dbe121f424613" title="Flattr" target="_blank"><img src="http://www.codeblog.ch/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/2011/06/concrete5-ajax-add-on-to-display-file-download-statistics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

