/** * Perform actions after object save * * @param AbstractModel $object * @param string $attribute * @return $this * @throws \Exception */ public function saveAttribute(AbstractModel $object, $attribute) { if ($attribute instanceof AbstractAttribute) { $attributes = $attribute->getAttributeCode(); } elseif (is_string($attribute)) { $attributes = [$attribute]; } else { $attributes = $attribute; } if (is_array($attributes) && !empty($attributes)) { $this->getConnection()->beginTransaction(); $data = array_intersect_key($object->getData(), array_flip($attributes)); try { $this->_beforeSaveAttribute($object, $attributes); if ($object->getId() && !empty($data)) { $this->getConnection()->update($object->getResource()->getMainTable(), $data, [$object->getResource()->getIdFieldName() . '= ?' => (int) $object->getId()]); $object->addData($data); } $this->_afterSaveAttribute($object, $attributes); $this->getConnection()->commit(); } catch (\Exception $e) { $this->getConnection()->rollBack(); throw $e; } } return $this; }
/** * Retrieve data * * @param string $key * @param mixed $index * @return mixed */ public function getData($key = '', $index = null) { if ('cc_number' === $key) { $ccNumber = parent::getData('cc_number'); $ccNumberEnc = parent::getData('cc_number_enc'); if (empty($ccNumber) && !empty($ccNumberEnc)) { $this->setData('cc_number', $this->decrypt($ccNumberEnc)); } } if ('cc_cid' === $key) { $ccCid = parent::getData('cc_cid'); $ccCidEnc = parent::getData('cc_cid_enc'); if (empty($ccCid) && !empty($ccCidEnc)) { $this->setData('cc_cid', $this->decrypt($ccCidEnc)); } } return parent::getData($key, $index); }
/** * @param string $key * @param null|string|int $index * @return mixed */ public function getData($key = '', $index = null) { if ($key == 'total_due') { return $this->getTotalDue(); } if ($key == 'base_total_due') { return $this->getBaseTotalDue(); } return parent::getData($key, $index); }