/** * Display task * * @return void */ public function displayTask() { // Must be logged in to be a curator if (User::isGuest()) { $this->_msg = Lang::txt('COM_PUBLICATIONS_CURATION_LOGIN'); $this->_login(); return; } // Get all user groups $usergroups = \Hubzero\User\Helper::getGroups(User::get('id')); // Check authorization $mt = new Tables\MasterType($this->database); $authorized = $this->_authorize($mt->getCuratorGroups()); // Incoming $assigned = Request::getInt('assigned', 0); // Build query $filters = array(); $filters['limit'] = Request::getInt('limit', 25); $filters['start'] = Request::getInt('limitstart', 0); $filters['sortby'] = Request::getVar('t_sortby', 'submitted'); $filters['sortdir'] = Request::getVar('t_sortdir', 'DESC'); $filters['ignore_access'] = 1; // Only get types for which authorized if ($authorized == 'limited') { $filters['master_type'] = $mt->getAuthTypes($usergroups, $authorized); } $filters['dev'] = 1; // get dev versions $filters['status'] = array(5, 7); // submitted/pending $filters['curator'] = $assigned || $authorized == false ? 'owner' : NULL; $this->view->filters = $filters; // Instantiate project publication $objP = new Tables\Publication($this->database); // Get all publications $this->view->rows = $objP->getRecords($filters); // Get total count $this->view->total = $objP->getCount($filters); // Initiate paging $this->view->pageNav = new \Hubzero\Pagination\Paginator($this->view->total, $this->view->filters['start'], $this->view->filters['limit']); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); //push the stylesheet to the view \Hubzero\Document\Assets::addPluginStylesheet('projects', 'publications'); if ($this->getError()) { foreach ($this->getErrors() as $error) { $this->view->setError($error); } } $this->view->option = $this->_option; $this->view->database = $this->database; $this->view->config = $this->config; $this->view->title = $this->_title; $this->view->authorized = $authorized; $this->view->display(); }
/** * 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; }