phone_number = $data['phone_number']; $this->profiles = $data['profiles']; $this->iso_country_code = $data['iso_country_code']; $this->calling_country_code = $data['calling_country_code']; $this->national_format = $data['national_format']; $this->invalid = $data['invalid']; $this->validation_errors = $data['validation_error']; $this->carrier_name = $data['carrier_name']; $this->type = $data['type']; $this->alert_list = $data['alert_list']; if ($this->invalid || $this->validation_errors !== null) { throw new \Exception('Validation failed'); } } public function prepareUpdate(): array { $params = $this->queryParams(); unset($params[':phone_number']); $params[':validation_errors'] = json_encode($params[':validation_errors']); // if new alert_list is null -- don't override if ($params[':alert_list'] === null) { unset($params[':alert_list']); } $placeholders = array_keys($params); $updateString = $this->updateStringByPlaceholders($placeholders); return [$params, $updateString]; } public function updateEntityInDb(int $entityId, int $apiKey): void { $this->country_code = 0; if ($this->iso_country_code !== null) { $countryModel = new \Models\Country(); $this->country_code = $countryModel->getCountryIdByIso($this->iso_country_code); } [$params, $updateString] = $this->prepareUpdate(); $params['entity_id'] = $entityId; $params['key'] = $apiKey; $query = (" UPDATE event_phone SET {$updateString} WHERE event_phone.id = :entity_id AND event_phone.key = :key "); $model = new \Models\Phone(); $model->execQuery($query, $params); } }