Example #1
0
 /**
  * Process file data
  *
  * @access public
  * @return void
  */
 public function processFileData($fileRecord, $pub, $version)
 {
     $attachment = $fileRecord['attachment'];
     $vid = $pub->version_id;
     $pid = $pub->id;
     // Get latest Git hash
     $vcs_hash = $this->_git->gitLog($attachment->path, '', 'hash');
     // Create attachment record
     if ($this->curationModel || $fileRecord['type'] != 'gallery') {
         $attachment->publication_id = $pid;
         $attachment->publication_version_id = $vid;
         $attachment->vcs_hash = $vcs_hash;
         $attachment->created_by = $this->_uid;
         $attachment->created = Date::toSql();
         $attachment->store();
     }
     // Copy files to the right location
     if ($this->curationModel) {
         // Get attachment type model
         $attModel = new Models\Attachments($this->database);
         $fileAttach = $attModel->loadAttach('file');
         // Get element manifest
         $elements = $this->curationModel->getElements($attachment->role);
         if (!$elements) {
             return false;
         }
         $element = $elements[0];
         // Set configs
         $configs = $fileAttach->getConfigs($element->manifest->params, $element->id, $pub, $element->block);
         // Check if names is already used
         $suffix = $fileAttach->checkForDuplicate($configs->path . DS . $attachment->path, $attachment, $configs);
         // Save params if applicable
         if ($suffix) {
             $pa = new \Components\Publications\Tables\Attachment($this->database);
             $pa->saveParam($attachment, 'suffix', $suffix);
         }
         // Copy file into the right spot
         $fileAttach->publishAttachment($attachment, $pub, $configs);
     }
 }
Example #2
0
 /**
  * List project notes available for publishing
  *
  * @return     array
  */
 public function browser()
 {
     // Incoming
     $ajax = Request::getInt('ajax', 0);
     $primary = Request::getInt('primary', 1);
     $versionid = Request::getInt('versionid', 0);
     if (!$ajax) {
         return false;
     }
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'notes', 'name' => 'browser'));
     // Get current attachments
     $pContent = new \Components\Publications\Tables\Attachment($this->_database);
     $role = $primary ? '1' : '0';
     $other = $primary ? '0' : '1';
     $view->attachments = $pContent->getAttachments($versionid, $filters = array('role' => $role, 'type' => 'note'));
     // Output HTML
     $view->params = $this->model->params;
     $view->option = $this->_option;
     $view->database = $this->_database;
     $view->model = $this->model;
     $view->uid = $this->_uid;
     $view->config = $this->_config;
     $view->title = $this->_area['title'];
     $view->primary = $primary;
     $view->versionid = $versionid;
     // Get messages	and errors
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     $html = $view->loadTemplate();
     $arr = array('html' => $html, 'metadata' => '');
     return $arr;
 }
