Exemple #1
0
 /**
  * As shortcat, Important the & MUST be there, even in php5.3
  *
  * @author Max Milbers
  * @param array/obj $data input data as assoc array or obj
  * @param boolean $preload You can preload the data here too preserve not updated data
  * @return array/obj $data the updated data
  */
 public function bindChecknStore(&$data, $preload = false)
 {
     $tblKey = $this->_tbl_key;
     $ok = true;
     if ($this->_translatable) {
         if (!class_exists('tsmTableData')) {
             require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmtabledata.php';
         }
         $db = JFactory::getDBO();
         $dataTable = clone $this;
         $langTable = new tsmTableData($this->_tbl_lang, $tblKey, $db);
         $langTable->setLanguage($this->_langTag);
         $langTable->setPrimaryKey($tblKey);
         $langData = array();
         $langObKeys = array();
         $langUniqueKeys = array();
         if (is_object($data)) {
             foreach ($this->_translatableFields as $name) {
                 $langTable->{$name} = $this->{$name};
                 if (isset($data->{$name})) {
                     //We directly store language stuff "escaped"
                     $langData[$name] = htmlspecialchars(html_entity_decode($data->{$name}, ENT_QUOTES, "UTF-8"), ENT_QUOTES, "UTF-8");
                 }
                 unset($dataTable->{$name});
                 if (!empty($this->_unique_name[$name])) {
                     $langUniqueKeys[$name] = 1;
                     unset($dataTable->_unique_name[$name]);
                     $langObKeys[$name] = 1;
                     unset($dataTable->_obkeys[$name]);
                 }
                 if (!empty($this->_obkeys[$name])) {
                     $langObKeys[$name] = 1;
                     unset($dataTable->_obkeys[$name]);
                 }
             }
         } else {
             foreach ($this->_translatableFields as $name) {
                 $langTable->{$name} = $this->{$name};
                 if (isset($data[$name])) {
                     $langData[$name] = htmlspecialchars(html_entity_decode($data[$name], ENT_QUOTES, "UTF-8"), ENT_QUOTES, "UTF-8");
                 }
                 unset($dataTable->{$name});
                 if (!empty($this->_unique_name[$name])) {
                     $langUniqueKeys[$name] = 1;
                     unset($dataTable->_unique_name[$name]);
                     $langObKeys[$name] = 1;
                     unset($dataTable->_obkeys[$name]);
                 }
                 if (!empty($this->_obkeys[$name])) {
                     $langObKeys[$name] = 1;
                     unset($dataTable->_obkeys[$name]);
                 }
             }
         }
         $langTable->_unique_name = $langUniqueKeys;
         $langTable->_obkeys = $langObKeys;
         $langTable->_slugAutoName = $this->_slugAutoName;
         unset($dataTable->_slugAutoName);
         $langTable->_slugName = 'slug';
         unset($dataTable->_slugName);
         $langTable->setProperties($langData);
         $langTable->_translatable = false;
         //We must check the langtable BEFORE we store the normal table, cause the langtable is often defining if there are enough data to store it (for exmple the name)
         if ($ok) {
             //vmdebug('my langtable before bind',$langTable->id);
             if (!$langTable->bind($data)) {
                 $ok = false;
                 $msg = 'bind';
                 // 			vmdebug('Problem in bind '.get_class($this).' '.$this->_db->getErrorMsg());
                 vmdebug('Problem in bind ' . get_class($this) . ' ');
             }
         }
         if ($ok) {
             if (!$langTable->check()) {
                 $ok = false;
                 vmdebug('Check returned false ' . get_class($langTable) . ' ' . $this->_tbl . ' ' . $langTable->_db->getErrorMsg());
             }
         }
         if ($ok) {
             $dataTable->bindChecknStoreNoLang($data, $preload);
             $this->bind($dataTable);
             $langTable->{$tblKey} = !empty($this->{$tblKey}) ? $this->{$tblKey} : 0;
             //vmdebug('bindChecknStoreNoLang my $tblKey '.$tblKey.' '.$langTable->$tblKey);
             if ($ok and $preload) {
                 if (!empty($langTable->{$tblKey})) {
                     $id = $langTable->{$tblKey};
                     if (!$langTable->load($id)) {
                         $ok = false;
                         vmdebug('Preloading of language table failed, no id given, cannot store ' . $this->_tbl);
                     }
                 } else {
                     if ($ok) {
                         if (!$langTable->bind($data)) {
                             $ok = false;
                             vmdebug('Problem in bind ' . get_class($this) . ' ');
                         }
                     }
                     if ($ok) {
                         if (!$langTable->check()) {
                             $ok = false;
                             vmdebug('Check returned false ' . get_class($langTable) . ' ' . $this->_tbl . ' ' . $langTable->_db->getErrorMsg());
                         }
                     }
                 }
             }
             if ($ok) {
                 if (!$langTable->store()) {
                     $ok = false;
                     // $msg .= ' store';
                     vmdebug('Problem in store with langtable ' . get_class($langTable) . ' with ' . $tblKey . ' = ' . $this->{$tblKey} . ' ' . $langTable->_db->getErrorMsg());
                 } else {
                     $this->bind($langTable);
                 }
             }
         }
     } else {
         if (!$this->bindChecknStoreNoLang($data, $preload)) {
             $ok = false;
         }
     }
     if ($ok) {
         if ($this->_lhash) {
             self::$_cache['l'][$this->_lhash] = $this->loadFieldValues(false);
         }
     }
     return $ok;
 }