Esempio n. 1
0
 private static function _addPlayerElement()
 {
     if (element_exists(ElementSet::ITEM_TYPE_NAME, 'Player')) {
         return;
     }
     $db = get_db();
     $table = $db->getTable('ItemType');
     $mpType = $table->findByName('Moving Image');
     if (!is_object($mpType)) {
         $mpType = new ItemType();
         $mpType->name = "Moving Image";
         $mpType->description = "A series of visual representations imparting an impression of motion when shown in succession. Examples include animations, movies, television programs, videos, zoetropes, or visual output from a simulation.";
         $mpType->save();
     }
     $mpType->addElements(array(array('name' => 'Player', 'description' => 'html for embedded player to stream video content')));
     $mpType->save();
 }
 public static function store()
 {
     self::check_logged_in();
     $params = $_POST;
     $attributes = array('name' => $params['name'], 'pnprefix' => $params['pnprefix']);
     $itemtype = new ItemType($attributes);
     $errors = $itemtype->errors();
     if (count($errors) == 0) {
         $itemtype->save();
         Redirect::to('/itemtype/' . $itemtype->id, array('message' => 'The new item type has been added to the database'));
     } else {
         View::make('itemtype/new.html', array('errors' => $errors, 'attributes' => $attributes));
     }
 }
Esempio n. 3
0
        break;
        // end default
    // end default
    case 'save':
        $ERRORS = array();
        $class_id = stripinput($_POST['item']['class_id']);
        if ($class_id == null) {
            $ERRORS[] = 'No class specified.';
        } else {
            $class = new ItemClass($db);
            $class = $class->findOneByItemClassId($class_id);
            if ($class == null) {
                $ERRORS[] = 'Invalid class specified.';
            }
        }
        // end id given
        if (sizeof($ERRORS) > 0) {
            draw_errors($ERRORS);
        } else {
            $item = new ItemType($db);
            $item->setItemClassId($class->getItemClassId());
            $item->setUniqueItem('N');
            $item->setTransferableItem('Y');
            $item->save();
            redirect(null, null, "admin-items-edit/?item[id]={$item->getItemTypeId()}");
        }
        // end no errors
        break;
        // end save
}
// end state switch
 /**
  * Install default profile
  *
  * Install default item types, elements, and profiles for easy setup
  *
  * @param array An array of parameters with names and descriptions
  *  of the default values we are setting up
  * @return void
  */
 public function installDefaults($params)
 {
     if (!($itemType = get_db()->getTable('ItemType')->findByName($params['typeName']))) {
         $itemType = new ItemType();
         $itemType->name = $params['typeName'];
         $itemType->description = $params['typeDesc'];
         $id = $itemType->save();
     }
     require_once dirname(dirname(dirname(__FILE__))) . '/models/MmdProfile.php';
     $profile = new MmdProfile();
     $profile->setViewer($this);
     $profile->name = $params['profileName'];
     $profile->viewer = $this->name;
     foreach ($this->_paramInfo as $param) {
         //$element = new Element();
         //check if element exists in Dublin Core
         $element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Dublin Core', $param['name']);
         if (empty($element)) {
             $element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Dublin Core', ucfirst($param['name']));
         }
         if (empty($element)) {
             $element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Dublin Core', strtoupper($param['name']));
         }
         if (empty($element)) {
             $element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Item Type Metadata', $param['name']);
         }
         if (empty($element)) {
             $element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Item Type Metadata', ucfirst($param['name']));
         }
         if (empty($element)) {
             $element = get_db()->getTable('Element')->findByElementSetNameAndElementName('Item Type Metadata', strtoupper($param['name']));
         }
         if (empty($element)) {
             $element = new Element();
             $element->setElementSet('Item Type Metadata');
             $element->setName($param['name']);
             $element->setDescription($param['description']);
             try {
                 $element->save();
             } catch (Exception $e) {
                 print_r($e);
                 die;
             }
         }
         $itemType->addElementById($element->id);
         if (isset($param['default']) && $param['default'] !== '') {
             $profile->setAuxParam($param['name'], $param['default'], 1);
         }
         if (isset($param['files'])) {
             $multiple = isset($param['multiple']) && $param['multiple'] != 'single' && $param['multiple'] ? 1 : 0;
             $fileparam = array('multiple' => isset($param['multiple']) && $param['multiple'] != 'single' && $param['multiple'] ? 1 : 0, 'extensions' => $param['files']);
             $profile->setAuxParam($param['name'], $fileparam, 2);
         }
         $profile->setAuxParam($param['name'], $element->id, 0);
     }
     $itemType->save();
     $item_type_id = $itemType->id;
     $profile->save();
     $profile_id = $profile->id;
     require_once dirname(dirname(dirname(__FILE__))) . '/models/MmdAssign.php';
     $assign = new MmdAssign();
     $assign->item_type_id = $item_type_id;
     $assign->profile_id = $profile_id;
     $assign->filetypes = $this->_allowedFiletypes;
     $assign->save();
     return 'Defaults installed successfully';
 }
Esempio n. 5
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aSize !== null) {
             if ($this->aSize->isModified() || $this->aSize->isNew()) {
                 $affectedRows += $this->aSize->save($con);
             }
             $this->setSize($this->aSize);
         }
         if ($this->aItemType !== null) {
             if ($this->aItemType->isModified() || $this->aItemType->isNew()) {
                 $affectedRows += $this->aItemType->save($con);
             }
             $this->setItemType($this->aItemType);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ItemPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ItemPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += ItemPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collItemRatings !== null) {
             foreach ($this->collItemRatings as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collSalesDetails !== null) {
             foreach ($this->collSalesDetails as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collShoppingCarts !== null) {
             foreach ($this->collShoppingCarts as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }