Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ChapterForm.inc.php
1 <?php
2 
17 import('lib.pkp.classes.form.Form');
18 
19 class ChapterForm extends Form {
22 
24  var $_chapter;
25 
29  function ChapterForm($monograph, &$chapter) {
30  parent::Form('controllers/grid/users/chapter/form/chapterForm.tpl');
31  $this->setMonograph($monograph);
32 
33  if ($chapter) {
34  $this->setChapter($chapter);
35  }
36 
37  // Validation checks for this form
38  $this->addCheck(new FormValidator($this, 'title', 'required', 'metadata.property.validationMessage.title'));
39  $this->addCheck(new FormValidatorPost($this));
40  }
41 
42 
43  //
44  // Getters/Setters
45  //
50  function getMonograph() {
51  return $this->_monograph;
52  }
53 
58  function setMonograph($monograph) {
59  $this->_monograph = $monograph;
60  }
61 
66  function getChapter() {
67  return $this->_chapter;
68  }
69 
74  function setChapter($chapter) {
75  $this->_chapter = $chapter;
76  }
77 
78  //
79  // Overridden template methods
80  //
85  function initData() {
86  AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_PKP_SUBMISSION);
87 
88  $monograph = $this->getMonograph();
89  $this->setData('submissionId', $monograph->getId());
90 
91  $chapter = $this->getChapter();
92  if ($chapter) {
93  $this->setData('chapterId', $chapter->getId());
94  $this->setData('title', $chapter->getTitle());
95  $this->setData('subtitle', $chapter->getSubtitle());
96  } else {
97  $this->setData('title', null);
98  $this->setData('subtitle', null);
99  }
100  }
101 
106  function readInputData() {
107  $this->readUserVars(array('title', 'subtitle', 'authors'));
108  }
109 
114  function execute() {
115  $chapterDao = DAORegistry::getDAO('ChapterDAO');
116  $chapter = $this->getChapter();
117 
118  if ($chapter) {
119  $chapter->setTitle($this->getData('title'), null); //Localized
120  $chapter->setSubtitle($this->getData('subtitle'), null); //Localized
121  $chapterDao->updateObject($chapter);
122  } else {
123  $monograph = $this->getMonograph();
124 
125  $chapter = $chapterDao->newDataObject();
126  $chapter->setMonographId($monograph->getId());
127  $chapter->setTitle($this->getData('title'), null); //Localized
128  $chapter->setSubtitle($this->getData('subtitle'), null); //Localized
129  $chapterDao->insertChapter($chapter);
130  }
131 
132  $this->setChapter($chapter);
133 
134  // Save the author associations. (See insert/deleteEntry.)
135  import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
136  ListbuilderHandler::unpack($request, $this->getData('authors'));
137 
138  return true;
139  }
140 
147  function insertEntry($request, $newRowId) {
148  $monograph = $this->getMonograph();
149  $chapter = $this->getChapter();
150  $authorId = (int) $newRowId['name'];
151  $sequence = (int) $newRowId['sequence'];
152 
153  // Create a new chapter author.
154  $chapterAuthorDao = DAORegistry::getDAO('ChapterAuthorDAO');
155  // FIXME: primary authors not set for chapter authors.
156  $chapterAuthorDao->insertChapterAuthor($authorId, $chapter->getId(), $monograph->getId(), false, $sequence);
157  return true;
158  }
159 
166  function updateEntry($request, $rowId, $newRowId) {
167  if (!$this->deleteEntry($request, $rowId)) return false;
168  return $this->insertEntry($request, $newRowId);
169  }
170 
177  function deleteEntry($request, $rowId) {
178  $chapter = $this->getChapter();
179  $authorId = (int) $rowId; // this is the authorId to remove and is already an integer
180  if ($authorId) {
181  // remove the chapter author.
182  $chapterAuthorDao = DAORegistry::getDAO('ChapterAuthorDAO');
183  $chapterAuthorDao->deleteChapterAuthorById($authorId, $chapter->getId());
184  return true;
185  }
186  return false;
187  }
188 }
189 
190 ?>
Form for adding/editing a chapter stores/retrieves from an associative array.
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
deleteEntry($request, $rowId)
insertEntry($request, $newRowId)
Form validation check to make sure the form is POSTed.
static requireComponents()
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
setChapter($chapter)
updateEntry($request, $rowId, $newRowId)
getData($key)
Definition: Form.inc.php:210
setMonograph($monograph)
Class to represent a form validation check.
unpack($request, $data, $deletionCallback=null, $insertionCallback=null, $updateCallback=null)
ChapterForm($monograph, &$chapter)