public function updateUser(User $user) { $updateArray = array('username' => $user->getUsername() ?: null, 'role' => $user->getRole() ?: null, 'salt' => $user->getSalt() ?: null, 'password' => $user->getPassword() ?: null, 'fullName' => $user->getFullName() ?: null, 'gender' => $user->getGender() ?: null, 'birthdate' => $user->getBirthdate() ?: null, 'email' => $user->getEmail() ?: null, 'mobile' => $user->getMobile() ?: null, 'cityId' => (int) $user->getCityId() ?: null, 'districtId' => (int) $user->getDistrictId() ?: null, 'address' => $user->getAddress() ?: null, 'rememberMe' => $user->getRememberMe() ?: null, 'lastAccess' => $user->getLastAccess() ?: null, 'activeKey' => $user->getActiveKey() ?: null, 'resetKey' => $user->getResetKey() ?: null, 'active' => $user->getActive(), 'registeredDate' => $user->getRegisteredDate() ?: null, 'facebook' => $user->getFacebook() ?: null, 'description' => $user->getDescription() ?: null, 'locked' => $user->getLocked() ?: null); $updateArray = array_filter($updateArray, 'strlen'); $updateArray = array_filter($updateArray); $update = $this->getDbSql()->update(self::TABLE_NAME); if ($user->getId()) { $update->where(array('id' => $user->getId())); } $update->set($updateArray); $query = $this->getDbSql()->buildSqlString($update); $result = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); return $result; }
/** * @param \User\Model\User $user * @return true|false */ public function save($user) { $data = array('role' => $user->getRole(), 'username' => $user->getUsername() ?: null, 'email' => $user->getEmail() ?: null, 'password' => $user->getPassword() ?: null, 'salt' => $user->getSalt() ?: null, 'fullName' => $user->getFullName() ?: null, 'avatar' => $user->getAvatar() ?: null, 'gender' => $user->getGender() ?: null, 'birthdate' => $user->getBirthdate() ?: null, 'cityId' => $user->getCityId() ?: null, 'districtId' => $user->getDistrictId() ?: null, 'address' => $user->getAddress() ?: null, 'mobile' => $user->getMobile() ?: null, 'lastAccess' => $user->getLastAccess() ?: null, 'active' => $user->getActive() ?: null, 'activeKey' => $user->getActiveKey() ?: null, 'createdById' => $user->getCreatedById() ?: null, 'createdDate' => $user->getCreatedDate(), 'createdDateTime' => $user->getCreatedDateTime(), 'description' => $user->getDescription() ?: null, 'rate' => $user->getRate() ?: null, 'rating' => $user->getRating() ?: null, 'facebook' => $user->getFacebook() ?: null); $results = false; if (!($id = $user->getId())) { $insert = $this->getDbSql()->insert(self::TABLE_NAME); $insert->values($data); $query = $this->getDbSql()->buildSqlString($insert); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); $user->setId($results->getGeneratedValue()); } else { $update = $this->getDbSql()->update(self::TABLE_NAME); $update->set($data); $update->where(array("id" => (int) $user->getId())); $query = $this->getDbSql()->buildSqlString($update); $results = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE); } return $results; }