コード例 #1
0
 public function save($userId)
 {
     $db = O::app()->getDb();
     $db->createCommand()->delete(TableNames::DIVISION_CHOICE, array('AND', 'user_id=:user_id', array('IN', 'div_id', array_keys($this->_allDivisionsName))), array('user_id' => $userId));
     $transaction = $db->beginTransaction();
     try {
         foreach ($this->choices as $weight => $div_id) {
             $db->createCommand()->insert(TableNames::DIVISION_CHOICE, array('user_id' => $userId, 'div_id' => $div_id, 'weight' => $weight));
         }
         $transaction->commit();
         UserState::invalidate($userId, $this->_rec->id);
         return true;
     } catch (CDbException $e) {
         $transaction->rollback();
         return false;
     }
 }
コード例 #2
0
 public function save()
 {
     $db = O::app()->db;
     $transaction = $db->beginTransaction();
     try {
         foreach ($this->_values as $k => $v) {
             $field_id = substr($k, 6);
             // field_{$id}
             if ($v[0] && !$v[1]) {
                 $db->createCommand()->insert(TableNames::FORM_VALUE, array('field_id' => $field_id, 'user_id' => $this->_userId, 'value' => $v[0]));
             } elseif ($v[0] != $v[1]) {
                 $db->createCommand()->update(TableNames::FORM_VALUE, array('value' => $v[0], 'updated' => new CDbExpression('CURRENT_TIMESTAMP')), 'field_id = :field_id AND user_id = :user_id', array('field_id' => $field_id, 'user_id' => $this->_userId));
             }
         }
         $transaction->commit();
         UserState::invalidate($this->_userId, $this->_recId, 'form');
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         $this->addErrors($e);
         return false;
     }
 }
コード例 #3
0
 public function save()
 {
     $db = O::app()->getDb();
     $slots = $db->createCommand()->select('us.slot_id')->from(TableNames::INTERVIEW_USER_SLOT . ' us')->join(TableNames::REC_ELM . ' oe', 'oe.elm_id = us.slot_id AND oe.rec_id = :rec_id')->where('us.user_id = :user_id')->queryColumn(array('rec_id' => $this->_recId, 'user_id' => $this->_userId));
     if ($slots) {
         $slots = array_flip($slots);
     } else {
         $slots = array();
     }
     $transaction = $db->beginTransaction();
     try {
         foreach ($this->time as $id => $time) {
             if (isset($slots[$id])) {
                 $db->createCommand()->update(TableNames::INTERVIEW_USER_SLOT, array('time' => $time, 'updated' => new CDbExpression('CURRENT_TIMESTAMP')), 'slot_id = :slot_id AND user_id = :user_id', array('slot_id' => $id, 'user_id' => $this->_userId));
             } else {
                 $db->createCommand()->insert(TableNames::INTERVIEW_USER_SLOT, array('slot_id' => $id, 'user_id' => $this->_userId, 'time' => $time));
             }
         }
         $transaction->commit();
         UserState::invalidate($this->_userId, $this->_recId, 'slots');
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
     return false;
 }