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'));
         }
     }
 }
 /**
  * 
  * @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 sortOrDelete($rec_id, $newList)
 {
     $db = O::app()->getDb();
     $transaction = $db->beginTransaction();
     try {
         $idToDelete = CDbCommandEx::create($db)->select('t.elm_id')->from($this->_tableName . ' t')->join(TableNames::REC_ELM_as('re'), '$re.elm_id = $t.elm_id')->where(array('AND', 're.rec_id = :rec_id', array('NOT IN', 're.elm_id', $newList)))->queryColumn(array('rec_id' => $rec_id));
         $weight = 0;
         foreach ($newList as $elm_id) {
             if (CDbCommandEx::create($db)->update(TableNames::REC_ELM, array('weight' => $weight), 'elm_id = :elm_id AND rec_id = :rec_id', array('elm_id' => $elm_id, 'rec_id' => $rec_id))) {
                 $weight++;
             }
         }
         CDbCommandEx::create($db)->delete(TableNames::REC_ELM, array('IN', 'elm_id', $idToDelete));
         $transaction->commit();
         return true;
     } catch (CException $e) {
         $transaction->rollback();
         throw $e;
     }
 }
 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';
     }
 }