dmBridge PHP API
UNLVRandomAddForm.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 UNLVRandomAddForm extends DMAbstractForm {
00014 
00015    protected function init() {
00016       $f = new DMSelectField('alias');
00017       $f->addAttribute('id', 'alias');
00018       $f->addOption('', 'Choose a collection...');
00019       foreach (DMCollection::getAuthorized() as $c) {
00020          $f->addOption($c->getAlias(), DMString::truncate($c->getName(), 60));
00021       }
00022       $f->setLabel('Collection');
00023       $this->addField($f);
00024 
00025       $f = new DMTextField('ptr');
00026       $f->addAttribute('id', 'ptr');
00027       $f->addAttribute('size', '7');
00028       $f->setType(DMFormFieldType::INTEGER);
00029       $f->setMin(0);
00030       $f->setMax(1000000);
00031       $f->setLabel('Pointer');
00032       $this->addField($f);
00033    }
00034 
00035    protected function loadFromDataStore() {}
00036 
00037    public function doAction() {
00038       $col = DMCollectionFactory::getCollection(
00039          $this->getFieldByName('alias')->getValue());
00040       $ptr = $this->getFieldByName('ptr')->getValue();
00041       $object = DMObjectFactory::getObject($col, $ptr);
00042       $ds = UNLVRandomDataStoreFactory::getDataStore();
00043 
00044       // check to make sure the object doesn't already exist
00045       if ($ds->isRandomObject($object)) {
00046          throw new DMIllegalArgumentException(
00047             DMLocalizedString::getString("RANDOM_OBJECT_ALREADY_EXISTS",
00048                   dirname(__FILE__) . "/../strings"));
00049       }
00050       // nope, so add it
00051 
00052       $ds->addRandomObject($object);
00053    }
00054 
00055 }
00056 
 All Data Structures Functions Variables