Example #1
0
 /**
  * Edit a type
  *
  * @return     void
  */
 public function editTask($row = null)
 {
     if ($row) {
         $this->view->row = $row;
     } else {
         // Incoming (expecting an array)
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = $id[0];
         } else {
             $id = 0;
         }
         // Load the object
         $this->view->row = new \Components\Publications\Tables\Category($this->database);
         $this->view->row->load($id);
     }
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     $this->view->config = $this->config;
     // Get all contributable master types
     $objMT = new \Components\Publications\Tables\MasterType($this->database);
     $this->view->types = $objMT->getTypes('alias', 1);
     // Push some styles to the template
     Document::addStyleSheet('components' . DS . $this->_option . DS . 'assets' . DS . 'css' . DS . 'publications.css');
     // Output the HTML
     $this->view->display();
 }
Example #2
0
 /**
  * Provision a new publication draft
  *
  * @return     object
  */
 public function createDraft()
 {
     // Incoming
     $base = Request::getVar('base', 'files');
     // Check permission
     if ($this->model->exists() && !$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Load publication & version classes
     $objP = new \Components\Publications\Tables\Publication($this->_database);
     $objC = new \Components\Publications\Tables\Category($this->_database);
     $mt = new \Components\Publications\Tables\MasterType($this->_database);
     // Determine publication master type
     $choices = $mt->getTypes('alias', 1);
     if (count($choices) == 1) {
         $base = $choices[0];
     }
     // Default to file type
     $mastertype = in_array($base, $choices) ? $base : 'files';
     // Need to provision a project
     if (!$this->model->exists()) {
         $alias = 'pub-' . strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1));
         $this->model->set('provisioned', 1);
         $this->model->set('alias', $alias);
         $this->model->set('title', $alias);
         $this->model->set('type', 2);
         // publication
         $this->model->set('state', 1);
         $this->model->set('setup_stage', 3);
         $this->model->set('created', Date::toSql());
         $this->model->set('created_by_user', $this->_uid);
         $this->model->set('owned_by_user', $this->_uid);
         $this->model->set('params', $this->model->type()->params);
         // Save changes
         if (!$this->model->store()) {
             throw new Exception($this->model->getError());
             return false;
         }
     }
     // Get type params
     $mType = $mt->getType($mastertype);
     // Make sure we got type info
     if (!$mType) {
         throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_LOAD_TYPE'));
         return false;
     }
     // Get curation model for the type
     $curationModel = new \Components\Publications\Models\Curation($mType->curation);
     // Get default category from manifest
     $cat = isset($curationModel->_manifest->params->default_category) ? $curationModel->_manifest->params->default_category : 1;
     if (!$objC->load($cat)) {
         $cat = 1;
     }
     // Get default title from manifest
     $title = isset($curationModel->_manifest->params->default_title) ? $curationModel->_manifest->params->default_title : Lang::txt('Untitled Draft');
     // Make a new publication entry
     $objP->master_type = $mType->id;
     $objP->category = $cat;
     $objP->project_id = $this->model->get('id');
     $objP->created_by = $this->_uid;
     $objP->created = Date::toSql();
     $objP->access = 0;
     if (!$objP->store()) {
         throw new Exception($objP->getError());
         return false;
     }
     if (!$objP->id) {
         $objP->checkin();
     }
     $this->_pid = $objP->id;
     // Initizalize Git repo and transfer files from member dir
     if ($this->model->isProvisioned()) {
         if (!$this->_prepDir()) {
             // Roll back
             $this->model->delete();
             $objP->delete();
             throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_FAILED_INI_GIT_REPO'));
             return false;
         } else {
             // Add creator as project owner
             $objO = $this->model->table('Owner');
             if (!$objO->saveOwners($this->model->get('id'), $this->_uid, $this->_uid, 0, 1, 1, 1)) {
                 throw new Exception(Lang::txt('COM_PROJECTS_ERROR_SAVING_AUTHORS') . ': ' . $objO->getError());
                 return false;
             }
         }
     }
     // Make a new dev version entry
     $row = new \Components\Publications\Tables\Version($this->_database);
     $row->publication_id = $this->_pid;
     $row->title = $row->getDefaultTitle($this->model->get('id'), $title);
     $row->state = 3;
     // dev
     $row->main = 1;
     $row->created_by = $this->_uid;
     $row->created = Date::toSql();
     $row->version_number = 1;
     $row->license_type = 0;
     $row->access = 0;
     $row->secret = strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1));
     if (!$row->store()) {
         // Roll back
         $objP->delete();
         throw new Exception($row->getError(), 500);
         return false;
     }
     if (!$row->id) {
         $row->checkin();
     }
     // Models\Publication
     $pub = new \Components\Publications\Models\Publication($this->_pid, 'dev');
     // Record action, notify team
     $this->onAfterCreate($pub);
     // Return publication object
     return $pub;
 }
Example #3
0
 /**
  * Remove one or more types
  *
  * @return     void Redirects back to main listing
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming (expecting an array)
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Ensure we have an ID to work with
     if (empty($ids)) {
         // Redirect with error message
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_NO_ITEM_SELECTED'), 'error');
         return;
     }
     $rt = new \Components\Publications\Tables\MasterType($this->database);
     foreach ($ids as $id) {
         // Check if the type is being used
         $total = $rt->checkUsage($id);
         if ($total > 0) {
             // Redirect with error message
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_TYPE_BEING_USED', $id), 'error');
             return;
         }
         // Delete the type
         $rt->delete($id);
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_ITEMS_REMOVED', count($ids)));
 }
Example #4
0
 /**
  * Edit a type
  *
  * @param   object  $row
  * @return  void
  */
 public function editTask($row = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!is_object($row)) {
         // Incoming (expecting an array)
         $id = Request::getVar('id', array(0));
         $id = is_array($id) ? $id[0] : $id;
         // Load the object
         $row = new \Components\Publications\Tables\Category($this->database);
         $row->load($id);
     }
     $this->view->row = $row;
     // Set any errors
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     $this->view->config = $this->config;
     // Get all contributable master types
     $objMT = new \Components\Publications\Tables\MasterType($this->database);
     $this->view->types = $objMT->getTypes('alias', 1);
     // Output the HTML
     $this->view->setLayout('edit')->display();
 }