Example #1
0
 public static function findOrCreate($db, $collection_ascii_id, $ascii_id)
 {
     $type = new Dase_DBO_ItemType($db);
     $coll = Dase_DBO_Collection::get($db, $collection_ascii_id);
     if (!$coll) {
         throw new Exception('no such collection');
     }
     $type->collection_id = $coll->id;
     $type->ascii_id = Dase_Util::dirify($ascii_id);
     if (!$type->findOne()) {
         $type->name = ucwords(str_replace('_', ' ', $ascii_id));
         $type->insert();
     }
     return $type;
 }
Example #2
0
 protected function setup($r)
 {
     $this->type = Dase_DBO_ItemType::get($this->db, $r->get('collection_ascii_id'), $r->get('item_type_ascii_id'));
     if (!$this->type) {
         $r->renderError(404);
     }
 }
Example #3
0
 function insert($db, $r, $collection)
 {
     //think about using Slug also
     $ascii_id = Dase_Util::dirify($this->getAsciiId());
     if (!$ascii_id) {
         $ascii_id = Dase_Util::dirify($this->getTitle());
     }
     if (!Dase_DBO_ItemType::get($db, $collection->ascii_id, $ascii_id)) {
         $type = new Dase_DBO_ItemType($db);
         $type->ascii_id = $ascii_id;
         $type->name = $this->getTitle();
         $type->collection_id = $collection->id;
         $type->description = $this->getSummary();
         $type->insert();
         return $type;
     } else {
         throw new Dase_Exception('item type exists');
     }
 }
Example #4
0
 function getItemTypes()
 {
     $res = array();
     $types = new Dase_DBO_ItemType($this->db);
     $types->collection_id = $this->id;
     $types->orderBy('name');
     foreach ($types->find() as $t) {
         $res[] = clone $t;
     }
     return $res;
 }
Example #5
0
 public function deleteItemTypeAttribute($r)
 {
     $type = Dase_DBO_ItemType::get($this->db, $this->collection->ascii_id, $r->get('type_ascii_id'));
     $att = Dase_DBO_Attribute::get($this->db, $this->collection->ascii_id, $r->get('att_ascii_id'));
     $ita = new Dase_DBO_AttributeItemType($this->db);
     $ita->attribute_id = $att->id;
     $ita->item_type_id = $type->id;
     if ($ita->findOne()) {
         $ita->delete();
         $r->renderOk('done');
     } else {
         $r->renderError(400);
     }
 }
Example #6
0
 function setItemType($type_ascii_id = '')
 {
     if (!$type_ascii_id || 'none' == $type_ascii_id || 'default' == $type_ascii_id) {
         $this->item_type_id = 0;
         $this->item_type_ascii_id = 'default';
         $this->item_type_name = 'default';
         $this->updated = date(DATE_ATOM);
         $this->update();
         return true;
     }
     $type = new Dase_DBO_ItemType($this->db);
     $type->ascii_id = $type_ascii_id;
     $type->collection_id = $this->collection_id;
     if ($type->findOne()) {
         $this->item_type_id = $type->id;
         $this->item_type_ascii_id = $type->ascii_id;
         $this->item_type_name = $type->name;
         $this->updated = date(DATE_ATOM);
         $this->update();
         $this->_item_type = $type;
         return true;
     } else {
         //now w/ auto-create 3/18/2011
         $type->name = $type_ascii_id;
         $type->insert();
         $this->item_type_id = $type->id;
         $this->item_type_ascii_id = $type->ascii_id;
         $this->item_type_name = $type->name;
         $this->updated = date(DATE_ATOM);
         $this->update();
         $this->_item_type = $type;
         return true;
     }
 }
Example #7
0
 function addItemType($item_type_ascii)
 {
     $c = $this->getCollection();
     $type = Dase_DBO_ItemType::get($this->db, $c->ascii_id, $item_type_ascii);
     if ($type) {
         $ita = new Dase_DBO_AttributeItemType($this->db);
         $ita->attribute_id = $this->id;
         $ita->item_type_id = $type->id;
         if (!$ita->findOne()) {
             $ita->insert();
         }
     }
 }
Example #8
0
 /** for now, PUT of a collection entry can only add, NOT delete item_types & attributes */
 function update($db, $r)
 {
     $coll = $this->getAsciiId();
     foreach ($this->getAttributes() as $att) {
         Dase_DBO_Attribute::findOrCreate($db, $coll, $att['term']);
     }
     foreach ($this->getItemTypes() as $type) {
         Dase_DBO_ItemType::findOrCreate($db, $coll, $type['term']);
     }
     $coll = Dase_DBO_Collection::get($db, $coll);
     $coll->updateVisibility($this->getVisibility());
     $r->renderResponse('updated collection');
 }