public static function getPropertyTypes($agentId) { $criteria = new CDbCriteria(); $criteria->condition = 'agent_id=:agentId'; $criteria->params = array(':agentId' => $agentId); $result = UserAgentPropertyType::model()->findAll($criteria); if ($result) { return $result; } else { false; } }
public function actionUpdate() { Yii::beginProfile('agent_update'); $userId = Yii::app()->user->id; $model = AgentProfileApi::getAgentDetails($userId); if (!$model) { throw new CHttpException(404, 'The requested page does not exist.'); } $image = $model->image; $propertyType = new UserAgentPropertyType(); $propertytypes = ''; $modelState = new GeoState(); $locationCity = new UserAgentLocations(); $locations = ''; $propertyTypeIds = UserAgentPropertyTypeApi::getPropertyTypes($model->id); if ($propertyTypeIds) { foreach ($propertyTypeIds as $types) { $propertytypes[] = $types->property_type_id; } } $locationCityIds = UserAgentLocationsApi::getLocations($model->id); $this->performAjaxValidation($model); if (isset($_POST['ajax']) && $_POST['ajax'] == 'agent-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['submit'])) { $model->attributes = $_POST['UserAgentProfile']; $valid = true; $model->user_id = $userId; $valid = $valid && $model->validate(); $agent = ""; if (!isset($_POST['property_type_id'])) { $propertyType->addError('property_type_id', 'Property Type cannot be blank.'); $valid = false; } if ($valid) { $data = $_POST['UserAgentProfile']; $data['image'] = $image; $imagePath = ImageUtils::uploadImage($model, 'image'); if ($imagePath) { $image = AgentProfileApi::addImage($userId, $imagePath); if ($image) { $data['image'] = $image; ImageUtils::deleteImage($imagePath); } } $agent = AgentProfileApi::updateAgentProfile($userId, $data); UserAgentPropertyTypeApi::deletePropertyTypes($agent->id); $propertytypes = UserAgentPropertyTypeApi::createPropertyTypes($agent->id, $_POST['property_type_id']); UserAgentLocationsApi::deleteLocations($agent->id); $locations = UserAgentLocationsApi::createLocations($agent->id, $_POST['city_id']); } if ($agent) { $data = array(); $user = UserApi::getUserById(Yii::app()->user->id); $user ? $data["user"] = $user->id : null; $data["agent"] = $agent->id; EmailApi::sendEmail($user->email_id, "ACTIVITY.AGENT.CREATE", $data); Yii::app()->user->setFlash('success', 'You are Successfully updated Agent Profile.'); $this->redirect('/agent/' . $userId); } } $this->render('update', array('model' => $model, 'propertyType' => $propertyType, 'propertytypes' => $propertytypes, 'modelState' => $modelState, 'locationCity' => $locationCity, 'locations' => $locations, 'locationCityIds' => $locationCityIds)); Yii::endProfile('agent_update'); }