• Main Page
  • Modules
  • Classes
  • Files
  • File List

controllers/grid/content/navigation/form/FooterCategoryForm.inc.php

00001 <?php
00015 import('lib.pkp.classes.form.Form');
00016 
00017 class FooterCategoryForm extends Form {
00021    var $_footerCategory;
00022 
00026    var $_pressId;
00027 
00033    function FooterCategoryForm($pressId, $footerCategory = null) {
00034       parent::Form('controllers/grid/content/navigation/form/footerCategoryForm.tpl');
00035 
00036       $this->setFooterCategory($footerCategory);
00037       $this->_pressId = $pressId;
00038 
00039       $this->addCheck(new FormValidator($this, 'title', 'required', 'grid.content.navigation.footer.titleRequired'));
00040       $this->addCheck(new FormValidator($this, 'description', 'required', 'grid.content.navigation.footer.descriptionRequired'));
00041       $this->addCheck(new FormValidator($this, 'path', 'required', 'grid.content.navigation.footer.pathRequired'));
00042       if (!$footerCategory) {
00043          $this->addCheck(new FormValidatorCustom(
00044             $this, 'path', 'required', 'grid.content.navigation.footer.pathRequired',
00045             create_function(
00046                '$path,$form,$footerCategoryDao,$pressId',
00047                'return !$footerCategoryDao->categoryExistsByPath($path,$pressId);'
00048             ),
00049             array(&$this, DAORegistry::getDAO('FooterCategoryDAO'), $pressId)
00050          ));
00051       } else {
00052          $this->addCheck(new FormValidatorCustom(
00053             $this, 'path', 'required', 'grid.content.navigation.footer.pathInUse',
00054             create_function(
00055                '$path,$form,$footerCategoryDao,$pressId',
00056                '$category =& $footerCategoryDao->getByPath($path,$pressId); return (!isset($category) || $category->getId() == $form->getData(\'footerCategoryId\'));'
00057             ),
00058             array(&$this, DAORegistry::getDAO('FooterCategoryDAO'), $pressId)
00059          ));
00060       }
00061       $this->addCheck(new FormValidatorPost($this));
00062    }
00063 
00064 
00065    //
00066    // Extended methods from Form
00067    //
00071    function fetch($request) {
00072       $templateMgr =& TemplateManager::getManager();
00073 
00074       $footerCategory =& $this->getFooterCategory();
00075       $templateMgr->assign_by_ref('footerCategory', $footerCategory);
00076       $templateMgr->assign('pressId', $this->getPressId());
00077 
00078       if (isset($footerCategory)) {
00079          $templateMgr->assign('title', $footerCategory->getTitle(null));
00080          $templateMgr->assign('path', $footerCategory->getPath());
00081          $templateMgr->assign('description', $footerCategory->getDescription(null));
00082       }
00083 
00084       return parent::fetch($request);
00085    }
00086 
00087    //
00088    // Extended methods from Form
00089    //
00093    function readInputData() {
00094       $this->readUserVars(array('title', 'description', 'path', 'footerLinks', 'footerCategoryId'));
00095    }
00096 
00100    function execute(&$request) {
00101 
00102       $footerCategoryDao =& DAORegistry::getDAO('FooterCategoryDAO');
00103       $footerCategory =& $this->getFooterCategory();
00104 
00105       if (!$footerCategory) {
00106          // this is a new footerCategory
00107          $footerCategory = $footerCategoryDao->newDataObject();
00108          $footerCategory->setPressId($this->getPressId());
00109          $existingFooterCategory = false;
00110       } else {
00111          $existingFooterCategory = true;
00112       }
00113 
00114       $footerCategory->setTitle($this->getData('title'), null); // localized
00115       $footerCategory->setDescription($this->getData('description'), null); // localized
00116       $footerCategory->setPath($this->getData('path'));
00117 
00118       if ($existingFooterCategory) {
00119          $footerCategoryDao->updateObject($footerCategory);
00120          $footerCategoryId = $footerCategory->getId();
00121       } else {
00122          $footerCategoryId = $footerCategoryDao->insertObject($footerCategory);
00123          $this->setFooterCategory($footerCategory); // so insertEntry() has it for new FooterLinks
00124       }
00125 
00126       // for the footer links in the listbuilder.
00127       ListbuilderHandler::unpack($request, $this->getData('footerLinks'));
00128 
00129       return $footerCategoryId;
00130    }
00131 
00135    function insertEntry($request, $newRowId) {
00136       $rowData = $newRowId;
00137 
00138       $footerLink =& $this->getFooterLinkFromRowData($request, $rowData);
00139       $press =& $request->getPress();
00140       $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00141       $footerLinkDao->insertObject($footerLink);
00142       return true;
00143    }
00144 
00148    function updateEntry($request, $rowId, $newRowId) {
00149       $rowData = $newRowId;
00150       $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00151       $footerLink =& $footerLinkDao->getById($rowId);
00152       if (!is_a($footerLink, 'FooterLink')) {
00153          assert(false);
00154          return false;
00155       }
00156 
00157       if ($rowData) {
00158          $footerLink =& $this->_setLocaleData($footerLink, $rowData);
00159          $footerLink->setUrl($rowData['url']);
00160       }
00161 
00162       $footerLinkDao->updateObject($footerLink);
00163       return true;
00164    }
00165 
00169    function deleteEntry($request, $rowId) {
00170       if ($rowId) {
00171          $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00172          $footerLink =& $footerLinkDao->getById($rowId);
00173          if (!is_a($footerLink, 'FooterLink')) {
00174             assert(false);
00175             return false;
00176          }
00177          $footerLinkDao->deleteObject($footerLink);
00178       }
00179    }
00180 
00187    function &getFooterLinkFromRowData(&$request, $rowData) {
00188       $footerLinkDao =& DAORegistry::getDAO('FooterLinkDAO');
00189       $footerLink = $footerLinkDao->newDataObject();
00190 
00191       if ($rowData) {
00192          $footerLink =& $this->_setLocaleData($footerLink, $rowData);
00193          $footerLink->setUrl($rowData['url']);
00194       }
00195 
00196       $press =& $request->getPress();
00197       $footerLink->setPressId($press->getId());
00198       $footerCategory =& $this->getFooterCategory();
00199       if (isset($footerCategory)) {
00200          $footerLink->setCategoryId($footerCategory->getId());
00201       }
00202 
00203       return $footerLink;
00204    }
00205 
00206 
00207    //
00208    // Private helper methods.
00209    //
00216    function &_setLocaleData(&$footerLink, $rowData) {
00217       foreach($rowData['title'] as $locale => $data) {
00218          $footerLink->setTitle($data, $locale);
00219       }
00220 
00221       return $footerLink;
00222    }
00223 
00224    //
00225    // helper methods.
00226    //
00227 
00232    function &getFooterCategory() {
00233       return $this->_footerCategory;
00234    }
00235 
00240    function setFooterCategory($footerCategory) {
00241       $this->_footerCategory =& $footerCategory;
00242    }
00243 
00248    function getPressId() {
00249       return $this->_pressId;
00250    }
00251 }
00252 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1