public function getAction()
 {
     $this->rescanItems();
     //@TODO: handle the query with $this->_getParam(...)
     $data = new Zend_Dojo_Data('id', $this->_items, "name");
     echo $data->toJson();
 }
Esempio n. 2
0
    /**
     * Prepare data for autocompletion
     *
     * @param  mixed   $data
     * @param  boolean $keepLayouts
     * @return string
     */
    public function prepareAutoCompletion($data, $keepLayouts = false)
    {
        if (!$data instanceof Zend_Dojo_Data) {
            require_once 'Zend/Dojo/Data.php';
            $items = array();
            foreach ($data as $key => $value) {
                $items[] = array('label' => $value, 'name' => $value);
            }
            $data = new Zend_Dojo_Data('name', $items);
        }

        if (!$keepLayouts) {
            require_once 'Zend/Controller/Action/HelperBroker.php';
            Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);

            require_once 'Zend/Layout.php';
            $layout = Zend_Layout::getMvcInstance();
            if ($layout instanceof Zend_Layout) {
                $layout->disableLayout();
            }
        }

        $response = Zend_Controller_Front::getInstance()->getResponse();
        $response->setHeader('Content-Type', 'application/json');

        return $data->toJson();
    }
Esempio n. 3
0
 /**
  *
  * @param string $pID, $pData, $pLabel
  * @return void
  */
 public function _store($pID, $pData, $pLabel)
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $zd = new Zend_Dojo_Data($pID, $pData, $pLabel);
     echo $zd->toJson();
 }
Esempio n. 4
0
 public function tracksAction()
 {
     $artistId = $this->_request->getParam('id');
     $releaseTable = new App_Table_Release();
     $releases = $releaseTable->findPublishedByArtist($artistId, false)->toArray(true);
     $data = new Zend_Dojo_Data('id', $releases, 'releases');
     echo $data->toJson();
 }
Esempio n. 5
0
 public function townsAction()
 {
     $municipality = $this->_getParam('municipality');
     $db = Zend_Db_Table::getDefaultAdapter();
     $towns = $db->fetchAll("SELECT id, name FROM Town WHERE code = ?", $municipality);
     $data = new Zend_Dojo_Data('id', $towns);
     $data->setLabel('name');
     $this->_helper->json($data);
 }
Esempio n. 6
0
 /**
  * List action
  *
  * @return void
  */
 public function listAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $q = Doctrine_Query::create()->from('Worklog w');
     $data = new Zend_Dojo_Data();
     $data->setIdentifier('id')->addItems($q->execute(array(), Doctrine::HYDRATE_ARRAY));
     echo $data->toJson();
 }
 public function getAction()
 {
     // Get the Parameters
     $pId = $this->getRequest()->getParam("id");
     // Get the DatabaseAdapter
     $db = $this->_helper->database->getAdapter();
     // 	see http://framework.zend.com/manual/en/zend.db.select.html
     //	you could also write the query as plain string lie SELECT * FROM user;
     //
     $select = $db->select()->from('user')->where('id = ?', $pId);
     // sql-injection save quotation
     $data = new Zend_Dojo_Data('id', $db->fetchAll($select), 'name');
     echo $data->toJson();
 }
Esempio n. 8
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. 9
0
 public function testShouldAllowPopulationFromJson()
 {
     $data = array('identifier' => 'id', 'label' => 'title', 'items' => array(array('id' => 1, 'title' => 'One', 'name' => 'First'), array('id' => 2, 'title' => 'Two', 'name' => 'Second'), array('id' => 3, 'title' => 'Three', 'name' => 'Third'), array('id' => 4, 'title' => 'Four', 'name' => 'Fourth')));
     require_once 'Zend/Json.php';
     $json = Zend_Json::encode($data);
     $dojoData = new Zend_Dojo_Data();
     $dojoData->fromJson($json);
     $test = $dojoData->toArray();
     $this->assertEquals($data, $test);
 }
Esempio n. 10
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;