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; }
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'); } }
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; } }