Esempio n. 1
0
 /**
  * Lists publications
  *
  * @return     void
  */
 public function displayTask()
 {
     // Incoming
     $this->view->filters = array();
     $this->view->filters['limit'] = Request::getState($this->_option . '.publications.limit', 'limit', Config::get('list_limit'), 'int');
     $this->view->filters['start'] = Request::getState($this->_option . '.publications.limitstart', 'limitstart', 0, 'int');
     $this->view->filters['search'] = urldecode(trim(Request::getState($this->_option . '.publications.search', 'search', '')));
     $this->view->filters['sortby'] = trim(Request::getState($this->_option . '.publications.sortby', 'filter_order', 'created'));
     $this->view->filters['sortdir'] = trim(Request::getState($this->_option . '.publications.sortdir', 'filter_order_Dir', 'DESC'));
     $this->view->filters['status'] = trim(Request::getState($this->_option . '.publications.status', 'status', 'all'));
     $this->view->filters['dev'] = 1;
     $this->view->filters['category'] = trim(Request::getState($this->_option . '.publications.category', 'category', ''));
     // Instantiate a publication object
     $this->view->model = new Models\Publication($this->database);
     // Get record count
     $this->view->total = $this->view->model->entries('count', $this->view->filters, true);
     // Get publications
     $this->view->rows = $this->view->model->entries('list', $this->view->filters, true);
     $this->view->config = $this->config;
     // Get <select> of types
     // Get types
     $rt = new Tables\Category($this->database);
     $this->view->categories = $rt->getContribCategories();
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     // Output the HTML
     $this->view->display();
 }
Esempio n. 2
0
 /**
  * Parse loaded data for further processing
  *
  * @access public
  * @return string
  */
 public function parse($dryRun = 1, $output = NULL)
 {
     // Set common props
     $this->_uid = User::get('id');
     // No errors. Let's rewind and parse
     $this->reader = new \XMLReader();
     $this->reader->XML($this->data);
     // Load classes
     $objCat = new Tables\Category($this->database);
     $objL = new Tables\License($this->database);
     // Get base type
     $base = Request::getVar('base', 'files');
     // Determine publication master type
     $mt = new Tables\MasterType($this->database);
     $choices = $mt->getTypes('alias', 1);
     $mastertype = in_array($base, $choices) ? $base : 'files';
     // Get type params
     $mType = $mt->getType($mastertype);
     // Get curation model for the type
     $curationModel = new \Components\Publications\Models\Curation($mType->curation);
     // Get defaults from manifest
     $title = $curationModel && isset($curationModel->_manifest->params->default_title) ? $curationModel->_manifest->params->default_title : 'Untitled Draft';
     $title = $title ? $title : 'Untitled Draft';
     $cat = isset($curationModel->_manifest->params->default_category) ? $curationModel->_manifest->params->default_category : 1;
     $this->curationModel = $curationModel;
     // Get element IDs
     $elementPrimeId = 1;
     $elementGalleryId = 2;
     $elementSupportId = 3;
     if ($this->curationModel) {
         $elements1 = $this->curationModel->getElements(1);
         $elements2 = $this->curationModel->getElements(2);
         $elements3 = $this->curationModel->getElements(3);
         $elementPrimeId = !empty($elements1) ? $elements1[0]->id : $elementPrimeId;
         $elementGalleryId = !empty($elements3) ? $elements3[0]->id : $elementGalleryId;
         $elementSupportId = !empty($elements2) ? $elements2[0]->id : $elementSupportId;
     }
     // Get project repo path
     $this->projectPath = $this->project->repo()->get('path');
     // Parse data
     $items = array();
     while ($this->reader->read()) {
         if ($this->reader->name === 'publication') {
             $node = new \SimpleXMLElement($this->reader->readOuterXML());
             // Check that category exists
             $category = isset($node->cat) ? $node->cat : 'dataset';
             $catId = $objCat->getCatId($category);
             $item['category'] = $category;
             $item['type'] = $mastertype;
             $item['errors'] = array();
             $item['tags'] = array();
             $item['authors'] = array();
             // Publication properties
             $item['publication'] = new Tables\Publication($this->database);
             $item['publication']->master_type = $mType->id;
             $item['publication']->category = $catId ? $catId : $cat;
             $item['publication']->project_id = $this->project->get('id');
             $item['publication']->created_by = $this->_uid;
             $item['publication']->created = Date::toSql();
             $item['publication']->access = 0;
             // Version properties
             $item['version'] = new Tables\Version($this->database);
             $item['version']->title = isset($node->title) && trim($node->title) ? trim($node->title) : $title;
             $item['version']->abstract = isset($node->synopsis) ? trim($node->synopsis) : '';
             $item['version']->description = isset($node->abstract) ? trim($node->abstract) : '';
             $item['version']->version_label = isset($node->version) ? trim($node->version) : '1.0';
             $item['version']->release_notes = isset($node->notes) ? trim($node->notes) : '';
             // Check license
             $license = isset($node->license) ? $node->license : '';
             $item['license'] = $objL->getLicenseByTitle($license);
             if (!$item['license']) {
                 $item['errors'][] = Lang::txt('COM_PUBLICATIONS_BATCH_ITEM_ERROR_LICENSE');
             } else {
                 $item['version']->license_type = $item['license']->id;
             }
             // Pick up files
             $item['files'] = array();
             if ($node->content) {
                 $i = 1;
                 foreach ($node->content->file as $file) {
                     $this->collectFileData($file, 1, $i, $item, $elementPrimeId);
                     $i++;
                 }
             }
             // Supporting docs
             if ($node->supportingmaterials) {
                 $i = 1;
                 foreach ($node->supportingmaterials->file as $file) {
                     $this->collectFileData($file, 2, $i, $item, $elementSupportId);
                     $i++;
                 }
             }
             // Gallery
             if ($node->gallery) {
                 $i = 1;
                 foreach ($node->gallery->file as $file) {
                     $this->collectFileData($file, 3, $i, $item, $elementGalleryId);
                     $i++;
                 }
             }
             // Tags
             if ($node->tags) {
                 foreach ($node->tags->tag as $tag) {
                     if (trim($tag)) {
                         $item['tags'][] = $tag;
                     }
                 }
             }
             // Authors
             if ($node->authors) {
                 $i = 1;
                 foreach ($node->authors->author as $author) {
                     $attributes = $author->attributes();
                     $uid = $attributes['uid'];
                     $this->collectAuthorData($author, $i, $uid, $item);
                     $i++;
                 }
             }
             // Set general process error
             if (count($item['errors']) > 0) {
                 $this->setError(Lang::txt('COM_PUBLICATIONS_BATCH_ERROR_MISSING_OR_INVALID'));
             }
             $items[] = $item;
             $this->reader->next();
         }
     }
     // Show what you'll get
     if ($dryRun == 1) {
         $eview = new \Hubzero\Component\View(array('name' => 'batchcreate', 'layout' => 'dryrun'));
         $eview->option = $this->_option;
         $eview->items = $items;
         $output .= $eview->loadTemplate();
     } elseif ($dryRun == 2) {
         // Get hub config
         $this->site = trim(Request::base(), DS);
         // Process batch
         $out = NULL;
         $i = 0;
         foreach ($items as $item) {
             if ($this->processRecord($item, $out)) {
                 $i++;
             }
         }
         if ($i > 0) {
             $output = '<p class="success">' . Lang::txt('COM_PUBLICATIONS_BATCH_SUCCESS_CREATED') . ' ' . $i . ' ' . Lang::txt('COM_PUBLICATIONS_BATCH_RECORDS_S') . '</p>';
         }
         if ($i != count($items)) {
             $output = '<p class="error">' . Lang::txt('COM_PUBLICATIONS_BATCH_FAILED_CREATED') . ' ' . (count($items) - $i) . ' ' . Lang::txt('COM_PUBLICATIONS_BATCH_RECORDS_S') . '</p>';
         }
         $output .= $out;
     }
     $this->reader->close();
     return $output;
 }
