示例#1
0
 /**
  * Get a list of resource types
  *   Accepts either a numeric array index or a string [id, name]
  *   If index, it'll return the entry matching that index in the list
  *   If string, it'll return either a list of IDs or names
  *
  * @param      mixed $idx Index value
  * @return     array
  */
 public function types($idx = null)
 {
     if (!$this->exists()) {
         return array();
     }
     if (!isset($this->types)) {
         $this->types = array();
         $rt = new Tables\Type($this->_db);
         if ($types = $rt->getMajorTypes()) {
             foreach ($types as $key => $type) {
                 if (!$type->alias) {
                     $types[$key]->alias = $rt->normalize($type->type);
                 }
             }
             $this->types = $types;
         }
     }
     if ($idx !== null) {
         if (is_numeric($idx)) {
             foreach ($this->types as $type) {
                 if ($type->id == $idx) {
                     return $type;
                 }
             }
         } else {
             if (is_string($idx)) {
                 $idx = trim($idx);
                 foreach ($this->types as $type) {
                     if ($type->alias == $idx) {
                         return $type;
                     }
                 }
             }
         }
         $this->setError(Lang::txt('Index not found: ') . __CLASS__ . '::' . __METHOD__ . '[' . $idx . ']');
         return false;
     }
     return $this->types;
 }
示例#2
0
 /**
  * Lists standalone resources
  *
  * @return  void
  */
 public function displayTask()
 {
     // Incoming
     $this->view->filters = array('limit' => Request::getState($this->_option . '.resources.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.resources.limitstart', 'limitstart', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.resources.search', 'search', '')), 'sort' => Request::getState($this->_option . '.resources.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.resources.sortdir', 'filter_order_Dir', 'DESC'), 'status' => Request::getState($this->_option . '.resources.status', 'status', 'all'), 'type' => Request::getState($this->_option . '.resources.type', 'type', ''));
     $model = new Resource($this->database);
     // Get record count
     $this->view->total = $model->getItemCount($this->view->filters);
     // Get resources
     $this->view->rows = $model->getItems($this->view->filters);
     // Get <select> of types
     $rt = new Type($this->database);
     $this->view->types = $rt->getMajorTypes();
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
示例#3
0
 /**
  * Display a list of contributable resource types and let the user pick
  *
  * @return     void
  */
 public function step_type()
 {
     $this->view->group = Request::getVar('group', '');
     $this->view->step = $this->step;
     $this->view->step++;
     // Get available resource types
     $rt = new Type($this->database);
     $this->view->types = $rt->getMajorTypes();
     // Output HTML
     if ($this->getError()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
     }
     $this->view->display();
 }
示例#4
0
 /**
  * Browse resources by tags
  *
  * @return     void
  */
 public function browsetagsTask()
 {
     // Check if we're using this view type
     if ($this->config->get('browsetags') == 'off') {
         return $this->browseTask();
     }
     // Incoming
     $this->view->tag = preg_replace("/[^a-zA-Z0-9]/", '', strtolower(Request::getVar('tag', '')));
     $this->view->tag2 = preg_replace("/[^a-zA-Z0-9]/", '', strtolower(Request::getVar('with', '')));
     $this->view->type = strtolower(Request::getVar('type', 'tools'));
     // default tag in tag browser is config var
     $this->view->supportedtag = $this->config->get('supportedtag');
     $this->view->supportedtag_default = $this->config->get('browsetags_defaulttag', '');
     if (!$this->view->tag && $this->view->supportedtag_default != '' && $this->view->type == 'tools') {
         $this->view->tag = $this->view->supportedtag_default;
     }
     // Get major types
     $t = new Type($this->database);
     $this->view->types = $t->getMajorTypes();
     // Normalize the title
     // This is so we can determine the type of resource to display from the URL
     // For example, /resources/learningmodules => Learning Modules
     $activetype = 0;
     $activetitle = '';
     for ($i = 0; $i < count($this->view->types); $i++) {
         if (trim($this->view->type) == $this->view->types[$i]->alias) {
             $activetype = $this->view->types[$i]->id;
             $activetitle = $this->view->types[$i]->type;
         }
     }
     asort($this->view->types);
     // Ensure we have a type to display
     if (!$activetype) {
         $this->_redirect = Route::url('index.php?option=' . $this->_option);
         return;
     }
     // Instantiate a resource object
     $rr = new Resource($this->database);
     // Determine if user can edit
     $this->view->authorized = $this->_authorize();
     // Set the default sort
     $default_sort = 'rating';
     if ($this->config->get('show_ranking')) {
         $default_sort = 'ranking';
     }
     // Set some filters
     $this->view->filters = array('tag' => $this->view->tag2 ? $this->view->tag2 : '', 'type' => $activetype, 'sortby' => $default_sort, 'limit' => 10, 'start' => 0);
     // Run query with limit
     $this->view->results = $rr->getRecords($this->view->filters);
     $this->type = $this->view->type;
     if ($activetitle) {
         $this->_task_title = $activetitle;
     } else {
         $this->_task_title = Lang::txt('COM_RESOURCES_ALL');
     }
     // Set page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     $this->view->title = $this->_title;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->config = $this->config;
     $this->view->setName('browse')->setLayout('tags')->display();
 }
示例#5
0
 /**
  * Get a list of resources
  *
  * @apiMethod GET
  * @apiUri    /resources/list
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "start",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "type",
  * 		"description":   "Type of resource to filter results.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "sortby",
  * 		"description":   "Value to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "date",
  * 		"allowedValues": "date, title, random"
  * }
  * @apiParameter {
  * 		"name":          "search",
  * 		"description":   "A word or phrase to search for.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @return    void
  */
 public function listTask()
 {
     // Incoming
     $filters = array('type' => Request::getVar('type', ''), 'sortby' => Request::getCmd('sortby', 'date'), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''));
     if (!in_array($filters['sortby'], array('date', 'date_published', 'date_created', 'date_modified', 'title', 'rating', 'ranking', 'random'))) {
         App::abort(404, Lang::txt('Invalid sort value of "%s" used.', $filters['sortby']));
     }
     require_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php';
     require_once Component::path('com_resources') . DS . 'tables' . DS . 'type.php';
     $database = App::get('db');
     // Instantiate a resource object
     $rr = new Resource($database);
     // encode results and return response
     $response = new stdClass();
     $response->records = array();
     $response->total = $rr->getCount($filters);
     if ($response->total) {
         // Get major types
         $t = new Type($database);
         $types = array();
         foreach ($t->getMajorTypes() as $type) {
             unset($type->params);
             unset($type->customFields);
             $types[$type->id] = $type;
         }
         $response->records = $rr->getRecords($filters);
         $base = rtrim(Request::base(), '/');
         foreach ($response->records as $i => $entry) {
             $entry->url = str_replace('/api', '', $base . '/' . ltrim(Route::url('index.php?option=com_resources&' . ($entry->alias ? 'alias=' . $entry->alias : 'id=' . $entry->id)), '/'));
             if (isset($types[$entry->type])) {
                 $entry->type = $types[$entry->type];
             }
             $response->records[$i] = $entry;
         }
     }
     $response->success = true;
     $this->send($response);
 }