public function getAttribute() { if (!$this->attribute) { $att = new Dase_DBO_Attribute($this->db); $att->load($this->attribute_id); $this->attribute = $att; } return $this->attribute; }
function insert($db, $r, $collection) { $att = new Dase_DBO_Attribute($db); $att->attribute_name = $this->getTitle(); //think about using getAscii or Slug also $att->ascii_id = Dase_Util::dirify($att->attribute_name); if (!Dase_DBO_Attribute::get($db, $collection->ascii_id, $att->ascii_id)) { $att->collection_id = $collection->id; $att->updated = date(DATE_ATOM); $att->sort_order = 9999; $att->is_on_list_display = 1; $att->is_public = 1; $att->in_basic_search = 1; $att->html_input_type = $this->getHtmlInputType(); $att->insert(); $sort_order = 0; foreach ($this->getDefinedValues() as $dv) { $sort_order++; $att->addDefinedValue($dv, $sort_order); } foreach ($this->getItemTypes() as $type) { $att->addItemType($type); } $att->resort(); } else { throw new Dase_Exception('attribute exists'); } return $att; }
/** implicit 1000 limit */ public function getAttributeValuesJson($r) { $attr = Dase_DBO_Attribute::get($this->db, $r->get('collection_ascii_id'), $r->get('att_ascii_id')); if (!$attr) { $r->renderError('404'); } if (0 == $attr->collection_id) { //since it is admin att we need to be able to limit to items in this coll $values_array = $attr->getDisplayValues($this->collection->ascii_id, $r->get('limit')); } else { $values_array = $attr->getDisplayValues(null, $r->get('limit')); } $result['att_name'] = $attr->attribute_name; $result['att_ascii'] = $attr->ascii_id; $result['coll'] = $r->get('collection_ascii_id'); $result['values'] = $values_array; $json_result = Dase_Json::get($result); if ($r->get('callback')) { $r->renderResponse($r->get('callback') . '(' . $json_result . ');'); } else { $r->renderResponse($json_result); } }
public function getAttributes() { $attributes = array(); if ('default' == $this->ascii_id) { $c = $this->getCollection(); foreach ($c->getAttributes() as $att) { $att = clone $att; $att->getFormValues(); $attributes[strtolower($att->attribute_name)] = $att; } } else { $att_it = new Dase_DBO_AttributeItemType($this->db); $att_it->item_type_id = $this->id; foreach ($att_it->find() as $ait) { $att = new Dase_DBO_Attribute($this->db); if ($att->load($ait->attribute_id)) { $att->getFormValues(); // for sorting // are attribute names unique??? $attributes[strtolower($att->attribute_name)] = $att; } } } ksort($attributes); $this->attributes = $attributes; return $attributes; }
function insert($db, $r, $fetch_enclosure = false) { $user = $r->getUser('http'); //allows service user to override created_by_eid $author = $this->getAuthorName(); if ($user->is_serviceuser && $author) { $created_by_eid = $author; } else { $created_by_eid = $user->eid; } $c = Dase_DBO_Collection::get($db, $r->get('collection_ascii_id')); if (!$c) { return; } $sn = Dase_Util::makeSerialNumber($r->slug); $item = $c->createNewItem($sn, $created_by_eid); foreach ($this->getMetadata() as $att => $keyval) { //creates atribute if it doesn't exist! Dase_DBO_Attribute::findOrCreate($db, $c->ascii_id, $att); foreach ($keyval['values'] as $v) { if (trim($v['text'])) { $val = $item->setValue($att, $v['text'], null, $v['mod']); } } } foreach ($this->getMetadataLinks() as $att => $keyval) { Dase_DBO_Attribute::findOrCreate($db, $c->ascii_id, $att); foreach ($keyval['values'] as $v) { if (trim($v['text'])) { //check that it's proper collection if ($c->ascii_id = $v['coll']) { //don't index just yet (the false param) $val = $item->setValueLink($att, $v['text'], $v['url'], $v['mod'], false); } } } } //item_type $item_type = $this->getItemType(); if ($item_type['term']) { $item->setItemType($item_type['term']); } //content if ($this->getContent()) { $item->setContent($this->getContent(), $eid, $this->getContentType()); } //$item->setValue('title',$this->getTitle()); //$item->setValue('description',$this->getSummary()); if ($fetch_enclosure) { $enc = $this->getEnclosure(); if ($enc) { $upload_dir = MEDIA_DIR . '/' . $c->ascii_id . '/uploaded_files'; if (!file_exists($upload_dir)) { $r->renderError(401, 'missing upload directory'); } $ext = Dase_File::$types_map[$enc['type']]['ext']; $new_file = $upload_dir . '/' . $item->serial_number . '.' . $ext; file_put_contents($new_file, file_get_contents($enc['href'])); try { $file = Dase_File::newFile($db, $new_file, $enc['mime_type']); $media_file = $file->addToCollection($item, false, MEDIA_DIR); } catch (Exception $e) { $r->renderError(500, 'could not ingest enclosure file (' . $e->getMessage() . ')'); } } } //messy $item->expireCaches($r->getCache()); $item->buildSearchIndex(); return $item; }
public function getItemsByAttAsAtom($attribute_ascii_id, $app_root) { $feed = $this->getBaseAtomFeed($app_root); $feed->setFeedType('items'); $att = Dase_DBO_Attribute::get($this->db, $this->ascii_id, $attribute_ascii_id); $vals = new Dase_DBO_Value($this->db); $vals->attribute_id = $att->id; foreach ($vals->find() as $val) { $item = new Dase_DBO_Item($this->db); $item->load($val->item_id); //use cached ??? $entry = $item->injectAtomEntryData($feed->addEntry(), $app_root); $entry->setSummary($item->getValue($attribute_ascii_id)); } return $feed->asXML($app_root); }
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); } }
public function getAttributes($r) { $atts = array(); $tpl = new Dase_Template($r); $aa = new Dase_DBO_Attribute($this->db); $aa->collection_id = 0; $aa->orderBy('attribute_name'); foreach ($aa->find() as $a) { //NOTE that you *must* use clone here!! $atts[] = clone $a; } $tpl->assign('atts', $atts); $r->renderResponse($tpl->fetch('admin/attributes.tpl')); }
public static function sortIdArray($db, $sort, $item_ids) { $sortable_array = array(); $test_att = new Dase_DBO_Attribute($db); $test_att->ascii_id = $sort; if (!$test_att->findOne()) { return $item_ids; } $prefix = $db->table_prefix; $dbh = $db->getDbh(); $sql = "\n\t\t\t\t\t\tSELECT v.value_text\n\t\t\t\t\t\tFROM {$prefix}attribute a, {$prefix}value v\n\t\t\t\t\t\tWHERE v.item_id = ?\n\t\t\t\t\t\tAND v.attribute_id = a.id\n\t\t\t\t\t\tAND a.ascii_id = ?\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t"; $sth = $dbh->prepare($sql); foreach ($item_ids as $item_id) { $sth->execute(array($item_id, $sort)); $vt = $sth->fetchColumn(); $value_text = $vt ? $vt : 99999999; $sortable_array[$item_id] = $value_text; } if (is_array($sortable_array)) { asort($sortable_array); return array_keys($sortable_array); } }
function getAdminEquiv($mapped_id) { if ($this->mapped_admin_att_id) { $mapped_id = $this->mapped_admin_att_id; } $aa = new Dase_DBO_Attribute($this->db); if ($aa->load($mapped_id)) { return $aa->ascii_id; } else { return 'none'; } }
<?php include 'config.php'; $colls = array(); $att = new Dase_DBO_Attribute($db); foreach ($att->findAll() as $a) { if ($a->ascii_id != Dase_Util::dirify($a->ascii_id)) { print "PROBLEM! {$a->ascii_id} "; $coll = $a->getCollection(); print "collection {$coll->ascii_id} "; $colls[$coll->ascii_id] = $coll->collection_name; print " values count: " . $a->getValuesCount(); print " item types count: " . count($a->getItemTypes()); print " defined values count: " . count($a->getDefinedValues()); $lower = Dase_Util::dirify($a->ascii_id); $a->ascii_id = $lower; //$a->update(); print $a; print "\n"; } else { print "OK {$a->ascii_id}\n"; } } print_r($colls);
/** 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'); }
public function getAdminAttributesJson($r) { $r->checkCache(); $c = $this->collection; $attributes = new Dase_DBO_Attribute($this->db); $attributes->collection_id = 0; $attributes->orderBy('attribute_name'); $att_array = array(); foreach ($attributes->find() as $att) { $att_array[] = array('id' => $att->id, 'ascii_id' => $att->ascii_id, 'attribute_name' => $att->attribute_name, 'input_type' => $att->html_input_type, 'sort_order' => $att->sort_order, 'collection' => $r->get('collection_ascii_id')); } $r->renderResponse(Dase_Json::get($att_array), $r); }