public function loadModel($id) { $m = CledCalendarExceptionDates::model(); // apply scope, if available $scopes = $m->scopes(); if (isset($scopes[$this->scope])) { $m->{$this->scope}(); } $model = $m->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('D2calendarModule.crud', 'The requested page does not exist.')); } return $model; }
public static function isHollidayHour($datetime) { //validate, if calendar fully loadded $sql = "\n SELECT \n cled_id\n FROM\n cled_calendar_exception_dates \n WHERE cled_date = DATE(:dt) \n OR cled_date = ADDDATE(DATE(:dt), 1) \n OR cled_date = ADDDATE(DATE(:dt), -1)\n "; $rawData = Yii::app()->db->createCommand($sql); $rawData->bindParam(":dt", $datetime, PDO::PARAM_STR); $cled_data = $rawData->queryAll(); //aizpildam esosho un nakamo gadu, ja nav 3 ierakstu if (count($cled_data) < 3) { $cled = new CledCalendarExceptionDates(); $cled->fillYear(date('Y')); $cled->fillYear(date('Y') + 1); } /** * peec kalendara paskatās: * - vai svētdiena un brīvdiens * - ir svetkudiena * - pirms no 23:00 * - pēc līdz 6:00 */ $sql = "\n SELECT MAX(\n CASE\n WHEN cled_type = 'Holliday' \n AND WEEKDAY(cled_date) = 6 \n THEN 1 \n WHEN cled_type = 'Public Holliday' \n THEN 1 \n ELSE 0 \n END) is_extra_date \n FROM\n cled_calendar_exception_dates \n WHERE cled_date = DATE(:dt) \n OR cled_date = DATE(ADDDATE(:dt, INTERVAL 1 HOUR)) \n OR cled_date = DATE(ADDDATE(:dt, INTERVAL - 6*60*60 - 1 SECOND))\n "; $rawData = Yii::app()->db->createCommand($sql); $rawData->bindParam(":dt", $datetime, PDO::PARAM_STR); return $rawData->queryScalar() == 1; }
<div class="btn-group"> <?php $this->widget('bootstrap.widgets.TbButton', array('label' => Yii::t('D2calendarModule.crud', 'Create'), 'icon' => 'icon-plus', 'size' => 'large', 'type' => 'success', 'url' => array('create'), 'visible' => false)); ?> </div> <div class="btn-group"> <h1> <i class=""></i> <?php echo Yii::t('D2calendarModule.model', 'Kalendārs'); ?> </h1> </div> <div class="btn-group"> <?php $next_year = CledCalendarExceptionDates::getNextYear(); $this->widget('bootstrap.widgets.TbButton', array('label' => 'Ģenerēt ' . $next_year . ' gada dienas', 'icon' => 'icon-plus', 'size' => 'large', 'type' => 'success', 'url' => array('generate', 'year' => $next_year), 'visible' => Yii::app()->user->checkAccess('d2calendarAdmin'))); ?> </div> </div> </div> <div class="row"> <div class="span5"> <?php Yii::beginProfile('CledCalendarExceptionDates.view.grid'); Yii::app()->clientScript->registerScript('init_grid_filter', "\n function init_grid_filter(){\n filter_CledCalendarExceptionDates_cled_date_range_init();\n }\n "); $this->widget('TbGridView', array('id' => 'cled-calendar-exception-dates-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'template' => '{pager}{items}{pager}', 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'afterAjaxUpdate' => 'init_grid_filter', 'columns' => array(array('name' => 'cled_date', 'value' => 'date("d.m.Y",strtotime($data->cled_date))', 'filter' => $this->widget('vendor.dbrisinajumi.DbrLib.widgets.TbFilterDateRangePicker', array('model' => $model, 'attribute' => 'cled_date_range', 'format' => 'DD.MM.YYYY', 'options' => array('ranges' => array('this_week', 'last_week', 'this_month', 'last_month', 'this_year'))), TRUE)), array('class' => 'editable.EditableColumn', 'name' => 'cled_type', 'editable' => array('type' => 'select', 'url' => $this->createUrl('/d2calendar/cledCalendarExceptionDates/editableSaver'), 'source' => $model->getEnumFieldLabels('cled_type')), 'filter' => $model->getEnumFieldLabels('cled_type')), array('class' => 'editable.EditableColumn', 'name' => 'cled_notes', 'editable' => array('url' => $this->createUrl('/d2calendar/cledCalendarExceptionDates/editableSaver')))))); Yii::endProfile('CledCalendarExceptionDates.view.grid'); ?> </div></div>