Example #3
0
 /**
  * Unpublish version/delete draft
  *
  * @return     string
  */
 public function cancelDraft()
 {
     // Incoming
     $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0);
     $confirm = Request::getInt('confirm', 0);
     $version = Request::getVar('version', 'default');
     $ajax = Request::getInt('ajax', 0);
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Load publication model
     $pub = new \Components\Publications\Models\Publication($pid, $version);
     if (!$pub->exists() || !$pub->belongsToProject($this->model->get('id'))) {
         throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'), 404);
         return;
     }
     // Save version ID
     $vid = $pub->version->get('id');
     // Append breadcrumbs
     if (!$ajax) {
         Pathway::append(stripslashes($pub->version->get('title')), $pub->link('edit'));
     }
     $baseUrl = Route::url($pub->link('editbase'));
     $baseEdit = Route::url($pub->link('edit'));
     // Can only unpublish published version or delete a draft
     if ($pub->version->get('state') != 1 && $pub->version->get('state') != 3 && $pub->version->get('state') != 4) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CANT_DELETE'));
     }
     // Unpublish/delete version
     if ($confirm) {
         if (!$this->getError()) {
             $pubtitle = \Hubzero\Utility\String::truncate($pub->version->get('title'), 100);
             if ($pub->version->get('state') == 1) {
                 // Unpublish published version
                 $pub->version->set('published_down', Date::toSql());
                 $pub->version->set('modified', Date::toSql());
                 $pub->version->set('modified_by', $this->_uid);
                 $pub->version->set('state', 0);
                 if (!$pub->version->store()) {
                     throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNPUBLISH_FAILED'), 403);
                     return;
                 } else {
                     $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_UNPUBLISHED');
                     // Add activity
                     $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_UNPUBLISHED');
                     $action .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version->get('version_label') . ' ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" ';
                     $aid = $this->model->recordActivity($action, $pid, $pubtitle, Route::url($pub->link('editversion')), 'publication', 0);
                 }
             } elseif ($pub->version->get('state') == 3 || $pub->version->get('state') == 4) {
                 $vlabel = $pub->version->get('version_label');
                 // Delete draft version
                 if (!$pub->version->delete()) {
                     throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DELETE_DRAFT_FAILED'), 403);
                     return;
                 }
                 // Delete authors
                 $pa = new \Components\Publications\Tables\Author($this->_database);
                 $authors = $pa->deleteAssociations($vid);
                 // Delete attachments
                 $pContent = new \Components\Publications\Tables\Attachment($this->_database);
                 $pContent->deleteAttachments($vid);
                 // Delete screenshots
                 $pScreenshot = new \Components\Publications\Tables\Screenshot($this->_database);
                 $pScreenshot->deleteScreenshots($vid);
                 // Build publication path
                 $path = PATH_APP . DS . trim($this->_pubconfig->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($pid);
                 // Build version path
                 $vPath = $path . DS . \Hubzero\Utility\String::pad($vid);
                 // Delete all version files
                 if (is_dir($vPath)) {
                     Filesystem::deleteDirectory($vPath);
                 }
                 // Delete access accosiations
                 $pAccess = new \Components\Publications\Tables\Access($this->_database);
                 $pAccess->deleteGroups($vid);
                 // Delete audience
                 $pAudience = new \Components\Publications\Tables\Audience($this->_database);
                 $pAudience->deleteAudience($vid);
                 // Delete publication existence
                 if ($pub->versionCount() == 0) {
                     // Delete all files
                     if (is_dir($path)) {
                         Filesystem::delete($path);
                     }
                     $pub->publication->delete($pid);
                     $pub->publication->deleteExistence($pid);
                     // Delete related publishing activity from feed
                     $objAA = $this->model->table('Activity');
                     $objAA->deleteActivityByReference($this->model->get('id'), $pid, 'publication');
                 }
                 // Add activity
                 $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_DRAFT_DELETED');
                 $action .= ' ' . $vlabel . ' ';
                 $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . $pubtitle . '"';
                 $aid = $this->model->recordActivity($action, $pid, '', '', 'publication', 0);
                 $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DRAFT_DELETED');
             }
         }
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'cancel'));
         // Output HTML
         $view->option = $this->_option;
         $view->database = $this->_database;
         $view->project = $this->model;
         $view->uid = $this->_uid;
         $view->pid = $pid;
         $view->pub = $pub;
         $view->publishedCount = $pub->version->getPublishedCount($pid);
         $view->task = $this->_task;
         $view->config = $this->model->config();
         $view->pubconfig = $this->_pubconfig;
         $view->ajax = $ajax;
         $view->title = $this->_area['title'];
         // Get messages	and errors
         $view->msg = $this->_msg;
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         return $view->loadTemplate();
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     App::redirect($baseUrl);
     return;
 }
