_data['password'])) { unset($this->_data['password']); } else { $this->_data['passwordTitle'] = $this->_data['password']; $this->_data['salt'] = substr(md5(time()), 0, 8); $this->_data['password'] = $this->_encryptPass($this->_data['password'], $this->_data['salt']); } return $this; } protected function _addDependenciesFromDb(array &$data) { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias . 'Address')); $select->where('`userId` = ?', $data['id'], Qs_Db::INT_TYPE); $addresses = $this->_db->fetchAll($select); foreach ($addresses as $address) { if (false !== strpos($address['type'], static::ADDRESS_BILLING)) { $types = explode(',', $address['type']); foreach ($types as $type) { if ($type == static::ADDRESS_BILLING) { $data[$type] = $address; if (empty($data[$type]['email'])) { $data[$type]['email'] = $data['email']; } if (empty($data[$type]['phone'])) { $data[$type]['phone'] = $data['phone']; } } else { $data[$type]['asBilling'] = 'y'; } } } else { $data[$address['type']] = $address; } } return $this; } protected function _insertDependency() { $billingAddress = array(); foreach ($this->getAddressTypes() as $type) { if (empty($this->_data[$type])) { continue; } $address = $this->_data[$type]; $address['userId'] = $this->getPrimaryKey(); if (static::ADDRESS_BILLING == $type) { $billingAddress = $address; $billingAddress['type'][] = $type; } else { if ('y' == $address['asBilling']) { $billingAddress['type'][] = $type; } else { $address['type'] = $type; $this->_getTable($this->_tableAlias . 'Address')->insert($address); } } } if (!empty($billingAddress)) { $billingAddress['type'] = implode(',', $billingAddress['type']); $this->_getTable($this->_tableAlias . 'Address')->insert($billingAddress); } return $this; } protected function _updateDependency() { $this->_deleteDependency(); $this->_insertDependency(); return $this; } protected function _deleteDependency() { $userId = $this->_db->quote($this->getPrimaryKey(), Qs_Db::INT_TYPE); $this->_getTable($this->_tableAlias . 'Address')->delete('`userId` = ' . $userId); return $this; } public function getAddressTypes() { if (null === $this->_addressTypes) { $tableData = $this->_getTable($this->_tableAlias . 'Address')->getMetaData(); $types = $tableData['type']['DATA_TYPE']; if (false === stripos($types, 'set(')) { throw new Qs_Db_Obj_Exception('Unknown type of address type column'); } $types = substr($types, 4, -1); $types = explode(',', $types); array_walk($types, function (&$item, $key) { $item = trim($item, "' "); }); if (empty($types)) { throw new Qs_Db_Obj_Exception('Wrong format of address type column'); } $types = array_filter($types); $types = array_merge($types); if (!in_array(static::ADDRESS_BILLING, $types)) { throw new Qs_Db_Obj_Exception('"billing" type is required for address type column'); } $billingIndex = array_search(static::ADDRESS_BILLING, $types); if (0 !== $billingIndex) { unset($types[$billingIndex]); array_unshift($types, static::ADDRESS_BILLING); } $this->_addressTypes = $types; } return $this->_addressTypes; } public function getObjectInfo() { $data = (array) $this->getData(); if (!empty($data)) { $data['itemTitle'] = $data['login']; } return $data; } }