/**
  * Ajax photoreloader
  * @param integer $id
  */
 public function actionReloadphoto($id)
 {
     try {
         $temp_dir = sys_get_temp_dir();
         $model = $this->loadModel($id);
         //$model = new Person;
         //$model->scenario = "PHOTO";
         $edbeo_file = WebServices::getPersonPhotoByCodeU($model->codeU);
         if (!empty($edbeo_file)) {
             $oldPhoto = $model->PhotoName;
             $tfio = Transliteration::translit2010($model->FirstName) . "_" . Transliteration::translit2010($model->LastName) . "_" . Transliteration::translit2010($model->MiddleName);
             $model->PhotoName = "person_{$id}" . "_{$tfio}.jpg";
             $path = Yii::app()->basePath . "/.." . Yii::app()->params['photosPath'];
             $bigpath = Yii::app()->basePath . "/.." . Yii::app()->params['photosBigPath'];
             $img = EWideImage::loadFromString(base64_decode($edbeo_file));
             if ($img->getWidth() < $img->getHeight()) {
                 $img->resize(120, null)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg");
                 $img->resize(180, null)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg");
             } else {
                 $img->resize(null, 150)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg");
                 $img->resize(null, 225)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg");
             }
             if ($model->save()) {
                 //PC::debug($model->PhotoName);
             } else {
                 //PC::debug(print_r($model->getErrors()));
             }
             echo CJSON::encode(array("result" => "SUCCESS", "data" => Yii::app()->request->baseUrl . Yii::app()->params['photosPath'] . $model->PhotoName));
         } else {
             echo CJSON::encode(array("result" => "ERROR", "data" => "Фото відсутнє!"));
         }
     } catch (Exception $e) {
         if (defined('YII_DEBUG')) {
             Yii::log($e->getMessage(), CLogger::LEVEL_INFO, 'actionReloadphoto');
         }
         echo CJSON::encode(array("result" => "ERROR", "data" => $e->getMessage()));
     }
 }
예제 #2
0
 protected function beforeSave()
 {
     unset($this->CreateDate);
     if ($this->KOATUUCodeL1ID == "0") {
         $this->KOATUUCodeL1ID = NULL;
     }
     if ($this->KOATUUCodeL2ID == "0") {
         $this->KOATUUCodeL2ID = NULL;
     }
     if ($this->KOATUUCodeL3ID == "0") {
         $this->KOATUUCodeL3ID = NULL;
     }
     if ($this->SchoolID == "0") {
         $this->SchoolID = NULL;
     }
     // $from=DateTime::createFromFormat('d.m.Y',$this->Birthday);
     $this->Birthday = date('Y-m-d', strtotime($this->Birthday));
     if (!empty($this->koatu)) {
         $koatu = explode(";", $this->koatu);
         $this->KOATUUCodeID = $koatu[0];
         $this->KOATUUCode = $koatu[1];
     }
     $kk = KoatuuLevel3::model()->findByPk($this->KOATUUCodeID);
     if (!empty($kk)) {
         //$kk = new KoatuuLevel3();
         // Yii::log($this->KOATUUCodeID);
         $this->KOATUUCodeL3ID = $this->KOATUUCodeID;
         $kk2 = KoatuuLevel2::model()->findByPk($kk->KOATUULevel2ID);
         $this->KOATUUCodeL2ID = $kk->KOATUULevel2ID;
         $this->KOATUUCodeL1ID = $kk2->KOATUULevel1ID;
     } else {
         $kk = KoatuuLevel2::model()->findByPk($this->KOATUUCodeID);
         if (!empty($kk)) {
             ///Yii::log($this->KOATUUCodeID);
             $this->KOATUUCodeL2ID = $this->KOATUUCodeID;
             $this->KOATUUCodeL1ID = $kk->KOATUULevel1ID;
         } else {
             Yii::log($this->KOATUUCodeID);
             $kk = KoatuuLevel3::model()->findByPk($this->KOATUUCodeID);
             if (!empty($kk)) {
                 $this->KOATUUCodeL1ID = $this->KOATUUCodeID;
             }
         }
     }
     if (empty($this->LastNameEn)) {
         $this->LastNameEn = Transliteration::translit2010($this->LastName);
     }
     if (empty($this->MiddleNameEn)) {
         $this->MiddleNameEn = Transliteration::translit2010($this->MiddleName);
     }
     if (empty($this->FirstNameEn)) {
         $this->FirstNameEn = Transliteration::translit2010($this->FirstName);
     }
     if (!Yii::app()->user->checkAccess("editResident")) {
         if ($this->CountryID != 804) {
             $this->IsResident = 0;
         } else {
             $this->IsResident = 1;
         }
     }
     if ($this->edboID == 0) {
         $this->edboID = "";
     }
     parent::beforeSave();
     return true;
 }