Example #4
0
 /**
  * Add/edit attachment
  *
  *
  * @return     boolean or error
  */
 public function addAttachment($database_name, $pub, $configs, $uid, $elementId, $element, $ordering = 1)
 {
     // Get database object and load record
     $objData = new \Components\Projects\Tables\Database($this->_parent->_db);
     $objData->loadRecord($database_name);
     $dbVersion = NULL;
     $objPA = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     if ($objPA->loadElementAttachment($pub->version_id, array('object_name' => $database_name), $elementId, $this->_name, $element->role)) {
         // Already attached
         $new = 0;
         if (!$objData->id) {
             // Original got deleted, can't do much
             return true;
         }
     } else {
         if (!$objData->id) {
             // Original database not found
             $this->setError(Lang::txt('Oups! Cannot attach selected database: database not found'));
             return false;
         }
         $objPA->publication_id = $pub->id;
         $objPA->publication_version_id = $pub->version_id;
         $objPA->type = $this->_name;
         $objPA->created_by = $uid;
         $objPA->created = Date::toSql();
         $objPA->role = $element->role;
         $new = 1;
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     }
     if ($new) {
         $result = Event::trigger('projects.clone_database', array($database_name, $pub->_project, $configs->servePath));
         $dbVersion = $result && isset($result[0]) ? $result[0] : NULL;
     } else {
         $rtime = $objPA->modified ? strtotime($objPA->modified) : NULL;
         if ($objPA->object_id != $objData->id || strtotime($objData->updated) > $rtime) {
             // New database instance - need to clone again and get a new version number
             $result = Event::trigger('projects.clone_database', array($database_name, $pub->_project, $configs->servePath));
             $dbVersion = $result && isset($result[0]) ? $result[0] : NULL;
             $objPA->modified_by = $uid;
             $objPA->modified = Date::toSql();
         } else {
             // No changes
             $dbVersion = $objPA->object_revision;
         }
     }
     // Failed to clone
     if (!$dbVersion) {
         $this->_parent->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_FAILED_DB_CLONE'));
         return false;
     }
     $objPA->object_id = $objData->id;
     $objPA->object_name = $database_name;
     $objPA->object_revision = $dbVersion;
     $objPA->element_id = $elementId;
     $objPA->ordering = $ordering;
     $objPA->title = $objPA->title ? $objPA->title : $objData->title;
     // Build link path
     $objPA->path = 'dataviewer' . DS . 'view' . DS . 'publication:dsl' . DS . $database_name . DS . '?v=' . $dbVersion;
     if (!$objPA->store()) {
         $this->_parent->setError(Lang::txt('There was a problem attaching the database'));
         return false;
     }
     // Determine accompanying files and copy them in the right location
     $this->publishDataFiles($objData, $configs);
     return true;
 }
Example #5
0
 /**
  * Transfer files from one version to another
  *
  * @return  boolean
  */
 public function transferData($elementparams, $elementId, $pub, $blockParams, $attachments, $oldVersion, $newVersion)
 {
     // Loop through attachments
     foreach ($attachments as $att) {
         // Make new attachment record
         $pAttach = new \Components\Publications\Tables\Attachment($this->_parent->_db);
         if (!$pAttach->copyAttachment($att, $newVersion->id, $elementId, User::get('id'))) {
             continue;
         }
     }
     return true;
 }
