예제 #1
0
 /**
  *
  */
 public function editAttribute($pa_values, $pa_options = null)
 {
     if (!$this->getPrimaryKey()) {
         return null;
     }
     $vb_already_in_transaction = $this->inTransaction();
     if (!$vb_already_in_transaction) {
         $o_trans = new Transaction();
         $this->setTransaction($o_trans);
     } else {
         $o_trans = $this->getTransaction();
     }
     unset(ca_attributes::$s_get_attributes_cache[$this->get('table_num') . '/' . $this->get('row_id')]);
     $this->setMode(ACCESS_WRITE);
     $this->set('locale_id', $pa_values['locale_id']);
     $this->update();
     if ($this->numErrors()) {
         if (!$vb_already_in_transaction) {
             $o_trans->rollback();
         }
         $vs_errors = join('; ', $this->getErrors());
         $this->clearErrors();
         $this->postError(1971, $vs_errors, 'ca_attributes->editAttribute()');
         return false;
     }
     $t_attr_val = new ca_attribute_values();
     $t_attr_val->purify($this->purify());
     $t_attr_val->setTransaction($o_trans);
     $t_attr_val->setMode(ACCESS_WRITE);
     $t_element = ca_attributes::getElementInstance($this->get('element_id'));
     $va_elements = $t_element->getElementsInSet();
     $va_attr_vals = $this->getAttributeValues();
     foreach ($va_attr_vals as $o_attr_val) {
         $vn_element_id = intval($o_attr_val->getElementID());
         if ($t_attr_val->load($o_attr_val->getValueID())) {
             if (isset($pa_values[$vn_element_id])) {
                 $vm_value = $pa_values[$vn_element_id];
             } else {
                 $vm_value = $pa_values[$o_attr_val->getElementCode()];
             }
             if ($t_attr_val->editValue($vm_value, $pa_options) === false) {
                 $this->postError(1973, join('; ', $t_attr_val->getErrors()), 'ca_attributes->editAttribute()');
             }
             foreach ($va_elements as $vn_i => $va_element_info) {
                 if ($va_element_info['element_id'] == $vn_element_id) {
                     unset($va_elements[$vn_i]);
                 }
             }
         }
     }
     $vn_attribute_id = $this->getPrimaryKey();
     // Add values that don't already exist (added after the fact?)
     foreach ($va_elements as $vn_index => $va_element) {
         if ($va_element['datatype'] == 0) {
             continue;
         }
         // skip containers
         $vn_element_id = $va_element['element_id'];
         if (isset($pa_values[$vn_element_id])) {
             $vm_value = $pa_values[$vn_element_id];
         } else {
             $vm_value = $pa_values[$va_element['element_code']];
         }
         if ($t_attr_val->addValue($vm_value, $va_element, $vn_attribute_id, $pa_options) === false) {
             $this->postError(1972, join('; ', $t_attr_val->getErrors()), 'ca_attributes->editAttribute()');
             break;
         }
     }
     if ($this->numErrors()) {
         if (!$vb_already_in_transaction) {
             $o_trans->rollback();
         }
         return false;
     }
     if (!$vb_already_in_transaction) {
         $o_trans->commit();
     }
     return true;
 }