public function getRuleName() { if (!$this->_rule) { $this->_rule = CDbCommandEx::create()->select('rule')->from(TableNames::REC_ADMIN)->where('$rec_id = :rec_id AND $user_id = :user_id', array('rec_id' => $this->_recId, 'user_id' => $this->_userId))->limit(1)->queryScalar(); } return $this->_rule; }
public function setUserId($userId) { if ($userId) { $command = CDbCommandEx::create()->select('d.div_id')->from(TableNames::DIVISION_CHOICE . ' dc')->join(TableNames::DIVISION . ' d', '$dc.div_id = $d.div_id AND $d.rec_id = :rec_id AND $d.enabled = 1')->order('dc.weight, d.weight, d.name')->where('$dc.user_id = :user_id'); $this->choices = $command->queryColumn(array('rec_id' => $this->_rec->id, 'user_id' => $userId)); } else { //$this->choices = array(); } }
/** * * @param type $name * @param type $cache * @return type */ public function findByName($name, $cache = TRUE) { $cache = O::app()->getCache(); if (!$cache || ($attributes = $cache->get(self::getCacheName($name))) == false) { $attributes = CDbCommandEx::create($this->dbConnection)->select()->from($this->tableName())->where('$name = :rec_name', array('rec_name' => $name))->limit(1)->queryRow(); if ($cache) { $cache->set(self::getCacheName($name), $attributes, 3600); } } return $obj = $this->populateRecord($attributes); }
public function actionSaveOptions($id) { if (isset($_POST['slot_options'])) { // check id $org_id = CDbCommandEx::create()->select('re.rec_id')->from(TableNames::INTERVIEW_SLOT . ' is')->join(TableNames::REC_ELM_as('re'), '$re.elm_id = $is.elm_id')->limit(1)->where('$is.elm_id = :elm_id', array('elm_id' => $id))->queryScalar(); if ($org_id == $this->rec->id) { CDbCommandEx::create()->update(TableNames::INTERVIEW_SLOT, array('options' => serialize($_POST['slot_options'])), 'elm_id = :elm_id', array('elm_id' => $id)); echo json_encode(array('status' => 'OK', 'error' => null)); } else { echo json_encode(array('status' => 'ERROR', 'error' => '403')); } } }
private function parseSlotTable($arg) { $id = $arg['elm_id']; $startDate = explode('-', $arg['start_date']); $endDate = explode('-', $arg['end_date']); $time_ranges = $arg['time_range']; $duration = $arg['duration']; //$options = $arg['options']; // SELECT t1.time, count(t1.user_id), t2.user_id FROM `oprecx_interview_user_slots` t1 LEFT JOIN `oprecx_interview_user_slots` t2 ON t2.slot_id = t1.slot_id AND t2.time = t1.time AND t2.user_id = 6 group by t1.time $reader = CDbCommandEx::create()->select('t1.time, COUNT(t1.user_id) as cnt, t2.user_id')->from(TableNames::INTERVIEW_USER_SLOT . ' t1')->leftJoin(TableNames::INTERVIEW_USER_SLOT . ' t2', '$t2.slot_id = $t1.slot_id AND $t2.time = $t1.time AND $t2.user_id = :user_id')->where('$t1.slot_id = :slot_id')->group('t1.time, t2.user_id')->order('t1.time')->query(array('slot_id' => $id, 'user_id' => O::app()->user->id)); $slot_count = array(); foreach ($reader as $row) { $slot_count[$row['time']] = array($row['cnt'], $row['user_id'] != null); } $y = $startDate[0]; $m = $startDate[1]; $d = $startDate[2]; $rv = array(); $month_len = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $month_len[1] = $y % 4 == 0 ? 29 : 28; while ($d <= $endDate[2] || $m < $endDate[1] || $y < $endDate[0]) { $tmp = array(); foreach ($time_ranges as $time_range) { for ($time = $time_range[0]; $time < $time_range[1]; $time += $duration) { $t = $time; $scn = $t % 60; $t = (int) ($t / 60); $mnt = $t % 60; $hr = (int) ($t / 60); $dt = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $y, $m, $d, $hr, $mnt, $scn); if (isset($slot_count[$dt])) { $tmp[] = array($time, $slot_count[$dt][1], $slot_count[$dt][0], 1); } else { $tmp[] = array($time, false, 0, 1); } } } $rv[] = array($y, $m, $d, $tmp); $d++; if ($d > $month_len[$m - 1]) { $m++; $d = 1; } if ($m > 12) { $y++; $m = 1; $month_len[1] = $y % 4 == 0 ? 29 : 28; } } return $rv; }
public function initComponent($rec_id, $user_id) { $this->_recId = $rec_id; $this->_userId = $user_id; //$this-> = array('id' => "reg-form-{$rec_id}-{$user_id}"); $this->_elements = array(); $this->_labels = array(); $required = array(); /** * @var CDbDataReader sql ini manggil */ $reader = CDbCommandEx::create()->selectDistinct('oe.elm_id AS form_id, oe.name AS form_name, oe.weight AS oe_weight, fv.value, ff.*')->from(TableNames::FORM_FIELD . ' ff')->join(TableNames::REC_ELM . ' oe', '$oe.elm_id = $ff.form_id AND $oe.rec_id = :rec_id')->join(TableNames::DIVISION_ELM . ' de', '$de.elm_id = $oe.elm_id')->join(TableNames::DIVISION_CHOICE . ' dc', '$dc.div_id = $de.div_id AND $dc.user_id = :user_id')->leftJoin(TableNames::FORM_VALUE . ' fv', '$fv.field_id = $ff.field_id AND $fv.user_id = :user_id')->order('oe.weight, oe.name, ff.weight, ff.created')->query(array(':user_id' => $user_id, ':rec_id' => $rec_id)); /** @var array $row */ foreach ($reader as $row) { $options = unserialize($row['options']); if (!is_array($options)) { $options = array(); } $name = 'field_' . $row['field_id']; $options['type'] = $row['type']; $options['label'] = $row['name']; $options['hint'] = $row['desc']; $options['required'] = $row['required']; $options['visible'] = true; if ('dropdownlist' === $options['type'] && !isset($options['prompt'])) { $options['prompt'] = '<<' . $options['label'] . '>>'; //O::t('oprecx', '- select -'); } if (!isset($options['placeholder'])) { $options['placeholder'] = $options['label']; } $this->_values[$name] = array($row['value'], $row['value']); $this->_elements[$name] = $options; $this->_labels[$name] = $row['name']; if ($row['required']) { $required[] = $name; } } if (count($required)) { $this->_rules[] = array(implode(', ', $required), 'required'); } }
public function actionSaveDivision() { if (isset($_POST['Division'])) { $db = O::app()->getDb(); if ($_POST['Division']['div_id'] == 0) { $this->checkAccess('division.add'); $row = CDbCommandEx::create($db)->select('MAX(t1.div_id) as i, MAX(t2.weight) as m, COUNT(t2.weight) c ')->from(TableNames::DIVISION . ' t1')->leftJoin(TableNames::DIVISION . ' t2', '$t2.rec_id = :rec_id', array('rec_id' => $this->rec->id))->queryRow(); $div_id = $row['i'] + 1; $db->createCommand()->insert(TableNames::DIVISION, array('div_id' => $div_id, 'rec_id' => $this->rec->id, 'name' => $_POST['Division']['name'], 'description' => $_POST['Division']['description'], 'weight' => max($row['m'], $row['c']) + 1)); } else { $this->checkAccess('division.edit'); $div_id = $_POST['Division']['div_id']; $db->createCommand()->update(TableNames::DIVISION, array('name' => $_POST['Division']['name'], 'description' => $_POST['Division']['description']), 'div_id = :div_id', array('div_id' => $div_id)); } if (O::app()->getRequest()->isAjaxRequest) { $division = Division::model()->findByPk($div_id); echo CJSON::encode(array('status' => 'OK', 'div_id' => $div_id, 'html' => $this->renderPartial('_division_item', array('item' => $division), true))); } else { $this->redirect(array('division')); } } else { throw new CHttpException(403); } }
private function parseSlotTable2($retriveCount = true) { static $month_len = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $slotTable = array(); list($y, $m, $d) = explode('-', $this->start_date); $endDate = explode('-', $this->end_date); $month_len[1] = $y % 4 == 0 ? 29 : 28; while ($d <= $endDate[2] || $m < $endDate[1] || $y < $endDate[0]) { $slotDay = array(); foreach ($this->time_range as $time_range) { for ($time = $time_range[0]; $time < $time_range[1]; $time += $this->duration) { $slotDay[self::formatTimeInt($time)] = array('n' => 0, 'max' => $this->max_user_per_slot, 'selected' => false); } } $slotTable[self::formatDate($y, $m, $d)] = $slotDay; $d++; if ($d > $month_len[$m - 1]) { $m++; $d = 1; } if ($m > 12) { $y++; $m = 1; $month_len[1] = $y % 4 == 0 ? 29 : 28; } } //* if ($retriveCount) { $command = CDbCommandEx::create()->select('t1.time, COUNT(t1.user_id) as n')->from(TableNames::INTERVIEW_USER_SLOT . ' t1')->where('$t1.slot_id = :slot_id', array('slot_id' => $this->id))->group('t1.time'); foreach ($command->query() as $row) { list($date, $time) = explode(' ', $row['time']); if (isset($slotTable[$date]) && isset($slotTable[$date][$time])) { $cell =& $slotTable[$date][$time]; $cell['n'] = $row['n']; //if ($row['user_id'] != null) $cell['selected'] = true; } } // */ } if (is_array($this->options)) { self::mergeTable($slotTable, $this->options); } return $slotTable; }
/** * * @param CDbDataReader $reader */ private function populateItem($data, $retriveDivList = true) { if (isset($data['elm_id'])) { $data['id'] = $data['elm_id']; } if ($retriveDivList) { $data['divList'] = CDbCommandEx::create()->select('div_id')->from(TableNames::DIVISION_ELM)->where('$elm_id = :elm_id', array('elm_id' => $data['id']))->queryColumn(); } /* @var $obj CSimpleModel */ $class = get_class($this); $obj = new $class(); $obj->data = $data; return $obj->afterPopulateItem(); }
/** * * @param InterviewSlotForm $model */ function generateInterviewTables($model) { /* @var $slot InterviewSlot */ $slot = $model->slot; $dateFormatter = O::app()->locale->dateFormatter; echo '<fieldset><legend>', $slot->name, '<br /><small>', $slot->description, '</small></legend><div class="slots">'; $radio_id_prefix = "InterviewSlotForm_time_{$slot->id}_"; $i = 0; $radioName = get_class($model) . "[time][{$slot->id}]"; $slotStatus = $slot->getStatus(); $slotOptions = $slot->options; $datetime = new DateTime(); if (isset($slotOptions['choiceOptions'])) { $n = $slotOptions['choiceOptions']['n']; switch ($slotOptions['choiceOptions']['unit']) { case 'd': case 'D': $datetime->add(new DateInterval('P' . $n . strtoupper($slotOptions['choiceOptions']['unit']))); $datetime->setTime(0, 0, 0); break; default: $datetime->add(new DateInterval('PT' . $n . strtoupper($slotOptions['choiceOptions']['unit']))); } } $enableFrom = $datetime->getTimestamp(); $currentChoice = CDbCommandEx::create()->select('time')->from(TableNames::INTERVIEW_USER_SLOT)->where('$slot_id = :slot_id AND $user_id = :user_id')->queryScalar(array('slot_id' => $slot->id, 'user_id' => O::app()->user->id)); foreach ($slot->getDateList() as $date) { $date_str = $dateFormatter->formatDateTime($date, 'full', NULL); echo '<div class="date"><h3>', $date_str, '</h3><div data-role="controlgroup" data-type="horizontal">', PHP_EOL; foreach ($slot->getTimeList() as $time) { $radio_id = $radio_id_prefix . $i++; $value = $date . ' ' . $time[0]; $checked = $currentChoice == $value; if (isset($slotStatus[$value])) { $user_count = $slotStatus[$value]['selected']; } else { $user_count = 0; } if (isset($slotOptions[$value]) && isset($slotOptions[$value]['max'])) { $max_user = $slotOptions[$value]['max']; } else { $max_user = $slot->max_user_per_slot; } $label_class = 'time-label '; if ($enableFrom == 0 || strtotime($value) > $enableFrom) { if ($checked) { $label_class .= 'time-label-available time-label-selected'; } elseif ($user_count >= $max_user) { $label_class .= 'time-label-full'; } elseif ($user_count > 0) { $label_class .= 'time-label-available time-label-halffull'; } else { $label_class .= 'time-label-available'; } } else { $label_class .= 'time-label-full'; } echo '<span class="time">', CHtml::radioButton($radioName, $checked, array('id' => $radio_id, 'value' => $value, 'data-role' => 'none', 'disabled' => $user_count >= $max_user)), CHtml::label(substr($time[0], 0, 5) . '-' . substr($time[1], 0, 5), $radio_id, array('data-slotid' => $slot->id, 'data-time' => $date_str, 'class' => $label_class)), '</span>', PHP_EOL; } echo '</div></div>'; } echo '</div></fieldset>', PHP_EOL; }
/** * * @return Recruitment[] */ public function getMyRecruitments($limit = FALSE) { return Recruitment::model()->populateRecords(CDbCommandEx::create()->select('o.id, o.name, o.full_name')->from(TableNames::RECRUITMENT_as('o'))->join(TableNames::REC_ADMIN . ' oa', 'oa.rec_id = $o.id')->where('$oa.user_id = :user_id', array('user_id' => O::app()->user->id))->order('o.updated DESC')->queryAll()); }
public function actionInterview() { $this->cekLogin('interview'); if ($this->isWizard) { $this->backAction = 'form'; } $slotlist = CDbCommandEx::create()->selectDistinct('is.elm_id, re.weight')->from(TableNames::INTERVIEW_SLOT . ' is')->join(TableNames::REC_ELM_as('re'), '$re.elm_id = $is.elm_id')->join(TableNames::DIVISION_ELM . ' de', '$de.elm_id = $is.elm_id')->join(TableNames::DIVISION_CHOICE . ' dc', '$dc.div_id = $de.div_id')->join(TableNames::DIVISION . ' d', '$d.div_id = $de.div_id')->where('$dc.user_id = :user_id AND $d.rec_id = :rec_id', array('user_id' => $this->user->id, 'rec_id' => $this->rec->id))->order('re.weight')->queryColumn(); if (isset($this->actionParams['slotid'])) { $slotid = $this->actionParams['slotid']; } elseif (count($slotlist) > 0) { $slotid = $slotlist[0]; } else { $slotid = NULL; } if ($slotid) { if (($slot_index = array_search($slotid, $slotlist)) === FALSE) { throw new CHttpException(403); } $model = new InterviewSlotForm('', $this->rec->id, $this->user->id, $slotid); if (isset($_POST['InterviewSlotForm'])) { $model->setAttributes($_POST['InterviewSlotForm']); if ($model->validate() && $model->save()) { $slot_index++; if ($slot_index < count($slotlist)) { if ($this->afterSave('interview', array('slotid' => $slotlist[$slot_index]))) { return; } } else { if ($this->afterSave('finish')) { return; } } } } $this->render('interview', array('model' => $model)); } else { echo 'No Slot available'; } }
public function getSelectedInterviewSlot() { if (!isset($this->_data['slots'])) { $this->_data['slots'] = CDbCommandEx::create()->selectDistinct('is.elm_id as slot_id, oe.name AS slot_name, ius.time, oe.weight')->from(TableNames::INTERVIEW_SLOT . ' is')->join(TableNames::REC_ELM . ' oe', '$oe.elm_id = $is.elm_id AND $oe.rec_id = :rec_id')->join(TableNames::DIVISION_ELM . ' de', '$de.elm_id = $oe.elm_id')->join(TableNames::DIVISION_CHOICE . ' dc', '$dc.div_id = $de.div_id AND $dc.user_id = :user_id')->leftJoin(TableNames::INTERVIEW_USER_SLOT . ' ius', '$ius.slot_id = $is.elm_id AND $ius.user_id = :user_id')->order('oe.weight, oe.name')->queryAll(true, array('rec_id' => $this->_recId, 'user_id' => $this->_userId)); $this->setModified(); } return self::arrayToObject($this->_data['slots']); }