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} ям."; }
</div> </div> <!-- CLOSE HEAD CONTAINER --> </div> <!-- CLOSE HEAD --> </div> <div class="mainCols" id="col"> <div class="lCol"> <div id="holes_select_list"> <?php $selected = $user->getState('selectedHoles', array()); if ($selected || $user->userModel->selected_holes_lists) { ?> <?php $this->renderPartial('_selected', array('gibdds' => $selected ? GibddHeads::model()->with('holes')->findAll('holes.id IN (' . implode(',', $selected) . ')') : array(), 'user' => $user->userModel)); ?> <?php } ?> </div> </div> <div class="rCol"> <div class="pdf_form" id="pdf_form" style="display: none; left:auto;"> <a href="#" onclick="var c=document.getElementById('pdf_form');if(c){c.style.display=c.style.display=='block'?'none':'block';}return false;" class="close">×</a> <div id="gibdd_form"></div> </div> <p> <?php
public function actionSelected($id) { //$this->layout='//layouts/header_user'; $user = Yii::app()->user; $list = UserSelectedLists::model()->findByPk((int) $id); if (!$list || $list->user_id != $user->id) { throw new CHttpException(403, 'Доступ запрещен.'); } if (isset($_POST['gibdd_change_id']) && $_POST['gibdd_change_id']) { $newgibdd = GibddHeads::model()->findByPk((int) $_POST['gibdd_change_id']); if ($newgibdd && $newgibdd->subject_id == $list->gibdd->subject_id) { foreach ($list->holes as $hole) { $hole->gibdd_id = $newgibdd->id; $hole->update(); } $list->gibdd_id = $newgibdd->id; $list->update(); $this->refresh(); } } $model = new Holes('search'); $model->unsetAttributes(); $model->showUserHoles = 3; if (isset($_POST['Holes']) || isset($_GET['Holes'])) { $model->attributes = isset($_POST['Holes']) ? $_POST['Holes'] : $_GET['Holes']; } $model->selecledList = $list->id; $cs = Yii::app()->getClientScript(); $cs->registerCssFile('/css/holes_list.css'); $cs->registerCssFile('/css/hole_view.css'); $cs->registerScriptFile(CHtml::asset($this->viewPath . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'holes_selector.js')); $cs->registerScriptFile('http://www.vertstudios.com/vertlib.min.js'); $cs->registerScriptFile(CHtml::asset($this->viewPath . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'StickyScroller' . DIRECTORY_SEPARATOR . 'StickyScroller.min.js')); $cs->registerScriptFile(CHtml::asset($this->viewPath . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'StickyScroller' . DIRECTORY_SEPARATOR . 'GetSet.js')); $holes = array(); $all_holes_count = 0; $this->render('selected', array('model' => $model, 'list' => $list, 'user' => Yii::app()->user)); //print_r(Yii::app()->user->getState('selectedHoles')); }
?> </div> </div> </div> <div class="clear"></div> <?php echo $form->dropDownList($model, 'showUserHoles', array(1 => 'Мои ямы', 2 => 'Чужие, на которые я отправил заявление'), array('prompt' => 'Все ямы')); ?> <?php if ($model->keys) { echo $form->dropDownList($model, 'gibdd_id', CHtml::listData(GibddHeads::model()->with(array('holes' => array('select' => 'ID, gibdd_id')))->findAll(array('condition' => 'holes.ID IN (' . implode(', ', $model->keys) . ')', 'order' => 't.name')), 'id', 'gibdd_name'), array('prompt' => 'Все ГИБДД')); } ?> <?php echo CHtml::submitButton('Найти'); ?> <br/> <div class="clear"></div><br /> <div style="text-align:right;"> <?php echo CHtml::checkBox('selectAll', false, array('id' => 'selectAll', 'class' => 'state_check')); echo CHtml::label('Выбрать все', 'selectAll'); ?> </div> <?php $this->endWidget();
public function loadGibddModel($id) { $model = GibddHeads::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionSelectHoles($del = false) { $gibdds = array(); $del = filter_var($del, FILTER_VALIDATE_BOOLEAN); if (isset($_POST['holes'])) { $holestr = $_POST['holes']; } else { $holestr = ''; } if ($holestr == 'all' && $del) { Yii::app()->user->setState('selectedHoles', array()); //Yii::app()->end(); } else { $holes = explode(',', $holestr); for ($i = 0; $i < count($holes); $i++) { $holes[$i] = (int) $holes[$i]; if (!$holes[$i]) { unset($holes[$i]); } } $selected = Yii::app()->user->getState('selectedHoles', array()); if (!$del) { $newsel = array_diff($holes, $selected); $selected = array_merge($selected, $newsel); } else { $newsel = array_intersect($selected, $holes); foreach ($newsel as $key => $val) { unset($selected[$key]); } } Yii::app()->user->setState('selectedHoles', $selected); if ($selected) { $gibdds = GibddHeads::model()->with('holes')->findAll('holes.id IN (' . implode(',', $selected) . ')'); } } $this->renderPartial('_selected', array('gibdds' => $gibdds, 'user' => Yii::app()->user->userModel)); //print_r(Yii::app()->user->getState('selectedHoles')); }
public function getTerritorialGibdd() { if (!$this->subject) { return array(); } $longitude = $this->LONGITUDE; $latitude = $this->LATITUDE; $numerator = 'POW(COS(RADIANS(lat)) * SIN(ABS(RADIANS(' . $longitude . ')-RADIANS(lng))),2)'; $numerator .= ' + POW( COS(RADIANS(' . $latitude . ')) * SIN(RADIANS(lat)) - SIN(RADIANS(' . $latitude . ')) * COS(RADIANS(lat))*COS(ABS(RADIANS(' . $longitude . ')-RADIANS(lng))) ,2)'; $numerator = 'SQRT(' . $numerator . ')'; $denominator = 'SIN(RADIANS(lat))*SIN(RADIANS(' . $latitude . ')) + COS(RADIANS(lat))*COS(RADIANS(' . $latitude . '))* COS(ABS(RADIANS(' . $longitude . ')-RADIANS(lng)))'; $condition = 'ATAN(' . $numerator . '/(' . $denominator . ')) * ' . self::EARTH_RADIUS_KM; $criteria = new CDbCriteria(); $criteria->select = array('*', $condition . ' as distance'); $criteria->condition = 'lat > 0 AND lng > 0'; $criteria->addCondition('moderated = 1 OR author_id=' . Yii::app()->user->id); if ($this->subject) { $criteria->addCondition('subject_id=' . $this->subject->id); } $criteria->order = 'ABS(distance) ASC'; $criteria->having = 'ABS(distance) < 1000'; $criteria->limit = 5; $gibdds = GibddHeads::model()->findAll($criteria); if ($this->subject) { array_unshift($gibdds, $this->subject->gibdd); } return $gibdds; }
public function actionSaveHoles2Selected($id, $holes) { if ($id) { $gibdd = GibddHeads::model()->findByPk((int) $id); $holemodel = Holes::model()->findAllByPk(explode(',', $holes)); if ($gibdd && $holemodel) { $model = new UserSelectedLists(); $model->user_id = Yii::app()->user->id; $model->gibdd_id = $gibdd->id; $model->date_created = time(); $model->holes = $holemodel; $model->save(); } } $p = Yii::app()->createController('holes'); $p[0]->actionSelectHoles(false); }
public function getTerritorialGibdd() { //if (!$this->subject) return Array(); $longitude = $this->LONGITUDE; $latitude = $this->LATITUDE; /* $numerator = 'POW(COS(RADIANS(lat)) * SIN(ABS(RADIANS('.$longitude.')-RADIANS(lng))),2)'; $numerator .= ' + POW( COS(RADIANS('.$latitude.')) * SIN(RADIANS(lat)) - SIN(RADIANS('.$latitude.')) * COS(RADIANS(lat))*COS(ABS(RADIANS('.$longitude.')-RADIANS(lng))) ,2)'; $numerator = 'SQRT('.$numerator.')'; $denominator = 'SIN(RADIANS(lat))*SIN(RADIANS('.$latitude.')) + COS(RADIANS(lat))*COS(RADIANS('.$latitude.'))* COS(ABS(RADIANS('.$longitude.')-RADIANS(lng)))'; $condition = 'ATAN('.$numerator.'/('.$denominator.')) * '.self::EARTH_RADIUS_KM; $criteria=new CDbCriteria; $criteria->select=Array('*', $condition.' as distance'); $criteria->condition='lat > 0 AND lng > 0'; $criteria->addCondition('moderated = 1 OR author_id='.Yii::app()->user->id); if ($this->subject) $criteria->addCondition('subject_id='.$this->subject->id); $criteria->order='ABS(distance) ASC'; $criteria->having='ABS(distance) < 1000'; $criteria->limit=5; $gibdds=GibddHeads::model()->findAll($criteria); if ($this->subject) array_unshift ($gibdds, $this->subject->gibdd);*/ $gibdds = GibddHeads::model()->with('areas')->findAll(array('order' => 't.level DESC, t.subject_id DESC')); $regionalGibdds = array(); $regkey = 0; foreach ($gibdds as $i => $gibdd) { $inpolyg = false; foreach ($gibdd->areas as $area) { $inpolyg = $this->inPolygon($area, $this, 'points'); if ($inpolyg) { break; } } if (!$inpolyg) { unset($gibdds[$i]); } else { if ($gibdd->level == 1) { $regionalGibdds[$i] = $gibdd; $regkey = $i; } } } if ($regionalGibdds) { if (count($regionalGibdds) > 1) { foreach ($regionalGibdds as $i => $gibdd) { $mindist = 999999999 * 9999999; foreach ($gibdd->areas as $area) { foreach ($area->points as $point) { $dist = sqrt(pow($point->lat - $this->LATITUDE, 2) + pow($point->lng - $this->LONGITUDE, 2)); if ($dist < $mindist) { $mindist = $dist; } } } $regionalGibdds[$i]->mindist = $mindist; } $mindist = $regionalGibdds[$regkey]->mindist; foreach ($regionalGibdds as $i => $gibdd) { if ($gibdd->mindist <= $mindist) { $mindist = $gibdd->mindist; } else { unset($gibdds[$i]); } } } } $newArr = array(); foreach ($gibdds as $gibdd) { $newArr[] = $gibdd; } return $newArr; }