Beispiel #1
0
 public function actionAdd($id = null)
 {
     $user = $this->auth();
     $address = Yii::app()->request->getParam('address');
     if (!$address) {
         $this->error('NO_ADDRESS');
     }
     $latitude = Yii::app()->request->getParam('latitude');
     if (!$latitude) {
         $this->error('LATITUDE_NOT_SET');
     }
     $longitude = Yii::app()->request->getParam('longitude');
     if (!$longitude) {
         $this->error('LONGITUDE_NOT_SET');
     }
     $comment = Yii::app()->request->getParam('comment');
     //	$gibdd_id=Yii::app()->request->getParam('gibdd_id');
     $type = Yii::app()->request->getParam('type');
     if (!$type) {
         $this->error('INCORRECT_TYPE');
     } else {
         $typemodel = HoleTypes::model()->find('alias="' . $type . '"');
         if (!$typemodel) {
             $this->error('INCORRECT_TYPE');
         } elseif (!$typemodel->published) {
             $this->error('DEPRECATED_TYPE');
         }
     }
     //	$addressArr    = RfSubjects::model()->Address($address);
     //	$subject_rf = $addressArr['subject_rf'];
     //		$city       = $addressArr['city'];
     //		$address    = $addressArr['address'];
     /**
      * 		if((!$subject_rf || !$city || !$address) && ($latitude && $longitude)){
      * 				$addressArr    = RfSubjects::model()->AddressfromLatLng($latitude, $longitude, $this->mapkey);
      * 					if ($addressArr) {
      * 						$subject_rf = $addressArr['subject_rf'];
      * 						$city       = $addressArr['city'];
      * 						$address    = $addressArr['address'];	
      * 					}
      * 			}
      */
     /**
      * 		// ворнинги, если надо
      * 		if(!$subject_rf || $subject_rf==0) $this->error('CANNOT_REALISE_SUBJECTRF');
      */
     // if(!$city) $this->error('CANNOT_REALISE_CITY');
     $tags = array();
     $model = new Holes();
     $model->USER_ID = $user->id;
     $model->DATE_CREATED = time();
     //$model->region_id=$subject_rf;
     // $model->ADR_CITY=trim($city);
     $model->ADDRESS = trim($address);
     if ($user->level > 50) {
         $model->PREMODERATED = 1;
     } else {
         $model->PREMODERATED = 0;
     }
     $model->LATITUDE = $latitude;
     $model->LONGITUDE = $longitude;
     $model->TYPE_ID = $typemodel->id;
     $model->COMMENT1 = $comment;
     /**
      * 		if (!$gibdd_id){
      * 			$subjmodel=RfSubjects::model()->findByPk($subject_rf);
      * 			if ($subjmodel) $model->gibdd_id=$subjmodel->gibdd_ru->id;
      * 			else $model->gibdd_id=0;
      * 			}
      * 		else $model->gibdd_id=$gibdd_id;
      */
     if (!$model->upploadedPictures) {
         $this->error('NO_FILES');
     }
     if ($model->countUpploadFiles() > 5) {
         $this->error('TOO_MANY_FILES');
     }
     $model->validate();
     if ($model->getError('upploadedPictures')) {
         $this->getUploadError($model->getError('upploadedPictures'));
     }
     if ($model->save() && $model->savePictures()) {
         $tags[] = CHtml::tag('callresult', array('result' => 1, 'inserteddefectid' => $model->ID), 'ok', true);
     } else {
         $this->error('CANNOT_ADD_DEFECT');
     }
     $this->renderXml($tags);
 }