public static function getLocations($agentId)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'agent_id=:agentId';
     $criteria->params = array(':agentId' => $agentId);
     $result = UserAgentLocations::model()->findAll($criteria);
     if ($result) {
         return $result;
     } else {
         false;
     }
 }
Example #2
0
 public function actionCreate()
 {
     Yii::beginProfile('agent_create');
     $userId = Yii::app()->user->id;
     $model = AgentProfileApi::getAgentDetails($userId);
     if ($model) {
         $this->redirect('/agent/' . $userId);
     }
     $model = new UserAgentProfile();
     $model_data = UserApi::getUser($userId);
     $propertyType = new UserAgentPropertyType();
     $propertytypes = '';
     $modelState = new GeoState();
     $locationCity = new UserAgentLocations();
     $locations = '';
     $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();
         if (!isset($_POST['property_type_id'])) {
             $propertyType->addError('UserAgentPropertyType', 'Property Type cannot be blank.');
             $valid = false;
         }
         //var_dump($_POST['city_id']);die();
         if (!isset($_POST['city_id'])) {
             $locationCity->addError('city_id', 'City cannot be blank.');
             $valid = false;
         }
         if ($valid) {
             $data = $_POST['UserAgentProfile'];
             $imagePath = ImageUtils::uploadImage($model, 'image');
             if ($imagePath) {
                 $image = AgentProfileApi::addImage($userId, $imagePath);
                 if ($image) {
                     $data['image'] = $image;
                     $agent = AgentProfileApi::createAgentProfile($userId, $data);
                     $propertytypes = UserAgentPropertyTypeApi::createPropertyTypes($agent->id, $_POST['property_type_id']);
                     $locations = UserAgentLocationsApi::createLocations($agent->id, $_POST['city_id']);
                     ImageUtils::deleteImage($imagePath);
                     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 created Agent Profile.');
                         $this->redirect('/agent/' . $userId);
                     }
                 }
             } else {
                 $model->addError('image', 'Image cannot be blank');
             }
         }
     }
     $model->mobile = $model_data['mobile'];
     $model->telephone = $model_data['telephone'];
     $model->email = $model_data['email_id'];
     $this->render('create', array('model' => $model, 'propertyType' => $propertyType, 'propertytypes' => $propertytypes, 'modelState' => $modelState, 'locationCity' => $locationCity, 'locations' => $locations));
     Yii::endProfile('agent_create');
 }