00001 <?php
00002
00016 import('lib.pkp.classes.form.Form');
00017
00018 class ChapterForm extends Form {
00020 var $_monographId;
00021
00023 var $_chapter;
00024
00028 function ChapterForm($monograph, &$chapter) {
00029 parent::Form('controllers/grid/users/chapter/form/chapterForm.tpl');
00030 $this->setMonograph($monograph);
00031
00032 if ($chapter) {
00033 $this->setChapter($chapter);
00034 }
00035
00036
00037 $this->addCheck(new FormValidator($this, 'title', 'required', 'metadata.property.validationMessage.title'));
00038 $this->addCheck(new FormValidatorPost($this));
00039 }
00040
00041
00042
00043
00044
00049 function getMonograph() {
00050 return $this->_monograph;
00051 }
00052
00057 function setMonograph($monograph) {
00058 $this->_monograph =& $monograph;
00059 }
00060
00065 function getChapter() {
00066 return $this->_chapter;
00067 }
00068
00073 function setChapter($chapter) {
00074 $this->_chapter =& $chapter;
00075 }
00076
00077
00078
00079
00084 function initData() {
00085 AppLocale::requireComponents(LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS, LOCALE_COMPONENT_PKP_SUBMISSION);
00086
00087 $monograph =& $this->getMonograph();
00088 $this->setData('monographId', $monograph->getId());
00089
00090 $chapter =& $this->getChapter();
00091 if ($chapter) {
00092 $this->setData('chapterId', $chapter->getId());
00093 $this->setData('title', $chapter->getTitle());
00094 $this->setData('subtitle', $chapter->getSubtitle());
00095 } else {
00096 $this->setData('title', null);
00097 $this->setData('subtitle', null);
00098 }
00099 }
00100
00105 function readInputData() {
00106 $this->readUserVars(array('title', 'subtitle', 'authors'));
00107 }
00108
00113 function execute() {
00114 $chapterDao =& DAORegistry::getDAO('ChapterDAO');
00115 $chapter =& $this->getChapter();
00116
00117 if ($chapter) {
00118 $chapter->setTitle($this->getData('title'), null);
00119 $chapter->setSubtitle($this->getData('subtitle'), null);
00120 $chapterDao->updateObject($chapter);
00121 } else {
00122 $monograph =& $this->getMonograph();
00123
00124 $chapter = $chapterDao->newDataObject();
00125 $chapter->setMonographId($monograph->getId());
00126 $chapter->setTitle($this->getData('title'), null);
00127 $chapter->setSubtitle($this->getData('subtitle'), null);
00128 $chapterDao->insertChapter($chapter);
00129 }
00130
00131 $this->setChapter($chapter);
00132
00133
00134 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
00135 ListbuilderHandler::unpack($request, $this->getData('authors'));
00136
00137 return true;
00138 }
00139
00146 function insertEntry(&$request, $newRowId) {
00147 $monograph =& $this->getMonograph();
00148 $chapter =& $this->getChapter();
00149 $authorId = (int) $newRowId['name'];
00150 $sequence = (int) $newRowId['sequence'];
00151
00152
00153 $chapterAuthorDao =& DAORegistry::getDAO('ChapterAuthorDAO');
00154
00155 $chapterAuthorDao->insertChapterAuthor($authorId, $chapter->getId(), $monograph->getId(), false, $sequence);
00156 return true;
00157 }
00158
00165 function updateEntry(&$request, $rowId, $newRowId) {
00166 if (!$this->deleteEntry($request, $rowId)) return false;
00167 return $this->insertEntry($request, $newRowId);
00168 }
00169
00176 function deleteEntry(&$request, $rowId) {
00177 $chapter = $this->getChapter();
00178 $authorId = (int) $rowId;
00179 if ($authorId) {
00180
00181 $chapterAuthorDao =& DAORegistry::getDAO('ChapterAuthorDAO');
00182 $chapterAuthorDao->deleteChapterAuthorById($authorId, $chapter->getId());
00183 return true;
00184 }
00185 return false;
00186 }
00187 }
00188
00189 ?>