Example #6
0
 /**
  * Add/edit file attachment
  *
  *
  * @return     boolean or error
  */
 public function addAttachment($filePath, $pub, $configs, $uid, $elementId, $element, $ordering = 1)
 {
     // Need to check against allowed types
     if ($configs->check) {
         if (!$this->checkAllowed(array($filePath), $element->typeParams->allowed_ext)) {
             return false;
         }
     }
     // Get latest Git hash
     $vcs_hash = $this->_git->gitLog($filePath, '', 'hash');
     $new = 0;
     $update = 0;
     $objPA = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     if ($objPA->loadElementAttachment($pub->version_id, array('path' => $filePath), $elementId, $this->_name, $element->role)) {
         // Update if new hash
         if ($vcs_hash && $vcs_hash != $objPA->vcs_hash) {
             $objPA->vcs_hash = $vcs_hash;
             $objPA->modified_by = $uid;
             $objPA->modified = Date::toSql();
             $update = 1;
             // Copy file again (new version)
             // Reflect the update in curation record
             $this->_parent->set('_update', 1);
         }
     } else {
         $new = 1;
         $objPA->publication_id = $pub->id;
         $objPA->publication_version_id = $pub->version_id;
         $objPA->path = $filePath;
         $objPA->type = $this->_name;
         $objPA->vcs_hash = $vcs_hash;
         $objPA->created_by = $uid;
         $objPA->created = Date::toSql();
         $objPA->role = $element->role;
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     }
     $objPA->element_id = $elementId;
     $objPA->ordering = $ordering;
     // Copy file from project repo into publication directory
     if ($objPA->store()) {
         // Check for conflict in file name
         if ($new == 1) {
             $suffix = $this->checkForDuplicate($configs->path . DS . $filePath, $objPA, $configs);
             if ($suffix) {
                 $pa = new \Components\Publications\Tables\Attachment($this->_parent->_db);
                 $pa->saveParam($objPA, 'suffix', $suffix);
             }
         }
         // Copy file over to where to belongs
         if (!$this->publishAttachment($objPA, $pub, $configs, $update)) {
             return false;
         }
         // Make default image (if applicable)
         if ($configs->handler && $configs->handler->getName() == 'imageviewer') {
             $currentDefault = new \Components\Publications\Tables\Attachment($this->_parent->_db);
             if (!$currentDefault->getDefault($pub->version_id)) {
                 $configs->handler->makeDefault($objPA, $pub, $configs);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * Sets the fields in this class with database data.
  *
  * @return boolean  True if succss and False otherwise
  */
 private function populateRDFData()
 {
     // Grabs database object
     $database = \App::get('db');
     $resource = new \Components\Publications\Tables\Version($database);
     $resource = $resource->getLastPubRelease($this->id);
     if (!$resource) {
         // Return if ID does not exist
         throw new Exception(Lang::txt('COM_PUBLICATIONS_FILE_NOT_FOUND'), 404);
         return false;
     }
     $this->setPaths();
     // Gets the author name
     $this->author_id = $resource->created_by;
     $this->created_by = User::getInstance($this->author_id)->name;
     // Set created date
     $this->date_created = $this->formatDate($resource->created);
     // Set description
     $this->intro = $resource->description;
     // Set title
     $this->title = $resource->title;
     // Set last modified date
     $this->date_modified = $this->formatDate($resource->modified);
     // Set published date
     $this->date_published = $this->formatDate($resource->published_up);
     // Set version ID
     $this->version_id = $resource->id;
     // Load the $types variable. In the form of array([type_id] => [type_name]).
     $resource = new \Components\Publications\Tables\Publication($database);
     $pub = $resource->getPublication($this->id);
     $type_id = $pub->category;
     $typesData = new \Components\Publications\Tables\Category($database);
     $allTypes = $typesData->getCategories(array('state' => 'all'));
     $this->types = array();
     foreach ($allTypes as $type) {
         $types[$type->id] = $type->name;
     }
     // Get the type name of this resource
     $this->type = $types[$type_id];
     // Get attachments
     $pubAttach = new \Components\Publications\Tables\Attachment($database);
     $attachments = $pubAttach->getAttachments($this->version_id);
     foreach ($attachments as $child) {
         $this->aggregates[$child->id]['parent_id'] = $this->id;
         $this->aggregates[$child->id]['title'] = basename($child->path);
         $this->aggregates[$child->id]['created'] = $this->formatDate($child->created);
         $this->aggregates[$child->id]['standalone'] = 0;
         $this->aggregates[$child->id]['path'] = $child->path;
         $this->aggregates[$child->id]['url'] = $this->componentURL . $this->id . '/serve?a=' . $child->id;
     }
     return true;
 }
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param      object  	$publication 	Current publication
  * @param      string  	$option    		Name of the component
  * @param      array   	$areas     		Active area(s)
  * @param      string  	$rtrn      		Data to be returned
  * @param      string 	$version 		Version name
  * @param      boolean 	$extended 		Whether or not to show panel
  * @return     array
  */
 public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true, $authorized = true)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) {
             // do nothing
             return $arr;
         }
     }
     if (!$publication->_category->_params->get('plg_supportingdocs')) {
         return $arr;
     }
     // Are we returning HTML?
     if ($rtrn == 'all' || $rtrn == 'html') {
         $database = App::get('db');
         $config = Component::params($option);
         // Instantiate a view
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'supportingdocs', 'name' => 'browse'));
         // Get docs
         $pContent = new \Components\Publications\Tables\Attachment($database);
         $view->docs = $pContent->getAttachments($publication->version_id, $filters = array('role' => array(1, 0, 2), 'order' => 'a.role DESC, a.ordering ASC'));
         // Get projects html helper
         require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php';
         // Build publication path
         $base_path = $config->get('webpath');
         $view->path = \Components\Publications\Helpers\Html::buildPubPath($publication->id, $publication->version_id, $base_path, $publication->secret, $root = 1);
         // Pass the view some info
         $view->option = $option;
         $view->publication = $publication;
         $view->config = $config;
         $view->version = $version;
         $view->live_site = Request::base();
         $view->authorized = $authorized;
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     return $arr;
 }
 /**
  * Draw file selector
  *
  * @return  object
  */
 public function drawSelector($elementId, $manifest, $pub = NULL, $status = NULL, $active = 0, $collapse = 0, $total = 0, $master = NULL, $order = 0)
 {
     // Get attachment type model
     $attModel = new \Components\Publications\Models\Attachments($this->_parent->_db);
     // Make sure we have attachments
     if (!isset($pub->_attachments)) {
         // Get attachments
         $pContent = new \Components\Publications\Tables\Attachment($this->_parent->_db);
         $pub->_attachments = $pContent->sortAttachments($pub->version_id);
     }
     // Get attached items
     $attachments = $pub->_attachments;
     $attachments = isset($attachments['elements'][$elementId]) ? $attachments['elements'][$elementId] : NULL;
     $attachments = $attModel->getElementAttachments($elementId, $attachments, $manifest->params->type, $manifest->params->role);
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'blockelement', 'layout' => 'dataselector'));
     $view->type = $manifest->params->type;
     $view->path = $this->path;
     $view->pub = $pub;
     $view->manifest = $manifest;
     $view->status = $status;
     $view->elementId = $elementId;
     $view->attachments = $attachments;
     $view->active = $active;
     $view->collapse = $collapse;
     $view->total = $total;
     $view->master = $master;
     $view->database = $this->_parent->_db;
     $view->order = $order;
     $view->viewer = 'edit';
     $view->git = $this->_git;
     return $view->loadTemplate();
 }
