Пример #1
0
 /**
  * Display a level of the tag browser
  * NOTE: This view should only be called through AJAX
  *
  * @return     void
  */
 public function browserTask()
 {
     // Incoming
     $level = Request::getInt('level', 0);
     // A container for info to pass to the HTML for the view
     $bits = array();
     $bits['supportedtag'] = $this->config->get('supportedtag');
     // Process the level
     switch ($level) {
         case 1:
             // Incoming
             $bits['type'] = Request::getInt('type', 7);
             $bits['id'] = Request::getInt('id', 0);
             $bits['tg'] = Request::getVar('input', '');
             $bits['tg2'] = Request::getVar('input2', '');
             $rt = new Tags($bits['id']);
             // Get tags that have been assigned
             $bits['tags'] = $rt->get_tags_with_objects($bits['id'], $bits['type'], $bits['tg2']);
             break;
         case 2:
             // Incoming
             $bits['type'] = Request::getInt('type', 7);
             $bits['id'] = Request::getInt('id', 0);
             $bits['tag'] = Request::getVar('input', '');
             $bits['tag2'] = Request::getVar('input2', '');
             $bits['sortby'] = Request::getVar('sortby', 'title');
             $bits['filter'] = Request::getVar('filter', array('level0', 'level1', 'level2', 'level3', 'level4'));
             if ($bits['tag'] == $bits['tag2']) {
                 $bits['tag2'] = '';
             }
             // Get parameters
             $bits['params'] = $this->config;
             // Get extra filter options
             $bits['filters'] = array();
             if ($this->config->get('show_audience') && $bits['type'] == 7) {
                 include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'audience.php';
                 include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'audiencelevel.php';
                 $rL = new AudienceLevel($this->database);
                 $bits['filters'] = $rL->getLevels();
             }
             $rt = new Tags($bits['id']);
             $bits['rt'] = $rt;
             // Get resources assigned to this tag
             $bits['tools'] = $rt->get_objects_on_tag($bits['tag'], $bits['id'], $bits['type'], $bits['sortby'], $bits['tag2'], $bits['filter']);
             // Set the typetitle
             $bits['typetitle'] = Lang::txt('COM_RESOURCES');
             // See if we can load the type so we can set the typetitle
             if (isset($bits['type']) && $bits['type'] != 0) {
                 $t = new Type($this->database);
                 $t->load($bits['type']);
                 $bits['typetitle'] = stripslashes($t->type);
             }
             $bits['supportedtagusage'] = $rt->getTagUsage($bits['supportedtag'], 'id');
             break;
         case 3:
             // Incoming (should be a resource ID)
             $id = Request::getInt('input', 0);
             include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'resource.php';
             $model = Models\Resource::getInstance($id);
             $rt = new Tags($id);
             $bits['rt'] = $rt;
             $bits['config'] = $this->config;
             $bits['params'] = $model->params;
             // Get resource
             $model->resource->ranking = round($model->resource->ranking, 1);
             // Generate the SEF
             if ($model->resource->alias) {
                 $sef = Route::url('index.php?option=' . $this->_option . '&alias=' . $model->resource->alias);
             } else {
                 $sef = Route::url('index.php?option=' . $this->_option . '&id=' . $model->resource->id);
             }
             // Get resource helper
             $helper = new Helper($model->resource->id, $this->database);
             //$helper->getFirstChild();
             //$helper->getContributorIDs();
             $bits['authorized'] = $model->access('edit');
             //$this->_authorize($helper->contributorIDs, $resource);
             $firstChild = $model->children(0);
             // Get the first child
             if ($firstChild || $model->isTool()) {
                 $bits['primary_child'] = Html::primary_child($this->_option, $model->resource, $firstChild, '');
             }
             // Get the sections
             $bits['sections'] = Event::trigger('resources.onResources', array($model, $this->_option, array('about'), 'metadata'));
             // Fill our container
             $bits['resource'] = $model->resource;
             $bits['helper'] = $helper;
             $bits['sef'] = $sef;
             break;
     }
     // Instantiate a new view
     $this->view->config = $this->config;
     $this->view->level = $level;
     $this->view->bits = $bits;
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setName('browse')->setLayout('tags_list')->display();
 }