dmBridge PHP API
DMCPCommentSettingsForm.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class DMCPCommentSettingsForm extends DMAbstractForm {
00014 
00015    protected function init() {
00016       $f = new DMSelectField('enable');
00017       $f->addAttribute('id', 'enable');
00018       $f->addOption(1, 'Enable Commenting');
00019       $f->addOption(0, 'Disable Commenting');
00020       $f->setLabel('Enable');
00021       $this->addField($f);
00022 
00023       $f = new DMSelectField('moderation');
00024       $f->addAttribute('id', 'moderation');
00025       $f->addOption(1, 'Enabled');
00026       $f->addOption(0, 'Disabled');
00027       $f->setLabel('Moderation');
00028       $f->setRequired(false);
00029       $this->addField($f);
00030 
00031       $f = new DMSelectField('notification');
00032       $f->addAttribute('id', 'notification');
00033       $f->addOption(1, 'Enabled');
00034       $f->addOption(0, 'Disabled');
00035       $f->setLabel('Notification');
00036       $f->setRequired(false);
00037       $this->addField($f);
00038 
00039       $f = new DMTextField('notification_email');
00040       $f->addAttribute('id', 'notification_email');
00041       $f->addAttribute('size', 30);
00042       $f->setType(DMFormFieldType::EMAIL);
00043       $f->setRequired(false);
00044       $f->setLabel('Notification email');
00045       $this->addField($f);
00046    }
00047 
00048    protected function loadFromDataStore() {
00049       $enabled = DMConfigXML::getInstance()->isCommentingEnabled();
00050       $this->getFieldByName('enable')->setValue((int) $enabled);
00051 
00052       $this->getFieldByName('moderation')->setValue(
00053          (int) DMConfigXML::getInstance()->isCommentModerationEnabled());
00054       $this->getFieldByName("moderation")->setEnabled($enabled);
00055 
00056       $this->getFieldByName('notification')->setValue(
00057          (int) DMConfigXML::getInstance()->isCommentNotificationEnabled());
00058       $this->getFieldByName("notification")->setEnabled($enabled);
00059 
00060       $this->getFieldByName('notification_email')->setValue(
00061          DMConfigXML::getInstance()->getCommentNotificationEmail());
00062       $this->getFieldByName("notification_email")->setEnabled($enabled);
00063    }
00064 
00068    public function validate() {
00069       $this->getFieldByName("notification_email")->setRequired(
00070             $this->getFieldByName('notification')->getValue());
00071       parent::validate();
00072    }
00073 
00074    public function doAction() {
00075       $bool = (bool) $this->getFieldByName('moderation')->getValue();
00076       DMConfigXML::getInstance()->setCommentModerationEnabled($bool);
00077       if (!$bool) {
00078          // approve all unapproved comments
00079          $ds = DMDataStoreFactory::getDataStore();
00080          if ($ds) {
00081             $cq = new DMCommentQuery($ds);
00082             $cq->setApproved(-1);
00083             foreach ($cq->getSearchResults() as $c) {
00084                $c->setApproved(true);
00085                DMDataStoreFactory::getDataStore()->saveComment($c);
00086             }
00087          }
00088       }
00089       DMConfigXML::getInstance()->setCommentingEnabled(
00090          (bool) $this->getFieldByName('enable')->getValue());
00091       DMConfigXML::getInstance()->setCommentNotificationEnabled(
00092          (bool) $this->getFieldByName('notification')->getValue());
00093       DMConfigXML::getInstance()->setCommentNotificationEmail(
00094          $this->getFieldByName('notification_email')->getValue());
00095       DMConfigXML::getInstance()->save();
00096    }
00097 
00098 }
 All Data Structures Functions Variables