Example #10
0
 /**
  * Load content editor for handler
  *
  * @return  void
  */
 public function loadEditor($handler, $pub, $elementId = 0)
 {
     // Get handler configs
     $configs = $handler->get('_configs');
     if (!$configs) {
         $configs = $handler->getConfig();
     }
     // Start editor
     $editor = new \Components\Publications\Models\Editor($handler, $configs);
     // Make sure we have attachments
     if (!isset($pub->_attachments)) {
         // Get attachments
         $pContent = new \Components\Publications\Tables\Attachment($this->_parent->_db);
         $pub->_attachments = $pContent->sortAttachments($pub->version_id);
     }
     // Sort out attachments for this element
     $attachments = $pub->_attachments;
     $attachments = isset($attachments['elements'][$elementId]) ? $attachments['elements'][$elementId] : NULL;
     // Set editor properties
     $editor->set('pub', $pub);
     $editor->set('attachments', $attachments);
     $editor->set('elementId', $elementId);
     // Check if assigned and get association record
     $objAssoc = new \Components\Publications\Tables\HandlerAssoc($this->_db);
     $association = $objAssoc->getAssociation($pub->version_id, $elementId, $handler->get('_name'));
     $editor->set('assoc', $association);
     // Check status
     $editor->set('configured', $association && $association->params ? true : false);
     $editor->set('assigned', $association ? true : false);
     $editor->set('relevant', self::isRelevant($handler, $attachments));
     // Check for changes
     // TBD
     return $editor;
 }
