Ejemplo n.º 1
0
 function ApiMethod()
 {
     $tp = $this->task_parts;
     if (!isset($_GET['q'])) {
         return ["Search API Options (GET parameters)" => ['q' => "(String) Search term [Required]", "l" => "(Int) Limit results", "o" => "(Int) Offset results", "d" => "(Array[String]) Collections to search", "c" => "(String) Restrict search results to those matching one category"], "Define which collections are searchable in config.php"];
     }
     $q = $_GET['q'];
     $data = ["generated" => time(), "search_term" => $q];
     $options = ["sort" => ["date" => -1]];
     if (isset($_GET['l'])) {
         $limit = (int) $_GET['l'];
         $options['limit'] = $limit;
         $data['limit'] = $limit;
     }
     if (isset($_GET['o'])) {
         $offset = (int) $_GET['o'];
         $options['skip'] = $offset;
         $data['offset'] = $offset;
     }
     $regex = new MongoDB\BSON\Regex("^{$q}", 'i');
     //ob_end_clean();
     //var_dump($regex);
     $filter = ['$or' => [["title" => ['$regex' => $regex]], ["tags" => ['$regex' => $regex]], ["description" => ['$regex' => $regex]], ["content" => ['$regex' => $regex]]]];
     //var_dump($filter);
     //return $filter;
     if (isset($_GET['c'])) {
         $category = $_GET['c'];
         $c_imp = new category_implementation();
         $all_cats = $c_imp->ReadMany();
         //Translate title to ID
         foreach ($all_cats as $cat) {
             if (strtolower($category) == strtolower($cat->title)) {
                 $category = $cat->_id;
             }
         }
         $filter = ['$and' => [$filter, ['category' => $category]]];
         $data['category'] = $category;
     }
     //return $filter;
     $results = [];
     $num_results = 0;
     foreach ($this->searchable as $col_name) {
         $v_cname = View::loadViewByEndpoint($col_name);
         if (class_exists($v_cname)) {
             $i_imp = new $v_cname();
             $col_results = $i_imp->implementation->ReadMany($filter, $options);
             $num_results += count($col_results);
             $results[$col_name] = $col_results;
             try {
                 $col_controller = Controller::loadControllerByName($col_name);
                 $data['typenames'][$col_name] = $col_controller::$title;
             } catch (Exception $e) {
                 $data['typenames'][$col_name] = $col_name;
             }
         }
     }
     $data['number_of_results'] = $num_results;
     $data['results'] = $results;
     return $data;
 }
Ejemplo n.º 2
0
 static function kpCategories()
 {
     $imp = new category_implementation();
     $data = $imp->ReadMany();
     $kp = [];
     foreach ($data as $item) {
         $kp[$item->_id] = $item->title;
     }
     return $kp;
 }
Ejemplo n.º 3
0
 /**
  * Generate API response
  * 
  * @return type
  */
 public function APIMethod()
 {
     $tp = $this->task_parts;
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'GET':
             if ($tp[1]) {
                 $id = $tp[1];
                 return $this->Output($id);
             } else {
                 $filter = [];
                 $options = [];
                 //Add filter
                 if (isset($_GET['q'])) {
                     $filter = array_merge($filter, (array) json_decode($_GET['q']));
                 }
                 //Add limit (0 = no limit)
                 if (isset($_GET['l'])) {
                     $limit = (int) $_GET['l'];
                     if ($limit > 0) {
                         $options['limit'] = $limit;
                         $data['limit'] = $limit;
                     }
                 }
                 //Add offset
                 if (isset($_GET['o'])) {
                     $offset = (int) $_GET['o'];
                     $options['skip'] = $offset;
                     $data['offset'] = $offset;
                 }
                 //Apply category filter
                 if (isset($_GET['c'])) {
                     $category = $_GET['c'];
                     $c_imp = new category_implementation();
                     $all_cats = $c_imp->ReadMany();
                     //Translate title to ID
                     foreach ($all_cats as $cat) {
                         if (strtolower($category) == strtolower($cat->title)) {
                             $category = $cat->_id;
                         }
                     }
                     $filter = ['$and' => [(object) $filter, ['category' => $category]]];
                     $data['category'] = $category;
                 }
                 return $this->OutputMany($filter, $options);
             }
             break;
         default:
             return ["ResponseStatus" => "Error", "ErrorName" => "InvalidRequestMethod", "Note" => "This API endpoint only supports GET requests"];
     }
 }
Ejemplo n.º 4
0
 function PrepareModel()
 {
     $model = $this->implementation->model;
     $vid_imp = new video_implementation();
     //$streams = $vid_imp->ReadMany(['live' => 1]);
     $streams = $vid_imp->ReadMany();
     foreach ($streams as $video) {
         $model['properties']['videos']['items']['enum'][] = $video->{_id};
         $model['properties']['videos']['items']['options']['enum_titles'][] = $video->title;
     }
     $model = category_implementation::ModelAddCategories($model);
     return $model;
 }
Ejemplo n.º 5
0
 function PrepareModel()
 {
     $model = $this->implementation->model;
     $model = category_implementation::ModelAddCategories($model);
     return $model;
 }
Ejemplo n.º 6
0
 function PrepareModel()
 {
     $model = $this->implementation->model;
     $show_imp = new show_implementation();
     $shows = $show_imp->ReadMany();
     $model['properties']['date']['default'] = date('Y-m-d');
     $model['properties']['show_id']['enum'][] = "";
     $model['properties']['show_id']['options']['enum_titles'][] = "";
     foreach ($shows as $show) {
         $model['properties']['show_id']['enum'][] = $show->{_id};
         $model['properties']['show_id']['options']['enum_titles'][] = $show->title;
     }
     $player_types = mediaPlayer::getPlayerTypes();
     foreach ($player_types as $player_type) {
         $model['properties']['type']['enum'][] = $player_type->name;
         $model['properties']['type']['options']['enum_titles'][] = $player_type->title;
     }
     $model = category_implementation::ModelAddCategories($model);
     return $model;
 }