/** * Save a type * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); //get format $format = Request::getVar('citationFormat', array()); // create or update custom format $model = CitationFormat::oneOrNew($format['id']); if ($model->style == 'Hub Custom' || $model->isNew() === true) { $model->set(array('style' => 'Hub Custom', 'format' => \Hubzero\Utility\Sanitize::clean($format['format']))); } else { $model->set(array('format' => \Hubzero\Utility\Sanitize::clean($format['format']))); } if (!$model->save()) { // redirect with error message App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_FORMAT_NOT_SAVED'), 'error'); } // successfully set the default value, redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_FORMAT_SAVED') . ' ' . $model->style); }
/** * Up **/ public function up() { // get all formats on the hub $formats = Components\Citations\Models\Format::all(); $ieee = false; // flag for IEEE format $apa = false; // flag for APA format foreach ($formats as $format) { // check for IEEE format if (strtolower($format->style) == 'ieee') { $ieee = true; } // check for APA style if (strtolower($format->style) == 'apa') { $apa = true; } } // end foreach if (!$apa) { //insert apa $apaFormat = Components\Citations\Models\Format::oneOrNew(null); $apaFormat->set(array('style' => 'APA', 'format' => '{AUTHORS}, {EDITORS} ({YEAR}), {TITLE/CHAPTER}, <i>{JOURNAL}</i>, <i>{BOOK TITLE}</i>, {EDITION}, {CHAPTER}, {SERIES}, {PUBLISHER}, {ADDRESS}, <b>{VOLUME}</b>, <b>{ISSUE/NUMBER}</b>: {PAGES}, {ORGANIZATION}, {INSTITUTION}, {SCHOOL}, {LOCATION}, {MONTH}, {ISBN/ISSN}, (DOI: {DOI}). Cited by: <a href=\'{SECONDARY LINK}\'>{SECONDARY COUNT}</a>')); $apaFormat->save(); } if (!$ieee) { //insert ieee $ieeeFormat = Components\Citations\Models\Format::oneOrNew(null); $ieeeFormat->set(array('style' => 'IEEE', 'format' => '{AUTHORS}, {EDITORS} ({YEAR}), {TITLE/CHAPTER}, <i>{JOURNAL}</i>, <i>{BOOK TITLE}</i>, {EDITION}, {CHAPTER}, {SERIES}, {PUBLISHER}, {ADDRESS}, <b>{VOLUME}</b>, <b>{ISSUE/NUMBER}</b>: {PAGES}, {ORGANIZATION}, {INSTITUTION}, {SCHOOL}, {LOCATION}, {MONTH}, {ISBN/ISSN}, (DOI: {DOI})')); $ieeeFormat->save(); } }
/** * Settings for group citations * * @param null * @return void * * */ private function settingsAction() { if ($_POST) { $display = Request::getVar('display', ''); $format = Request::getVar('citation-format', ''); // craft a clever name $name = "custom-member-" . $this->member->get('uidNumber'); // fetch or create new format $citationFormat = \Components\Citations\Models\Format::oneOrNew($format); // if the setting a custom member citation type if ($citationFormat->isNew() || $citationFormat->style == $name && !$citationFormat->isNew()) { $citationFormat->set(array('format' => Request::getVar('template'), 'style' => $name)); // save format $citationFormat->save(); // update group $citationFormatID = $citationFormat->id; } else { // returned value from format select box $citationFormatID = $format; } $include_coins = \Hubzero\Utility\Sanitize::clean(Request::getVar('include_coins', '')); $coins_only = \Hubzero\Utility\Sanitize::clean(Request::getVar('coins_only', '')); $citation_show_tags = \Hubzero\Utility\Sanitize::clean(Request::getVar('citations_show_tags', '')); $citation_show_badges = \Hubzero\Utility\Sanitize::clean(Request::getVar('citations_show_badges', '')); // set member citation parameters $this->member->setParam('citationFormat', $citationFormatID); $this->member->setParam('include_coins', $include_coins); $this->member->setParam('coins_only', $coins_only); $this->member->setParam('citations_show_tags', $citation_show_tags); $this->member->setParam('citations_show_badges', $citation_show_badges); // save profile settings if (!$this->member->update()) { // failed App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_SETTINGS_NOT_SAVED'), 'error'); } // redirect after save App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_SETTINGS_SAVED'), 'success'); return; } else { // instansiate the view $view = $this->view('settings'); // pass the group through $view->member = $this->member; // get group settings $params = json_decode($this->member->get('params')); $view->include_coins = isset($params->include_coins) ? $params->include_coins : "false"; $view->coins_only = isset($params->coins_only) ? $params->coins_only : "false"; $view->citations_show_tags = isset($params->citations_show_tags) ? $params->citations_show_tags : "true"; $view->citations_show_badges = isset($params->citations_show_badges) ? $params->citations_show_badges : "true"; $citationsFormat = isset($params->citationFormat) ? $params->citationFormat : 1; // intended for the case that the group's custom // format is removed from the jos_citations_format try { $view->currentFormat = \Components\Citations\Models\Format::oneOrFail($citationsFormat); } catch (\Exception $e) { $view->currentFormat = \Components\Citations\Models\Format::all()->where('style', 'like', 'ieee'); } // get the name of the current format (see if it's custom) // the name of the custom format $name = "custom-member-" . $this->member->get('uidNumber'); $custom = \Components\Citations\Models\Format::all()->where('style', 'LIKE', $name)->count(); if ($custom > 0) { // show the menu entry for the custom $view->customFormat = true; } else { // show menu item for new custom format $view->customFormat = false; } // get formats $view->formats = \Components\Citations\Models\Format::all()->where('style', 'NOT LIKE', '%custom-member-%')->where('style', 'NOT LIKE', '%custom-group-%')->orWhere('style', '=', $name)->rows()->toObject(); $view->templateKeys = \Components\Citations\Models\Format::all()->getTemplateKeys(); // Output HTML foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); } }
/** * Settings for group citations * * @param null * @return void * * */ private function _settings() { if ($_POST) { $display = Request::getVar('display', ''); $format = Request::getVar('citation-format', ''); $params = json_decode($this->group->get('params')); if (!is_object($params)) { $params = new stdClass(); } // craft a clever name $name = "custom-group-" . $this->group->cn; // fetch or create new format $citationFormat = \Components\Citations\Models\Format::oneOrNew($format); // if the setting a custom group citation type if ($citationFormat->isNew() || $citationFormat->style == $name && !$citationFormat->isNew()) { $citationFormat->set(array('format' => Request::getVar('template'), 'style' => $name)); // save format $citationFormat->save(); // update group $params->citationFormat = $citationFormat->id; } else { // returned value from format select box $params->citationFormat = $format; } // more parameters for citations $params->display = Request::getVar('display', ''); $params->include_coins = Request::getVar('include_coins', ''); $params->coins_only = Request::getVar('coins_only', ''); $params->citations_show_tags = Request::getVar('citations_show_tags', ''); $params->citations_show_badges = Request::getVar('citations_show_badges', ''); // update the group parameters $gParams = new Registry($params); $gParams->merge($params); $this->group->set('params', $gParams->toString()); $this->group->update(); // redirect after save App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_SETTINGS_SAVED'), 'success'); return; } else { // instansiate the view $view = $this->view('default', 'settings'); // pass the group through $view->group = $this->group; // get group settings $params = json_decode($this->group->get('params')); $view->include_coins = isset($params->include_coins) ? $params->include_coins : "false"; $view->coins_only = isset($params->coins_only) ? $params->coins_only : "false"; $view->citations_show_tags = isset($params->citations_show_tags) ? $params->citations_show_tags : "true"; $view->citations_show_badges = isset($params->citations_show_badges) ? $params->citations_show_badges : "true"; $citationsFormat = isset($params->citationFormat) ? $params->citationFormat : 1; // intended for the case that the group's custom // format is removed from the jos_citations_format try { $view->currentFormat = \Components\Citations\Models\Format::oneOrFail($citationsFormat); } catch (\Exception $e) { $view->currentFormat = \Components\Citations\Models\Format::all()->where('style', 'like', 'ieee'); } // get the name of the current format (see if it's custom) // the name of the custom format $name = "custom-group-" . $this->group->cn; $custom = \Components\Citations\Models\Format::all()->where('style', 'LIKE', $name)->count(); if ($custom > 0) { // show the menu entry for the custom $view->customFormat = true; } else { // show menu item for new custom format $view->customFormat = false; } // get formats $view->formats = \Components\Citations\Models\Format::all()->where('style', 'NOT LIKE', '%custom-group-%')->where('style', 'NOT LIKE', '%custom-member-%')->orWhere('style', '=', $name)->rows()->toObject(); $view->templateKeys = \Components\Citations\Models\Format::all()->getTemplateKeys(); // Output HTML foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); } }