/** * Address model when edited and saved beforeSave method is called * before saving the changes to database to check if specific address * fields have changed.If the address is changed we set lat/long to * null and invalid flag to false and then saved else saved directly. * in this way we can figure out which address were modified. */ protected function beforeSave() { if (parent::beforeSave()) { $isAddressChanged = false; $addressCheckFields = array('street1', 'street2', 'city', 'state', 'country', 'postalCode'); foreach ($addressCheckFields as $addressField) { if (array_key_exists($addressField, $this->originalAttributeValues)) { if ($this->{$addressField} != $this->originalAttributeValues[$addressField]) { $isAddressChanged = true; break; } } } if ($isAddressChanged) { $this->latitude = null; $this->longitude = null; $this->invalid = false; } return true; } else { return false; } }
/** * Special handling to set 'isNewModel'. This is needed to properly set the jobQueue * //todo: move backwards into OwnedModel if that is ok generally. * @see RedBeanModel::beforeSave() */ protected function beforeSave() { $this->isNewModel = $this->id < 0; return parent::beforeSave(); }
public function beforeSave() { if (!parent::beforeSave()) { return false; } if ($this->id < 0 || isset($this->originalAttributeValues['unsubscribed']) && $this->originalAttributeValues['unsubscribed'] != $this->unsubscribed) { $operation = Autoresponder::OPERATION_SUBSCRIBE; if ($this->unsubscribed) { $operation = Autoresponder::OPERATION_UNSUBSCRIBE; } AutoresponderItem::registerAutoresponderItemsByAutoresponderOperation($operation, $this->marketingList->id, $this->contact); } $this->modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); return true; }