Example #1
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 #2
0
 /**
  * Save block content
  *
  * @return  string  HTML
  */
 public function save($manifest = NULL, $blockId = 0, $pub = NULL, $actor = 0, $elementId = 0)
 {
     // Set block manifest
     if ($this->_manifest === NULL) {
         $this->_manifest = $manifest ? $manifest : self::getManifest();
     }
     // Make sure changes are allowed
     if ($this->_parent->checkFreeze($this->_manifest->params, $pub)) {
         return false;
     }
     // Load publication version
     $objP = new \Components\Publications\Tables\Publication($this->_parent->_db);
     if (!$objP->load($pub->id)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND'));
         return false;
     }
     $tagsHelper = new \Components\Publications\Helpers\Tags($this->_parent->_db);
     $tags = trim(Request::getVar('tags', '', 'post'));
     $tagsHelper->tag_object($actor, $pub->id, $tags, 1);
     // Reflect the update in curation record
     $this->_parent->set('_update', 1);
     // Save category
     $cat = Request::getInt('pubtype', 0);
     if ($cat && $pub->_category->id != $cat) {
         $objP->category = $cat;
         $objP->store();
     }
     return true;
 }