/**
  * get_instance
  *
  * Create the unique instance of class if not exist and return him
  *
  * @param void
  * @return taxonomymeta
  */
 public static function get_instance()
 {
     if (self::$oInstance == null) {
         self::$oInstance = new wpeo_taxonomy_meta();
     }
     return self::$oInstance;
 }
예제 #2
0
 /**
  * Construction de l'objet taxinomie par remplissage du modèle / Build taxonomy through fill in the model
  *
  * @param object $object L'object avec lequel il faut construire le modèle / The object which one to build
  * @param string $meta_key Le nom de la "meta" contenant la définition complète de l'object sous forme json / The "meta" name containing the complete definition of object under json format
  * @param boolean $cropped Permet de choisir si on construit le modèle complet ou uniquement les champs principaux / Allows to choose if the entire model have to be build or only main model
  */
 public function __construct($object, $meta_key, $cropped)
 {
     /**	Instanciation du constructeur de modèle principal / Instanciate the main model constructor	*/
     parent::__construct($object);
     /** If cropped don't get meta */
     if (!$cropped) {
         /** Lecture des "metas" pour la taxinomie / Read taxonomy "meta" */
         $meta = null;
         if (!empty($object) && is_object($object) && class_exists('wpeo_taxonomy_meta')) {
             $meta = wpeo_taxonomy_meta::get_term_taxonomy_meta($object->term_taxonomy_id);
         }
         $internal_meta = !empty($meta) && !empty($meta[$meta_key]) && !empty($meta[$meta_key][0]) ? json_decode($meta[$meta_key][0]) : null;
         if (!empty($this->array_option)) {
             foreach ($this->array_option as $key => $array) {
                 $this->option[$key] = $this->fill_value($object, $meta, $key, $array, $internal_meta);
             }
         }
     }
 }
예제 #3
0
 /**
  * SETTER - Enregistrement des données associées a un objet avec rangement selon les types de champs / Save information associated to an object regarding field type
  *
  * @param Object $object Définition complète de l'objet à enregistrer / Complete object definition to save
  */
 private function save_meta_data($object)
 {
     /** Read the object model option */
     $array_option = $object->get_array_option();
     foreach ($object->option as $field_name => $field) {
         if (!isset($array_option[$field_name]['type']) || is_array($array_option[$field_name]['type'])) {
             foreach ($field as $sub_field_name => $sub_field) {
                 if (isset($array_option[$sub_field_name]['field_type']) && 'meta' == $array_option[$sub_field_name]['field_type']) {
                     /** Update a single meta for specific field */
                     wpeo_taxonomy_meta::update_term_taxonomy_meta($object->term_taxonomy_id, $array_option[$sub_field_name]['field'], $object->option[$field_name][$sub_field_name]);
                     unset($object->option[$field_name][$sub_field_name]);
                 }
             }
         } else {
             if (isset($array_option[$field_name]['field_type']) && 'meta' == $array_option[$field_name]['field_type']) {
                 /** Update a single meta for specific field */
                 wpeo_taxonomy_meta::update_term_taxonomy_meta($object->term_taxonomy_id, $array_option[$field_name]['field'], $object->option[$field_name]);
                 unset($object->option[$field_name]);
             }
         }
     }
     /**	Update the main meta with json datas	*/
     wpeo_taxonomy_meta::update_term_taxonomy_meta($object->term_taxonomy_id, $this->meta_key, json_encode($object->option));
 }