示例#1
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;
     }
 }