00001 <?php
00002
00016
00017
00018
00019 import('form.Form');
00020
00021 class AnnouncementTypeForm extends Form {
00023 var $typeId;
00024
00029 function AnnouncementTypeForm($typeId = null) {
00030 $this->typeId = isset($typeId) ? (int) $typeId : null;
00031
00032 parent::Form('manager/announcement/announcementTypeForm.tpl');
00033
00034
00035 $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'manager.announcementTypes.form.typeNameRequired'));
00036
00037 $this->addCheck(new FormValidatorPost($this));
00038 }
00039
00044 function getLocaleFieldNames() {
00045 $announcementTypeDao =& DAORegistry::getDAO('AnnouncementTypeDAO');
00046 return $announcementTypeDao->getLocaleFieldNames();
00047 }
00048
00052 function display() {
00053 $templateMgr = &TemplateManager::getManager();
00054 $templateMgr->assign('typeId', $this->typeId);
00055 $templateMgr->assign('helpTopicId', 'journal.managementPages.announcements');
00056
00057 parent::display();
00058 }
00059
00063 function initData() {
00064 if (isset($this->typeId)) {
00065 $announcementTypeDao = &DAORegistry::getDAO('AnnouncementTypeDAO');
00066 $announcementType = &$announcementTypeDao->getAnnouncementType($this->typeId);
00067
00068 if ($announcementType != null) {
00069 $this->_data = array(
00070 'name' => $announcementType->getName(null)
00071 );
00072
00073 } else {
00074 $this->typeId = null;
00075 }
00076 }
00077 }
00078
00082 function readInputData() {
00083 $this->readUserVars(array('name'));
00084 }
00085
00089 function execute() {
00090 $announcementTypeDao = &DAORegistry::getDAO('AnnouncementTypeDAO');
00091 $journal = &Request::getJournal();
00092
00093 if (isset($this->typeId)) {
00094 $announcementType = &$announcementTypeDao->getAnnouncementType($this->typeId);
00095 }
00096
00097 if (!isset($announcementType)) {
00098 $announcementType = &new AnnouncementType();
00099 }
00100
00101 $announcementType->setJournalId($journal->getJournalId());
00102 $announcementType->setName($this->getData('name'), null);
00103
00104
00105 if ($announcementType->getTypeId() != null) {
00106 $announcementTypeDao->updateAnnouncementType($announcementType);
00107 } else {
00108 $announcementTypeDao->insertAnnouncementType($announcementType);
00109 }
00110 }
00111 }
00112
00113 ?>