Example #1
0
 /**
  * The function returns JSON responses for different methods.
  * 
  * @access public
  * @param string $method THe method.
  * @return string The JSON response.
  */
 public function json($method = null)
 {
     $response = array();
     switch ($method) {
         case 'tags':
             $Tag = new Tag();
             $params = array();
             $params[] = $Tag->getParam('search', Request::get('term'));
             foreach ($Tag->findList($params, 'Name asc', 0, 20) as $Tag) {
                 $response[] = $Tag->Name;
             }
             break;
         case 'ref':
             $Object = null;
             $params = array();
             if (Request::get('field') == 'Reference[Page]') {
                 $Object = new Content_Page();
             } else {
                 if (Request::get('field') == 'Reference[Product]') {
                     $Object = new Product();
                 }
             }
             if ($Object) {
                 $params[] = $Object->getParam('search', Request::get('term'));
                 foreach ($Object->findShortList($params, 'Name asc', 0, 10) as $Object) {
                     printf("%d|%s\n", $Object->Id, $Object->Name);
                 }
             }
             exit;
             break;
     }
     return $this->outputJSON($response);
 }