public static function getProjectTypes($builderId)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'builder_id=:builderId';
     $criteria->params = array(':builderId' => $builderId);
     $result = UserBuilderProjectType::model()->findAll($criteria);
     if ($result) {
         return $result;
     } else {
         false;
     }
 }
 public function actionUpdate()
 {
     Yii::beginProfile('builder_update');
     $userId = Yii::app()->user->id;
     $model = BuilderProfileApi::getBuilderDetails($userId);
     if (!$model) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $image = $model->image;
     $projectType = new UserBuilderProjectType();
     $projecttypes = '';
     $modelState = new GeoState();
     $locationCity = new UserBuilderLocations();
     $locations = '';
     $projectTypeIds = UserBuilderProjectTypeApi::getProjectTypes($model->id);
     if ($projectTypeIds) {
         foreach ($projectTypeIds as $types) {
             $projecttypes[] = $types->project_type_id;
         }
     }
     $locationCityIds = UserBuilderLocationsApi::getLocations($model->id);
     if ($locationCityIds) {
         foreach ($locationCityIds as $cities) {
             $locations[] = $cities->city_id;
         }
     }
     $this->performAjaxValidation($model);
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'builder-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['submit'])) {
         $model->attributes = $_POST['UserBuilderProfile'];
         $valid = true;
         $model->user_id = $userId;
         $valid = $valid && $model->validate();
         $builder = "";
         if (!isset($_POST['project_type_id'])) {
             $projectType->addError('UserBuilderProjectType', 'Project Type cannot be blank.');
             $valid = false;
         }
         if (!isset($_POST['city_id'])) {
             $locationCity->addError('city_id', 'City cannot be blank.');
             $valid = false;
         }
         if ($valid) {
             $data = $_POST['UserBuilderProfile'];
             $data['image'] = $image;
             $imagePath = ImageUtils::uploadImage($model, 'image');
             if ($imagePath) {
                 $image = BuilderProfileApi::addImage($userId, $imagePath);
                 if ($image) {
                     $data['image'] = $image;
                     ImageUtils::deleteImage($imagePath);
                 }
             }
             $builder = BuilderProfileApi::updateBuilderProfile($userId, $data);
             UserBuilderProjectTypeApi::deleteProjectTypes($builder->id);
             $projecttypes = UserBuilderProjectTypeApi::createProjectTypes($builder->id, $_POST['project_type_id']);
             UserBuilderLocationsApi::deleteLocations($builder->id);
             $locations = UserBuilderLocationsApi::createLocations($builder->id, $_POST['city_id']);
         }
         if ($builder) {
             $data = array();
             $user = UserApi::getUserById(Yii::app()->user->id);
             $user ? $data["user"] = $user->id : null;
             $data["builder"] = $builder->id;
             EmailApi::sendEmail($user->email_id, "ACTIVITY.BUILDER.CREATE", $data);
             Yii::app()->user->setFlash('success', 'You are Successfully updated Builder Profile.');
             $this->redirect('/builder/' . $userId);
         }
     }
     $this->render('update', array('model' => $model, 'projectType' => $projectType, 'projecttypes' => $projecttypes, 'modelState' => $modelState, 'locationCity' => $locationCity, 'locations' => $locations, 'locationCityIds' => $locationCityIds));
     Yii::endProfile('builder_update');
 }