public function actionGibddreply($id = null, $holes = null) { $this->layout = '//layouts/header_user'; $count = 0; $firstAnswermodel = array(); $models = array(); if (!$holes) { $model = $this->loadModel($id); $model->scenario = 'gibdd_reply'; if (!$model->request_gibdd) { throw new CHttpException(403, 'Доступ запрещен.'); } $models[] = $model; } else { $models = Holes::model()->findAllByPk(explode(',', $holes)); } foreach ($models as $i => $model) { if (!$model->request_gibdd) { unset($models[$i]); continue; } $answer = new HoleAnswers(); if (isset($_GET['answer']) && $_GET['answer']) { $answer = HoleAnswers::model()->findByPk((int) $_GET['answer']); } $answer->request_id = $model->request_gibdd->id; if (isset($_POST['HoleAnswers'])) { $answer->attributes = $_POST['HoleAnswers']; //if (isset($_POST['HoleAnswers']['results'])) $answer->results=$_POST['HoleAnswers']['results']; $answer->request_id = $model->request_gibdd->id; if (!$answer->date) { $answer->date = time(); } if ($firstAnswermodel) { $answer->firstAnswermodel = $firstAnswermodel; } if ($answer->save()) { if ($model->STATE == "inprogress" || $model->STATE == "achtung") { $model->STATE = 'gibddre'; } $model->GIBDD_REPLY_RECEIVED = 1; $model->DATE_STATUS = time(); if ($model->update()) { if ($count == 0) { $firstAnswermodel = $answer; } $count++; $links[] = CHtml::link($model->ADDRESS, array('view', 'id' => $model->ID)); if (!$holes) { $this->redirect(array('view', 'id' => $model->ID)); } } } } else { if (!$answer->isNewRecord) { $answer->results = CHtml::listData($answer->results, 'id', 'id'); } } } if ($holes && $count) { if ($count) { Yii::app()->user->setFlash('user', 'Успешная загрузка ответа ГИБДД на ямы: <br/>' . implode('<br/>', $links) . '<br/><br/><br/>'); } else { Yii::app()->user->setFlash('user', 'Произошла ошибка! Ни одного ответа не загружено'); } $this->redirect(array('personal')); } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $cs = Yii::app()->getClientScript(); $cs->registerCssFile('/css/add_form.css'); $cs->registerScriptFile('http://api-maps.yandex.ru/1.1/index.xml?key=' . $this->mapkey); $this->flushUploadDir(); $this->render('gibddreply', array('models' => $models, 'answer' => $answer, 'jsplacemarks' => '')); }
public function getAllAnswers() { return HoleAnswers::model()->with('request')->findAll(array('condition' => 'request.hole_id=' . $this->ID . ' AND request.id=t.request_id', 'order' => 't.date ASC')); }