function getItem() { if (!$this->item) { $this->item = Dase_DBO_Item::get($this->db, $this->p_collection_ascii_id, $this->p_serial_number); } return $this->item; }
public static function getByUnique($db, $unique) { $sections = explode('/', $unique); $sernum = array_pop($sections); $coll = array_pop($sections); //will return false if no such item return Dase_DBO_Item::get($db, $coll, $sernum); }
protected function setup($r) { //do we really want to hit db w/ every request? $this->item = Dase_DBO_Item::get($this->db, $r->get('collection_ascii_id'), $r->get('serial_number')); if (!$this->item && 'put' != $r->method) { $r->renderError(404); } //all auth happens in individual methods }
public function getItem($r) { $t = new Dase_Template($r, true); $item = Dase_DBO_Item::get($this->db, $r->get('coll_ascii'), $r->get('serial_number')); $json = $item->asJson($r->app_root); $php_data = json_decode($json, true); $t->assign('item', $php_data); $t->assign('coll_ascii', $r->get('coll_ascii')); $r->renderResponse($t->fetch('item.tpl')); }
function getItem() { $item = new Dase_DBO_Item($this->db); if ($item->load($this->item_id)) { $item->getCollection(); return $item; } else { if ($this->p_collection_ascii_id && $this->p_serial_number) { $item = Dase_DBO_Item::get($this->db, $this->p_collection_ascii_id, $this->p_serial_number); if ($item) { $item->getCollection(); return $item; } } } return false; }
public function postToCart($r) { $u = $this->user; $u->expireDataCache($r->getCache()); $tag = new Dase_DBO_Tag($this->db); $tag->dase_user_id = $u->id; $tag->type = 'cart'; if ($tag->findOne()) { $tag_item = new Dase_DBO_TagItem($this->db); $item_uniq = str_replace($r->app_root . '/', '', $r->getBody()); list($coll, $sernum) = explode('/', $item_uniq); //todo: compat $item = Dase_DBO_Item::get($this->db, $coll, $sernum); $tag_item->item_id = $item->id; $tag_item->p_collection_ascii_id = $coll; $tag_item->p_serial_number = $sernum; $tag_item->tag_id = $tag->id; $tag_item->updated = date(DATE_ATOM); $tag_item->sort_order = 99999; if ($tag_item->insert()) { //will not need this when we use item_unique: //writes are expensive ;-) //$tag_item->persist(); $tag->updateItemCount(); $r->renderResponse("added cart item {$tag_item->id}"); } else { $r->renderResponse("add to cart failed"); } } else { $r->renderResponse("no such cart"); } }
function addLinks($db, $r) { $eid = $r->getUser()->eid; $sernum = $this->getSerialNumber(); $c = Dase_DBO_Collection::get($db, $r->get('collection_ascii_id')); if (!$c) { return; } $item = Dase_DBO_Item::get($db, $c->ascii_id, $sernum); if (!$item) { return; } $item->updated = date(DATE_ATOM); $item->update(); foreach ($this->getMetadataLinks() as $att => $keyval) { foreach ($keyval['values'] as $v) { if (trim($v['text'])) { //check that it's proper collection if ($c->ascii_id = $v['coll']) { $val = $item->setValueLink($att, $v['text'], $v['url'], $v['mod']); } } } } $item->buildSearchIndex(); return $item; }
function removeItem($item_unique, $update_count = false) { $tag_item = new Dase_DBO_TagItem($this->db); $tag_item->tag_id = $this->id; list($coll, $sernum) = explode('/', $item_unique); //todo: compat $item = Dase_DBO_Item::get($this->db, $coll, $sernum); $tag_item->item_id = $item->id; $tag_item->p_collection_ascii_id = $coll; $tag_item->p_serial_number = $sernum; if ($tag_item->findOne()) { $log_text = "removing {$item_unique} from set {$this->eid}/{$this->ascii_id}"; Dase_Log::info(LOG_FILE, $log_text); $tag_item->delete(); //this is too expensive when many items are being removed in one request if ($update_count) { $this->updateItemCount(); } } }
public function deleteMedia($r) { $item = Dase_DBO_Item::get($this->db, $this->collection_ascii_id, $this->serial_number); if (!$item) { $r->renderError(404, 'no such item'); } if (!$this->user->can('write', $item)) { $r->renderError(401, 'cannot delete media in this item'); } try { $item->deleteAdminValues(); //move actual files to 'deleted' directory $item->deleteMedia(MEDIA_DIR); } catch (Exception $e) { Dase_Log::debug(LOG_FILE, 'media handler error: ' . $e->getMessage()); $r->renderError(500, 'could not delete media (' . $e->getMessage() . ')'); } $item->buildSearchIndex(); $r->renderOk('deleted resource'); }