Esempio n. 1
0
 /**
  * Get the meta data from a photo
  *
  * @param array An array of PinholePhotoMetaDataBinding data objects
  *               with $shortname as the key of the array.
  * @return array An array of PinholeMetaData dataobjects
  */
 protected function saveMetaDataInternal($meta_data)
 {
     $instance_id = $this->image_set->instance === null ? null : $this->image_set->instance->id;
     $where_clause = sprintf('PinholeMetaData.instance %s %s', SwatDB::equalityOperator($instance_id), $this->db->quote($instance_id, 'integer'));
     $existing_meta_data = SwatDB::getOptionArray($this->db, 'PinholeMetaData', 'shortname', 'id', null, $where_clause);
     foreach ($meta_data as $data) {
         $shortname = substr($data->shortname, 0, 255);
         $title = substr($data->title, 0, 255);
         if (mb_check_encoding($data->value, 'UTF-8')) {
             $value = $data->value;
         } else {
             // assume ISO-8859-1
             $value = iconv('ISO-8859-1', 'UTF-8', $data->value);
         }
         $value = substr($value, 0, 255);
         if (!in_array($shortname, $existing_meta_data)) {
             $meta_data_id = SwatDB::insertRow($this->db, 'PinholeMetaData', array('text:shortname', 'text:title', 'integer:instance'), array('shortname' => $shortname, 'title' => $title, 'instance' => $instance_id), 'id');
         } else {
             $meta_data_id = array_search($shortname, $existing_meta_data);
         }
         SwatDB::insertRow($this->db, 'PinholePhotoMetaDataBinding', array('integer:photo', 'integer:meta_data', 'text:value'), array('photo' => $this->id, 'meta_data' => $meta_data_id, 'value' => $value));
     }
 }