16 import(
'lib.pkp.classes.form.Form');
34 public function __construct($pressId, $spotlightId =
null) {
35 parent::__construct(
'controllers/grid/content/spotlights/form/spotlightForm.tpl');
37 $this->_spotlightId = $spotlightId;
38 $this->_pressId = $pressId;
41 $this->
addCheck(
new FormValidatorCustom($this,
'assocId',
'required',
'grid.content.spotlights.itemRequired',
function($assocId) use ($form) {
42 list($id, $type) = preg_split(
'/:/', $assocId);
43 return is_numeric($id) && $id > 0 && $form->_isValidSpotlightType($type);
45 $this->
addCheck(
new FormValidator($this,
'title',
'required',
'grid.content.spotlights.titleRequired'));
57 public function fetch($request, $template =
null, $display =
false) {
62 $templateMgr->assign(array(
63 'spotlight' => $spotlight,
67 if (isset($spotlight)) $templateMgr->assign(array(
68 'title' => $spotlight->getTitle(
null),
69 'description' => $spotlight->getDescription(
null),
70 'assocTitle' => $this->getAssocTitle($spotlight->getAssocId(), $spotlight->getAssocType()),
71 'assocId' => $spotlight->getAssocId() .
':' . $spotlight->getAssocType(),
74 return parent::fetch($request, $template, $display);
84 $this->
readUserVars(array(
'title',
'description',
'assocId'));
90 public function execute(...$functionArgs) {
97 $spotlight = $spotlightDao->newDataObject();
99 $existingSpotlight =
false;
101 $existingSpotlight =
true;
104 list($assocId, $assocType) = preg_split(
'/:/', $this->
getData(
'assocId'));
105 $spotlight->setAssocType($assocType);
106 $spotlight->setTitle($this->
getData(
'title'),
null);
107 $spotlight->setDescription($this->
getData(
'description'),
null);
108 $spotlight->setAssocId($assocId);
110 if ($existingSpotlight) {
111 $spotlightDao->updateObject($spotlight);
112 $spotlightId = $spotlight->getId();
114 $spotlightId = $spotlightDao->insertObject($spotlight);
117 parent::execute(...$functionArgs);
150 switch ($assocType) {
151 case SPOTLIGHT_TYPE_BOOK:
153 $returner = isset($submission) ? $submission->getLocalizedTitle() :
'';
155 case SPOTLIGHT_TYPE_SERIES:
157 $series = $seriesDao->getById($assocId, $this->
getPressId());
158 $returner = isset($series) ? $series->getLocalizedTitle() :
'';
172 $validTypes = array(SPOTLIGHT_TYPE_BOOK, SPOTLIGHT_TYPE_SERIES);
173 return in_array((
int) $type, $validTypes);