/** * 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; } $selections = Request::getVar('selecteditems', ''); $toAttach = explode(',', $selections); $added = 0; // Load classes $pAuthor = new \Components\Publications\Tables\Author($this->_parent->_db); $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); $order = $pAuthor->getLastOrder($pub->version_id) + 1; foreach ($toAttach as $owner) { if (!trim($owner)) { continue; } if ($pAuthor->loadAssociationByOwner($owner, $pub->version_id)) { // Restore deleted author if ($pAuthor->status == 2 || $pAuthor->status == 0) { $pAuthor->status = 1; $pAuthor->modified = Date::toSql(); $pAuthor->modified_by = $actor; if ($pAuthor->updateAssociationByOwner()) { // Reflect the update in curation record $this->_parent->set('_update', 1); } } } else { $profile = $pAuthor->getProfileInfoByOwner($owner); $invited = $profile->invited_name ? $profile->invited_name : $profile->invited_email; $pAuthor->project_owner_id = $owner; $pAuthor->publication_version_id = $pub->version_id; $pAuthor->user_id = $profile->uidNumber ? $profile->uidNumber : 0; $pAuthor->ordering = $order; $pAuthor->status = 1; $pAuthor->organization = $profile->organization ? $profile->organization : ''; $pAuthor->name = $profile && $profile->name ? $profile->name : $invited; $pAuthor->firstName = $profile->givenName ? $profile->givenName : ''; $pAuthor->lastName = $profile->surname ? $profile->surname : ''; $pAuthor->created = Date::toSql(); $pAuthor->created_by = $actor; if (!$pAuthor->createAssociation()) { continue; } else { // Update ordering $order++; // Reflect the update in curation record $this->_parent->set('_update', 1); $added++; } } } if ($added) { $this->set('_message', Lang::txt('Author selection saved')); } // Save group owner if (!$selections) { $this->saveGroupOwner($pub); } return true; }