Exemplo n.º 1
0
 public function actionImportHoles()
 {
     set_time_limit(0);
     $holes = BHoles::model()->findAll();
     $count = 0;
     foreach ($holes as $hole) {
         //if (1){
         if ($hole->picturenames && isset($hole->picturenames['medium']['fresh']) && count($hole->picturenames['medium']['fresh']) > 0) {
             $model = new Holes('import');
             $model->attributes = $hole->attributes;
             $model->ID = $hole->ID;
             $type = HoleTypes::model()->find('alias = "' . $hole->TYPE . '"');
             $model->TYPE_ID = $type->id;
             if ($model->ADR_SUBJECTRF) {
                 $gibdd = GibddHeads::model()->find('is_regional=1 AND subject_id=' . $model->ADR_SUBJECTRF);
                 if ($gibdd) {
                     $model->gibdd_id = $gibdd->id;
                 } else {
                     $model->gibdd_id = 0;
                 }
             } else {
                 $model->gibdd_id = 0;
             }
             //if ($model->errors) print_r ($model->errors);
             if ($model->STATE == "inprogress") {
                 if (!$model->DATE_SENT) {
                     $model->DATE_SENT = $model->DATE_CREATED;
                 }
                 //echo date('d.m.Y', $model->DATE_SENT).'<br/>';
             }
             if ($model->save()) {
                 //if (0){
                 $count++;
                 foreach ($hole->picturenames['medium']['fresh'] as $i => $src) {
                     $picture = new HolePictures();
                     $picture->type = 'fresh';
                     $picture->filename = $src;
                     $picture->hole_id = $hole->ID;
                     $picture->user_id = $model->USER_ID;
                     $picture->ordering = $i;
                     $picture->save();
                 }
                 foreach ($hole->picturenames['medium']['fixed'] as $i => $src) {
                     $picture = new HolePictures();
                     $picture->type = 'fixed';
                     $picture->filename = $src;
                     $picture->hole_id = $hole->ID;
                     $picture->user_id = $model->USER_ID;
                     $picture->ordering = $i;
                     $picture->save();
                 }
                 if ($model->STATE == "fixed") {
                     $fixmodel = new HoleFixeds();
                     $fixmodel->user_id = $model->USER_ID;
                     $fixmodel->hole_id = $model->ID;
                     $fixmodel->date_fix = $model->DATE_STATUS;
                     $fixmodel->comment = $model->COMMENT2;
                     $fixmodel->save();
                 }
                 if ($model->STATE != "fresh") {
                     if (!$model->DATE_SENT) {
                         $model->DATE_SENT = $model->DATE_CREATED;
                     }
                     $request = new HoleRequests();
                     $request->hole_id = $model->ID;
                     $request->user_id = $model->USER_ID;
                     $request->gibdd_id = $model->gibdd_id;
                     $request->date_sent = $model->DATE_SENT;
                     $request->type = 'gibdd';
                     $request->save();
                     if ($model->GIBDD_REPLY_RECEIVED) {
                         $answer = new HoleAnswers('import');
                         //$answer->attributes=Array('uppload_files'=>Array(123,456));
                         $answer->isimport = true;
                         $answer->request_id = $request->id;
                         $answer->date = $model->DATE_STATUS;
                         $answer->comment = $model->COMMENT_GIBDD_REPLY;
                         if ($answer->save()) {
                             $dir = $_SERVER['DOCUMENT_ROOT'] . $answer->filesFolder;
                             if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/')) {
                                 mkdir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/');
                             }
                             if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/' . $answer->request->hole->ID)) {
                                 mkdir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/' . $answer->request->hole->ID);
                             }
                             if (!is_dir($dir)) {
                                 mkdir($dir);
                             }
                             if (!is_dir($dir . '/thumbs')) {
                                 mkdir($dir . '/thumbs');
                             }
                             foreach ($hole->picturenames['medium']['gibddreply'] as $i => $src) {
                                 $pict = new HoleAnswerFiles();
                                 $pict->file_name = $src;
                                 $pict->file_type = 'image';
                                 $pict->answer_id = $answer->id;
                                 copy($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/original/' . $answer->request->hole->ID . '/' . $src, $dir . '/' . $src);
                                 //unlink ($_SERVER['DOCUMENT_ROOT'].'/upload/st1234/original/'.$src);
                                 copy($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/medium/' . $answer->request->hole->ID . '/' . $src, $dir . '/thumbs/' . $src);
                                 //unlink ($_SERVER['DOCUMENT_ROOT'].'/upload/st1234/medium/'.$src);
                                 $pict->save();
                             }
                         } else {
                             print_r($answer->errors);
                             die;
                         }
                     }
                 }
             }
         }
     }
     echo "Добавлено {$count} ям.";
 }
Exemplo n.º 2
0
 public function BeforeSave()
 {
     parent::beforeSave();
     $this->ADR_CITY = trim($this->ADR_CITY);
     if ($this->scenario == 'fix') {
         $fixmodel = new HoleFixeds();
         $fixmodel->user_id = Yii::app()->user->id;
         $fixmodel->hole_id = $this->ID;
         $fixmodel->date_fix = time();
         $fixmodel->comment = $this->COMMENT2;
         $fixmodel->save();
     }
     return true;
 }
Exemplo n.º 3
0
 public function actionFix($id)
 {
     $this->layout = '//layouts/header_user';
     $model = $this->loadModel($id);
     $fixmodel = new HoleFixeds();
     $fixmodel->user_id = Yii::app()->user->id;
     $fixmodel->hole_id = $model->ID;
     $fixmodel->date_fix = time();
     if (!$model->isUserHole && Yii::app()->user->level < 50) {
         if ($model->STATE == Holes::STATE_FIXED || !$model->requests || !$model->requests_user[0]->answers || $model->user_fix) {
             throw new CHttpException(403, 'Доступ запрещен.');
         }
     } elseif ($model->STATE == Holes::STATE_FIXED && $model->user_fix) {
         throw new CHttpException(403, 'Доступ запрещен.');
     }
     $model->scenario = 'fix';
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile(Yii::app()->request->baseUrl . '/css/add_form.css');
     if (isset($_POST['Holes'])) {
         $model->STATE = Holes::STATE_FIXED;
         $model->COMMENT2 = $_POST['Holes']['COMMENT2'];
         $fixmodel->comment = $model->COMMENT2;
         $model->DATE_STATUS = time();
         $fixmodel->date_fix = strtotime($_POST['fixdate']);
         $tran = $model->dbConnection->beginTransaction();
         if ($model->save() && $model->savePictures() && $fixmodel->save()) {
             $tran->commit();
             $this->redirect(array('view', 'id' => $model->ID));
         }
     }
     $this->render('fix_form', array('model' => $model, 'fixmodel' => $fixmodel, 'newimage' => new PictureFiles()));
 }
Exemplo n.º 4
0
 public function BeforeSave()
 {
     parent::beforeSave();
     $this->DATE_STATUS = time();
     $this->archive = 0;
     $Subs = array('Город' => '', 'город' => '');
     $this->ADR_CITY = trim(strtr($this->ADR_CITY, $Subs));
     if ($this->scenario == 'fix') {
         $fixmodel = new HoleFixeds();
         $fixmodel->user_id = Yii::app()->user->id;
         $fixmodel->hole_id = $this->ID;
         $fixmodel->date_fix = time();
         $fixmodel->comment = $this->COMMENT2;
         $fixmodel->save();
     }
     return true;
 }