dmBridge PHP API
DMCPTagSettingsForm.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 DMCPTagSettingsForm extends DMAbstractForm {
00014 
00015    protected function init() {
00016       $f = new DMSelectField('enable');
00017       $f->addAttribute('id', 'enable');
00018       $f->addOption(1, 'Enable Tagging');
00019       $f->addOption(0, 'Disable Tagging');
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       $this->addField($f);
00029    }
00030 
00031    protected function loadFromDataStore() {
00032       $this->getFieldByName('enable')->setValue(
00033          (int) DMConfigXML::getInstance()->isTaggingEnabled());
00034       $this->getFieldByName('moderation')->setValue(
00035          (int) DMConfigXML::getInstance()->isTagModerationEnabled());
00036    }
00037 
00038    public function doAction() {
00039       $bool = (bool) $this->getFieldByName('moderation')->getValue();
00040       if (!$bool) {
00041          // approve all unapproved tags
00042          $ds = DMDataStoreFactory::getDataStore();
00043          $tq = new DMTagQuery($ds);
00044          $tq->setApproved(-1);
00045          foreach ($tq->getSearchResultsAsObjects() as $t) {
00046             $t->setApproved(true);
00047             $ds->saveTag($t);
00048          }
00049       }
00050       DMConfigXML::getInstance()->setTaggingEnabled(
00051             (bool) $this->getFieldByName('enable')->getValue());
00052       DMConfigXML::getInstance()->setTagModerationEnabled($bool);
00053       DMConfigXML::getInstance()->save();
00054    }
00055 
00056 }
 All Data Structures Functions Variables