Esempio n. 1
0
 /**
  * @see Zupal_Grid_IGrid::render_data()
  *
  * NOTE: the params argument is unused at this point
  *
  * @param array $pParams
  * @param unknown_type $pStart
  * @param unknown_type $pRows
  * @param unknown_type $pSort
  */
 public function render_data(array $pParams, $pStart = 0, $pRows = 100, $pSort = 'name')
 {
     $cache = Zupal_Media_MusicBrainz_Cache::getInstance();
     $key = 'artists_' . $pStart . '_' . $pRows . '_' . $pSort;
     if (array_key_exists('name', $pParams)) {
         $name = $pParams['name'];
         $key .= '_' . trim(preg_replace('~[\\W]+~', '_', $name));
     } else {
         $name = '';
     }
     if (!$cache->test($key)) {
         $count_sql = sprintf('SELECT count(id) FROM `%s`', $this->table()->tableName());
         if ($name) {
             $pParams['name'] = "{$name}%";
             $count_sql .= " WHERE `name` LIKE '{$name}%'";
         }
         error_log(__METHOD__ . ': count = ' . $count_sql);
         $select = $this->_select($pParams, $pSort);
         $select->limit($pRows, $pStart);
         $fsql = $select->assemble();
         //	error_log(__METHOD__ . ': '. $fsql);
         $rows = $this->table()->fetchAll($select);
         $items = array();
         foreach ($rows as $row) {
             $data = $row->toArray();
             foreach ($data as $k => $v) {
                 if (is_null($v)) {
                     $data[$k] = '';
                 }
             }
             $items[] = $data;
         }
         $count = $this->table()->getAdapter()->fetchOne($count_sql);
         $data = new Zend_Dojo_Data('id', $items, 'name');
         $data->setMetadata('numRows', $count);
         $cache->save($data, $key);
     }
     return $cache->load($key);
 }
Esempio n. 2
0
<?php

require_once dirname(__FILE__) . '/bootstrap.php';
$plugin = Zend_Registry::get('init');
$plugin->initDb();
$loader = new My_Controller_Helper_ResourceLoader();
$loader->initModule('spindle');
$request = $plugin->getRequest();
$model = $loader->getModel('Paste');
$dojoData = new Zend_Dojo_Data('id', $model->fetchActive($request->getQuery()), 'id');
$dojoData->setMetadata('count', $model->fetchActiveCount());
header('Content-Type: application/json');
echo $dojoData;