Esempio n. 3
0
 /**
  * Browse publications
  *
  * @return  void
  */
 public function browseTask()
 {
     // Set the default sort
     $default_sort = 'date';
     if ($this->config->get('show_ranking')) {
         $default_sort = 'ranking';
     }
     // Incoming
     $this->view->filters = array('category' => Request::getVar('category', ''), 'sortby' => Request::getCmd('sortby', $default_sort), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'tag' => trim(Request::getVar('tag', '', 'request', 'none', 2)), 'tag_ignored' => array());
     if (!in_array($this->view->filters['sortby'], array('date', 'title', 'id', 'rating', 'ranking', 'popularity'))) {
         $this->view->filters['sortby'] = $default_sort;
     }
     // Get projects user has access to
     if (!User::isGuest()) {
         $obj = new \Components\Projects\Tables\Project($this->database);
         $this->view->filters['projects'] = $obj->getUserProjectIds(User::get('id'));
     }
     // Get major types
     $t = new Tables\Category($this->database);
     $this->view->categories = $t->getCategories();
     if (is_numeric($this->view->filters['category'])) {
         $this->view->filters['category'] = (int) $this->view->filters['category'];
     }
     if (!is_int($this->view->filters['category'])) {
         foreach ($this->view->categories as $cat) {
             if (trim($this->view->filters['category']) == $cat->url_alias) {
                 $this->view->filters['category'] = (int) $cat->id;
                 break;
             }
         }
         if (!is_int($this->view->filters['category'])) {
             $this->view->filters['category'] = null;
         }
     }
     // Instantiate a publication object
     $model = new Models\Publication();
     // Execute count query
     $this->view->total = $model->entries('count', $this->view->filters);
     // Run query with limit
     $this->view->results = $model->entries('list', $this->view->filters);
     // Initiate paging
     $this->view->pageNav = new \Hubzero\Pagination\Paginator($this->view->total, $this->view->filters['start'], $this->view->filters['limit']);
     // Get type if not given
     $this->_title = Lang::txt(strtoupper($this->_option)) . ': ';
     if ($this->view->filters['category'] != '') {
         $t->load($this->view->filters['category']);
         $this->_title .= $t->name;
         $this->_task_title = $t->name;
     } else {
         $this->_title .= Lang::txt('COM_PUBLICATIONS_ALL');
         $this->_task_title = Lang::txt('COM_PUBLICATIONS_ALL');
     }
     // Set page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     $this->view->title = $this->_title;
     $this->view->config = $this->config;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setName('browse')->setLayout('default')->display();
 }