コード例 #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;
     if ($this->_translatable) {
         if (!class_exists('VmTableData')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'vmtabledata.php';
         }
         $db = JFactory::getDBO();
         $langTable = new VmTableData($this->_tbl_lang, $tblKey, $db);
         $langTable->setPrimaryKey($tblKey);
         $langData = array();
         $langObKeys = array();
         $langUniqueKeys = array();
         if (is_object($data)) {
             foreach ($this->_translatableFields as $name) {
                 if (!empty($data->{$name})) {
                     $langData[$name] = $data->{$name};
                 } else {
                     $langData[$name] = '';
                 }
                 unset($this->{$name});
                 if (!empty($this->_unique_name[$name])) {
                     $langUniqueKeys[$name] = JText::sprintf('COM_VIRTUEMART_STRING_ERROR_NOT_UNIQUE_NAME', JText::_('COM_VIRTUEMART_' . strtoupper($name)));
                     unset($this->_unique_name[$name]);
                     $langObKeys[$name] = JText::sprintf('COM_VIRTUEMART_STRING_ERROR_OBLIGATORY_KEY', JText::_('COM_VIRTUEMART_' . strtoupper($name)));
                     unset($this->_obkeys[$name]);
                 }
                 if (!empty($this->_obkeys[$name])) {
                     $langObKeys[$name] = JText::sprintf('COM_VIRTUEMART_STRING_ERROR_OBLIGATORY_KEY', JText::_('COM_VIRTUEMART_' . strtoupper($name)));
                     unset($this->_obkeys[$name]);
                 }
             }
             // 				$langTable->$tblKey = $data->$tblKey;
         } else {
             foreach ($this->_translatableFields as $name) {
                 if (!empty($data[$name])) {
                     $langData[$name] = $data[$name];
                 } else {
                     $langData[$name] = '';
                 }
                 unset($this->{$name});
                 if (!empty($this->_unique_name[$name])) {
                     $langUniqueKeys[$name] = JText::sprintf('COM_VIRTUEMART_STRING_ERROR_NOT_UNIQUE_NAME', JText::_('COM_VIRTUEMART_' . strtoupper($name)));
                     unset($this->_unique_name[$name]);
                     $langObKeys[$name] = JText::sprintf('COM_VIRTUEMART_STRING_ERROR_OBLIGATORY_KEY', JText::_('COM_VIRTUEMART_' . strtoupper($name)));
                     unset($this->_obkeys[$name]);
                 }
                 if (!empty($this->_obkeys[$name])) {
                     $langObKeys[$name] = JText::sprintf('COM_VIRTUEMART_STRING_ERROR_OBLIGATORY_KEY', JText::_('COM_VIRTUEMART_' . strtoupper($name)));
                     unset($this->_obkeys[$name]);
                 }
             }
             // 				$langTable->$tblKey = $data[$tblKey];
         }
         $langTable->_unique_name = $langUniqueKeys;
         $langTable->_obkeys = $langObKeys;
         $langTable->_slugAutoName = $this->_slugAutoName;
         unset($this->_slugAutoName);
         $langTable->_slugName = 'slug';
         unset($this->_slugName);
         $langTable->setProperties($langData);
         $langTable->_translatable = false;
         // 			$dataLang = $data;
         // 			vmdebug('my $dataLang',$langTable,$data);
         // 			vmdebug('my $table $this',$this);
         $this->bindChecknStoreNoLang($data, $preload);
         // 			vmdebug('bindchecknstore',$langData,$this);
         $langTable->{$tblKey} = !empty($this->{$tblKey}) ? $this->{$tblKey} : 0;
         $ok = true;
         if ($preload) {
             if ($ok) {
                 if (!empty($langTable->{$tblKey})) {
                     $id = $langTable->{$tblKey};
                     if (!$langTable->load($id)) {
                         $ok = false;
                     } else {
                         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;
                 // $msg .= ' check';
                 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 ' . get_class($langTable) . ' ' . $langTable->_db->getErrorMsg());
             } else {
                 vmdebug('stored product_name ' . $langTable->product_name);
             }
         }
     } else {
         $this->bindChecknStoreNoLang($data, $preload);
     }
     return true;
 }