Beispiel #1
0
 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;
 }
Beispiel #2
0
 function setValue($att_ascii_id, $value_text, $url = '', $modifier = '', $index = false)
 {
     if (!trim($att_ascii_id) || !trim($value_text) && "0" !== $value_text) {
         return false;
     }
     //allows for admin metadata, att_ascii for which always begins 'admin_'
     //NOTE: we DO create att if it does not exist
     if (false === strpos($att_ascii_id, 'admin_')) {
         $att = Dase_DBO_Attribute::findOrCreate($this->db, $this->p_collection_ascii_id, $att_ascii_id);
     } else {
         $att = Dase_DBO_Attribute::findOrCreateAdmin($this->db, $att_ascii_id);
     }
     if ($att) {
         if ('listbox' == $att->html_input_type) {
             //never includes url or modifier
             $pattern = '/[\\n;]/';
             $prepared_string = preg_replace($pattern, '%', trim($value_text));
             $values_array = explode('%', $prepared_string);
             foreach ($values_array as $val_txt) {
                 $v = new Dase_DBO_Value($this->db);
                 $v->item_id = $this->id;
                 $v->attribute_id = $att->id;
                 $v->value_text = $val_txt;
                 //note: duplicate detection
                 //added 4/9/2010
                 if (!$v->findOne()) {
                     $v->insert();
                 }
             }
         } else {
             $v = new Dase_DBO_Value($this->db);
             $v->item_id = $this->id;
             $v->attribute_id = $att->id;
             $v->value_text = trim($value_text);
             $v->url = $url;
             $v->modifier = $modifier;
             //note: duplicate detection
             //added 4/9/2010
             if (!$v->findOne()) {
                 $v->insert();
             }
             if ($index) {
                 $this->updated = date(DATE_ATOM);
                 $this->update();
                 $this->buildSearchIndex();
             }
             return $v;
         }
         if ($index) {
             $this->updated = date(DATE_ATOM);
             $this->update();
             $this->buildSearchIndex();
         }
     } else {
         //simply returns false if no such attribute
         Dase_Log::debug(LOG_FILE, '[WARNING] no such attribute ' . $att_ascii_id);
         return false;
     }
 }
Beispiel #3
0
 public function postToAttributes($r)
 {
     $att_ascii_id = Dase_Util::dirify($r->get('attribute_name'));
     //note if att_ascii_id MATCHES, we do not create a new att, we grab match
     $att = Dase_DBO_Attribute::findOrCreate($this->db, $this->collection->ascii_id, $att_ascii_id);
     $att->attribute_name = $r->get('attribute_name');
     $att->usage_notes = $r->get('usage_notes');
     $att->modifier_defined_list = $r->get('modifier_defined_list');
     if ($r->has('is_on_list_display')) {
         $att->is_on_list_display = 1;
     } else {
         $att->is_on_list_display = 0;
     }
     if ($r->has('in_basic_search')) {
         $att->in_basic_search = 1;
     } else {
         $att->in_basic_search = 0;
     }
     if ($r->has('is_public')) {
         $att->is_public = 1;
     } else {
         $att->is_public = 0;
     }
     if ($r->has('is_repeatable')) {
         $att->is_repeatable = 1;
     } else {
         $att->is_repeatable = 0;
     }
     if ($r->has('is_required')) {
         $att->is_required = 1;
     } else {
         $att->is_required = 0;
     }
     $att->html_input_type = $r->get('input_type');
     $att->update();
     $att->resort('999');
     $params['msg'] = "{$att->attribute_name} created";
     $r->renderRedirect('manage/' . $this->collection->ascii_id . '/attribute/' . $att->ascii_id, $params);
 }
Beispiel #4
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');
 }