Esempio n. 1
0
 public function convert_from_storage($source)
 {
     if (!$this->storage->object) {
         // That's all folks, no storage object, thus we cannot continue.
         return;
     }
     $tags = net_nemein_tag_handler::get_object_tags($this->storage->object);
     $this->value = net_nemein_tag_handler::tag_array2string($tags);
 }
Esempio n. 2
0
 /**
  * Converts storage format to live format, all invalid keys are dropped, and basic validation
  * is done to ensure constraints like allow_multiple are met.
  */
 function convert_from_storage($source)
 {
     debug_print_r("source", $source);
     $this->selection = array();
     if ($this->option_callback !== null) {
         $source = $this->_callback->list_all();
     }
     if ($this->use_tag_library || $this->force_saving_to_tag_library) {
         if (!$this->storage->object) {
             $source = null;
         } else {
             $tags = net_nemein_tag_handler::get_object_tags($this->storage->object);
             $source = net_nemein_tag_handler::tag_array2string($tags);
         }
         debug_add("tag lib single source: {$source}");
     }
     if ($source === false || $source === null) {
         // We are fine at this point.
         return;
     }
     if ($this->allow_multiple) {
         // In multiselect mode, we need to convert as per type setting.
         $source = $this->_convert_multiple_from_storage($source);
     } else {
         if (!is_array($source)) {
             $source = array($source);
         }
     }
     debug_add("final source: {$source}");
     foreach ($source as $key) {
         $key = (string) $key;
         if ($this->key_exists($key)) {
             $this->selection[] = $key;
             if (!$this->allow_multiple) {
                 // Whatever happens, in this mode we only have one key.
                 return;
             }
         } else {
             if (!$this->require_corresponding_option) {
                 $this->selection[] = $key;
                 if (!$this->allow_multiple) {
                     // Whatever happens, in this mode we only have one key.
                     return;
                 }
             } else {
                 if ($this->allow_other) {
                     $this->others[] = $key;
                     if (!$this->allow_multiple) {
                         // Whatever happens, in this mode we only have one key.
                         return;
                     }
                 } else {
                     debug_add("Encountered unknown key {$key} for field {$this->name}, skipping it.", MIDCOM_LOG_INFO);
                 }
             }
         }
     }
 }