public static function menuBadges() { $array = array(); $inbox = $quotes['open'] = $quotes['closed'] = $bookings['provisional'] = $bookings['confirmed'] = $bookings['cancelled'] = 0; $today = new DateTime(); $criteria = new CDbCriteria(); $criteria->addCondition('mstRequestUsers.user_id = ' . Yii::app()->user->getInfo()); $criteria->addCondition('mstRequestUsers.archived = 0'); $criteria->with = array('mstRequestUsers'); $modelArray = Requests::model()->findAll($criteria); foreach ($modelArray as $model) { switch ((int) $model->booking_type) { case 0: if ($model->mstRequestUsers[0]->seen == 0) { $inbox++; } break; case 1: $eventDateObj = new DateTime($model->bookingDate); if ($eventDateObj > $today) { $quotes['closed']++; } else { $quotes['open']++; } break; case 2: $bookings['provisional']++; break; case 3: $bookings['confirmed']++; break; case 4: $bookings['cancelled']++; break; } } $array['inbox'] = $inbox; $array['quotes'] = $quotes; $array['bookings'] = $bookings; return $array; }
public function actionBooking() { Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/request-date.css"); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/request-date-resp.css"); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/responsive-calendar/responsive-calendar.js", CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/request-booking.js", CClientScript::POS_END); if (Yii::app()->request->isPostRequest) { $getDate = Yii::app()->request->getParam('changeDate', false); $dateObj = DateTime::createFromFormat('j-n-Y', $getDate); if ($dateObj) { $dateObj = new DateTime($getDate); $this->_model->bookingDate = $dateObj->format('Y-m-d'); $this->_model->save(); } } $today = ComponentTime::todayStart(); $events = array(); // $bookingDate = new DateTime(date('Y-m-d', strtotime($this->_model->bookingDate))); // while ($bookingDate >= $today) { // $events[$bookingDate->format('Y-m-d')] = array( // 'number' => 1, // ); // $bookingDate->modify('-1 day'); // } $options = array('time' => date('Y-m', strtotime($this->_model->bookingDate)), 'events' => $events); $criteria = new CDbCriteria(); $criteria->addCondition('mstRequestUsers.user_id = ' . Yii::app()->user->getInfo()); $criteria->addCondition('mstRequestUsers.archived = 0'); $criteria->addCondition('booking_type > 0'); $criteria->with = array('mstRequestUsers'); $modelArray = Requests::model()->findAll($criteria); $requests = array(); foreach ($modelArray as $model) { $requests[] = array('color' => ComponentType::booking($model->booking_type), 'day' => date('j', strtotime($model->eventDate)), 'month' => date('n', strtotime($model->eventDate)), 'year' => date('Y', strtotime($model->eventDate))); } $passedDays = array(); $created_on = new DateTime(date('Y-m-d', strtotime($this->_model->created_on))); while ($created_on < $today) { $passedDays[] = array('day' => $created_on->format('j'), 'month' => $created_on->format('n'), 'year' => $created_on->format('Y')); $created_on->modify('+1 day'); } $today = array('day' => $today->format('j'), 'month' => $today->format('n'), 'year' => $today->format('Y')); $bookingDate = new DateTime(date('Y-m-d', strtotime($this->_model->bookingDate))); // $bookingDate = array( // 'day' => $bookingDate->format('j'), // 'month' => $bookingDate->format('n'), // 'year' => $bookingDate->format('Y'), // ); $array = array('options' => $options, 'color' => ComponentType::booking($this->_model->booking_type), 'today' => $today, 'requests' => $requests, 'passedDays' => $passedDays, 'bookingDate' => $bookingDate->format('m-d-Y')); $json = json_encode($array); Yii::app()->clientScript->registerScript('mapvar10', "var json='" . $json . "';", CClientScript::POS_HEAD); $this->render('booking', array('model' => $this->_model)); }
public static function getMessageCreators($id) { $messageCreatorIds = []; $requestUsersArray = []; $messagesArray = array(); $requestsModel = Requests::model()->findByPk($id); if ($requestsModel) { foreach ($requestsModel->mstRequestUsers as $user) { $requestUsersArray[] = (int) $user->user_id; } } if (!empty($requestUsersArray)) { $criteria = new CDbCriteria(); $criteria->addCondition('request.id = ' . $requestsModel->id); $criteria->addCondition('t.status = 1'); $criteria->order = 't.created_on DESC'; $criteria->with = array('request'); $modelArray = Messages::model()->findAll($criteria); foreach ($modelArray as $model) { $messagesArray = array('creator' => $model->created_by); } } return $messagesArray; }
private function isReal($id) { $return = false; if ($id > 0) { $model = Requests::model()->findByPk($id); if ($model != null) { $requestUsersArray = array(); foreach ($model->mstRequestUsers as $user) { $requestUsersArray[] = (int) $user->user_id; } if (in_array(Yii::app()->user->getInfo(), $requestUsersArray)) { $return = array('model' => $model, 'requestUsers' => $requestUsersArray); } } } return $return; }
public function loadModelDoc($id) { $criteria = new CDbCriteria(); $criteria->with = array('doc'); $criteria->compare('t.id', $id); $model = Requests::model()->find($criteria); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionRequest() { if (!isset($_POST['doc_id'])) { $res['note'] = 'Не выбран номер запроса'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } if (!isset($_POST['comment']) || empty($_POST['comment'])) { $res['note'] = 'Необходимо прокомментировать заявку'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', array($_POST['doc_id'])); $check = Documents::model()->findAll($criteria); if (empty($check)) { $res['note'] = 'Заявка с таим номером не существует'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } if ($check[0]->user_id != Yii::app()->user->id) { $res['note'] = 'Этот заявка был создан не Вами'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } $criteria_req = new CDbCriteria(); $criteria_req->addInCondition('doc_id', array($check[0]->id)); $criteria_req->addInCondition('user_id', array($check[0]->user_id)); $criteria_req->addInCondition('state', array('WAIT')); $check_req = Requests::model()->count($criteria_req); if ($check_req != 0) { $res['note'] = 'Запрос уже был отправлен, дождитесь решения администрации'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } if ($this->documentUpdate($check[0]->id, array('state' => 'Inquiry'))) { if ($this->createRequest(Yii::app()->user->id, $_POST['doc_id'], $_POST['comment'])) { $res['note'] = 'Запрос успешно отправлен'; $res['type'] = 'success'; echo json_encode($res); Yii::app()->end(); } else { $this->documentUpdate($check[0]->id, array('state' => 'Save')); $res['note'] = 'Ошибка Базы Данных, обратитесь к администрации'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } } else { $res['note'] = 'Ошибка Базы Данных, обратитесь к администрации'; $res['type'] = 'error'; echo json_encode($res); Yii::app()->end(); } Yii::app()->end(); }
public function actionCalendar() { // $this->layout = "//layouts/calendar"; Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/my-calendar.css"); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/my-calendar-resp.css"); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/jQuery/jquery-ui.min.js", CClientScript::POS_HEAD); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/fullcalendar/fullcalendar.js", CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/spin/spin.js", CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/main.js", CClientScript::POS_END); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/my-calendar.js", CClientScript::POS_END); $returnArray = array(); $day = 60 * 60 * 24; $time = time(); $from = Yii::app()->request->getParam('from', ''); $to = Yii::app()->request->getParam('to', ''); $criteria = new CDbCriteria(); $criteria->addCondition('mstRequestUsers.user_id = ' . Yii::app()->user->getInfo()); $criteria->addCondition('mstRequestUsers.archived = 0'); // $criteria->addCondition('booking_type > 0'); if (!empty($from)) { $criteria->addCondition('bookingDate >= ' . $from); } if (!empty($to)) { $criteria->addCondition('bookingDate < ' . $to); } $criteria->with = array('mstRequestUsers'); $modelArray = Requests::model()->findAll($criteria); $eventsArray = array(); $requestsTempArray = array(); foreach ($modelArray as $model) { if ($model->booking_type > 0) { $criteria = new CDbCriteria(); $criteria->select = 'sum(amount) as amount'; $criteria->addCondition('request_id = ' . $model->id); $criteria->addCondition('status = 1'); $modelSum = Payments::model()->find($criteria); $moneyPaid = (int) $modelSum->amount; $eventsArray[] = array('id' => $model->id, 'creator' => $model->createdBy->firstName . ' ' . $model->createdBy->lastName, 'title' => ComponentString::showPart($model->map->name, 14), 'map' => ComponentString::showPart($model->map->name, 28), 'event_type' => $model->eventType->name, 'start_time' => date('H:i A', strtotime($model->start_time)), 'end_time' => date('H:i A', strtotime($model->end_time)), 'start' => $model->eventDate, 'dateName' => date('l, F d, Y', strtotime($model->eventDate)), 'allDay' => true, 'type' => $model->booking_type, 'daysTotal' => ceil((strtotime($model->eventDate) - strtotime($model->created_on)) / $day), 'daysLeft' => ceil((strtotime($model->eventDate) - $time) / $day), 'moneyPaid' => $moneyPaid, 'moneyTotal' => $model->amount); } else { $requestsTempArray[date('d-m-Y', strtotime($model->eventDate))][] = 1; } } $criteria = new CDbCriteria(); $criteria->addCondition(' (LOWER(calendarType.name) = "flag" AND t.created_by = ' . Yii::app()->user->getInfo() . ') OR (LOWER(calendarType.name) = "unavailable" AND t.created_by = ' . Yii::app()->user->getInfo() . ') OR (LOWER(calendarType.name) = "holiday") '); $criteria->addCondition('calendarType.status = 1'); $criteria->addCondition('t.status = 1'); $criteria->with = array('calendarType'); $modelArray = Calendar::model()->findAll($criteria); $flagsArray = array(); $holidaysArray = array(); $unavailableArray = array(); foreach ($modelArray as $model) { switch (strtolower($model->calendarType->name)) { case 'flag': $flagsArray[] = array('id' => $model->id, 'title' => ComponentString::showPart($model->message, 30), 'start' => $model->calendar_date); break; case 'holiday': $holidaysArray[] = array('id' => $model->id, 'title' => $model->message, 'start' => $model->calendar_date); break; case 'unavailable': $unavailableArray[] = array('id' => $model->id, 'title' => $model->message, 'start' => $model->calendar_date); break; } } $requestsArray = array(); foreach ($requestsTempArray as $key => $request) { $requestsArray[$key] = count($request); } $returnArray['events'] = $eventsArray; $returnArray['flags'] = $flagsArray; $returnArray['requests'] = $requestsArray; $returnArray['holidays'] = $holidaysArray; $returnArray['unavailable'] = $unavailableArray; $json = json_encode($returnArray); Yii::app()->clientScript->registerScript('mapvar10', "var json='" . $json . "';", CClientScript::POS_HEAD); $this->render('calendar'); }