Skip to content

Instantly share code, notes, and snippets.

@radutopala
Created September 18, 2012 10:21
Show Gist options
  • Save radutopala/3742451 to your computer and use it in GitHub Desktop.
Save radutopala/3742451 to your computer and use it in GitHub Desktop.
Tree Widget example
<?php
class MyModelPeer extends BaseMyModelPeer {
public static function getStats($id)
{
//use $id for something
$stats['company1']['product1'] = array('items'=>5, 'price'=>5*10);
$stats['company1']['product2'] = array('items'=>9, 'price'=>9*2);
$stats['company2']['product3'] = array('items'=>12, 'price'=>12*3);
$stats['company2']['product4'] = array('items'=>105, 'price'=>105*23);
$stats['company3']['product5'] = array('items'=>99, 'price'=>99*19);
$stats['company3']['product6'] = array('items'=>5, 'price'=>5*2);
$data = array(); $k = -1;
foreach ($stats as $company=>$products)
{
$k++;
$pk = $k;
$data[$pk] = array('_id'=>$k,'name'=>$company,'items'=>0,'price'=>0,'_parent'=>null,'_is_leaf'=>false);
foreach ($products as $product=>$statTypes)
{
$data[$pk]['items']+=$statTypes['items'];
$data[$pk]['price']+=$statTypes['price'];
$k++;
$data[$k] = array('_id'=>$k,'name'=>$product,'items'=>$statTypes['items'],'price'=>$statTypes['price'],'_parent'=>$pk,'_is_leaf'=>true);
}
}
return $data;
}
} // MyModelPeer
<?xml version="1.0" encoding="UTF-8"?>
<i:view xmlns:i="http://www.appflower.com/schema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" type="list" xsi:schemaLocation="http://www.appflower.com/schema/appflower.xsd">
<i:title><![CDATA[Statistics]]></i:title>
<i:datasource type="static">
<i:class>MyModelPeer</i:class>
<i:method name="getStats" type="static">
<i:param name="pv1">{id}</i:param>
</i:method>
</i:datasource>
<i:fields tree="true">
<i:column label="Name" name="name"/>
<i:column label="Total Sold Items" name="items"/>
<i:column label="Total Sold Value" name="price"/>
</i:fields>
</i:view>
<?php
class statsAction extends sfAction
{
/**
* Execute actions
*
* @param sfWebRequest $request
*/
public function execute($request)
{
$this->id = $request->getParameter('id');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment