Example #1
0
 /**
  * Prepare data for autocompletion
  *
  * @param  mixed   $data
  * @param  boolean $keepLayouts
  * @return string
  */
 public function prepareAutoCompletion($data, $keepLayouts = false)
 {
     if (!$data instanceof DojoData) {
         $items = array();
         foreach ($data as $key => $value) {
             $items[] = array('label' => $value, 'name' => $value);
         }
         $data = new DojoData('name', $items);
     }
     if (!$keepLayouts) {
         $this->getBroker()->load('viewRenderer')->setNoRender(true);
         $layout = Layout::getMvcInstance();
         if ($layout instanceof Layout) {
             $layout->disableLayout();
         }
     }
     $response = FrontController::getInstance()->getResponse();
     $response->setHeader('Content-Type', 'application/json');
     return $data->toJson();
 }
Example #2
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')));
     $json = Json::encode($data);
     $dojoData = new DojoData();
     $dojoData->fromJson($json);
     $test = $dojoData->toArray();
     $this->assertEquals($data, $test);
 }