Example #11
0
 /**
  * Add/edit file attachment
  *
  * @param   integer  $id
  * @param   string   $title
  * @param   object   $pub
  * @param   object   $configs
  * @param   integer  $uid
  * @param   integer  $elementId
  * @param   object   $element
  * @param   integer  $ordering
  * @return  boolean
  */
 public function addAttachment($id, $title, $pub, $configs, $uid, $elementId, $element, $ordering = 1)
 {
     // Need to check against allowed types
     $accept = isset($element->typeParams->accept) ? $element->typeParams->accept : NULL;
     if ($configs->check) {
         if (!$this->checkAllowed($id, $accept)) {
             return false;
         }
     }
     $path = rtrim(Request::base(), '/') . '/' . ltrim(Route::url('index.php?option=com_publications&id=' . $id), '/');
     $objPA = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     if ($objPA->loadElementAttachment($pub->version_id, array('path' => $path), $elementId, $this->_name, $element->role)) {
         // Link already attached
         $this->setError(Lang::txt('The publication is already attached'));
         return true;
     } else {
         $objPA->publication_id = $pub->id;
         $objPA->publication_version_id = $pub->version_id;
         $objPA->path = $path;
         $objPA->type = $this->_name;
         $objPA->created_by = $uid;
         $objPA->created = Date::toSql();
         $objPA->role = $element->role;
         $objPA->title = $title;
         $objPA->object_id = $id;
         $objPA->object_name = $this->_name;
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     }
     $objPA->element_id = $elementId;
     $objPA->ordering = $ordering;
     if (!$objPA->store()) {
         $this->setError(Lang::txt('There was a problem attaching the publication'));
         return false;
     }
     return true;
 }
Example #12
0
 /**
  * Delete attachment record
  *
  * @return  void
  */
 public function deleteItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0)
 {
     $aid = $aid ? $aid : Request::getInt('aid', 0);
     // Load attachment
     $row = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     // We need attachment record
     if (!$aid || !$row->load($aid)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_EDIT_CONTENT'));
         return false;
     }
     // Attachment type
     $type = $row->type;
     // Get attachment type model
     $attModel = new \Components\Publications\Models\Attachments($this->_parent->_db);
     // Save incoming attachment info
     $attModel->remove($type, $row, $pub, $actor, $elementId, $manifest->elements->{$elementId}, $manifest->params);
     // Set success message
     if ($attModel->get('_message')) {
         $this->set('_message', $attModel->get('_message'));
     }
     // Set request to update curation record
     if ($attModel->get('_update')) {
         $this->_parent->set('_update', 1);
     }
     return true;
 }
Example #13
0
 /**
  * Make image default for publication
  *
  * @return  void
  */
 public function makeDefault($row, $pub, $configs)
 {
     // Make sure we got config
     if (!$this->_config) {
         $this->getConfig();
     }
     // TBD - to come from component configs
     $defaultMasterName = 'master.png';
     $defaultThumbName = 'thumb.gif';
     $path = $this->getFilePath($row->path, $row->id, $configs, $row->params);
     // No file found
     if (!is_file($path)) {
         return false;
     }
     // Check if image
     if (!getimagesize($path)) {
         return false;
     }
     $copyToThumb = $configs->pubBase . DS . $defaultThumbName;
     $copyToMaster = $configs->pubBase . DS . $defaultMasterName;
     $thumbName = \Components\Publications\Helpers\Html::createThumbName(basename($path), $this->_config->params->thumbSuffix, $this->_config->params->thumbFormat);
     $thumbPath = dirname($path) . DS . $thumbName;
     // Copy to master
     if (is_file($path)) {
         Filesystem::copy($path, $copyToMaster);
         // Create/update thumb
         Filesystem::copy($path, $copyToThumb);
         $hi = new \Hubzero\Image\Processor($copyToThumb);
         if (count($hi->getErrors()) == 0) {
             $hi->resize(100, false, true, true);
             $hi->save($copyToThumb);
         }
     } else {
         return false;
     }
     // Get current default
     $currentDefault = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     $currentDefault->getDefault($row->publication_version_id);
     // Unmark as default
     if ($currentDefault->id) {
         $currentDefault->saveParam($currentDefault, 'pubThumb', '');
     }
     // Mark this image as default
     $currentDefault->saveParam($row, 'pubThumb', '1');
     return true;
 }