/** * Save the students state for this workshop to disk. * * @param UserState $state * @return int */ public function serialize(UserState $state) { $saveFile = sprintf('%s/%s', $this->path, static::SAVE_FILE); $data = file_exists($saveFile) ? $this->readJson($saveFile) : []; $data[$this->workshopName] = ['completed_exercises' => $state->getCompletedExercises(), 'current_exercise' => $state->getCurrentExercise()]; return file_put_contents($saveFile, json_encode($data)); }
public function getUserState() { if ($this->_userState) { return $this->_userState; } return $this->_userState = UserState::load($this->getUser()->getId(), $this->rec->id); }
/** * * @param int $userId * @param int $recId * @return UserState Description */ public static function &load($userId, $recId) { //$cacheName = "oprecx:UserState:userId={$userId}:recId={$recId}"; $objName = "{$userId}:{$recId}"; if (!isset(self::$_loaded[$objName])) { $obj = new UserState(); $obj->_userId = $userId; $obj->_recId = $recId; if (false === ($data = O::app()->cache->get(sprintf(self::$_cacheName, $userId, $recId)))) { $data = array(); $obj->setModified(); } $obj->_data = $data; self::$_loaded[$objName] =& $obj; } return self::$_loaded[$objName]; }
/** * 根据GEOHASH编码得到附近的人 * @param string $geohashCode * @return array $arr */ public function getNearPerson($geohashCode) { $neighbors = $this->geohash->neighbors($geohashCode); array_push($neighbors, $geohashCode); $criteria = new CDbCriteria(); $criteria->addInCondition('geohash', array_values($neighbors)); $states = UserState::model()->findAll($criteria); $arr = array(); foreach ($states as $key => $value) { $arr[$key] = $value->userId; } return $arr; }
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; } }
/** * * @param * @param * @return */ public function stateChange($userId, array $data) { $username = User::model()->findByPk($userId)->username; $avatar0 = User::model()->findByPk($userId)->avatar0; $model = UserState::model()->findByPk($userId); if (array_key_exists('userId', $data)) { unset($data['userId']); } $model->attributes = $data; if (!empty($model->attributes)) { $model->save(); $data = $model->attributes; $data['username'] = $username; $data['avatar0'] = $avatar0; foreach ($data as $key => $value) { Yii::app()->user->setState($key, $value); } return true; } }
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; } }
private function upload($model, $attribute = 'file') { $file = array(); $attach = CUploadedFile::getInstance($model, $attribute); if ($attach) { if ('jpg' == $attach->extensionName || 'png' == $attach->extensionName || 'gif' == $attach->extensionName) { $model->type = '1'; } if ($attach->extensionName == 'amr' || $attach->extensionName == 'caf') { $model->type = '2'; } $preRand = $model->receiver . time() . '.'; $imageName = $preRand . $attach->extensionName; $file['origin'] = $imageName; $attach->saveAs($this->savePath . $imageName); if ($attach->extensionName != 'amr' && $attach->extensionName != 'caf') { $thumb = Yii::app()->thumb; $thumb->image = $this->savePath . $imageName; $size = getimagesize($thumb->image); $width = $size[0]; $height = $size[1]; $thumb->width = $width / 2; $thumb->height = $height / 2; $thumb->mode = 4; $thumb->directory = $this->savePath; $thumb->defaultName = '_' . $preRand; $thumb->createThumb(); $thumb->save(); if (UserState::model()->findByPk($model->receiver)->type == 0) { $file['thumb'] = $thumb->defaultName . $attach->extensionName; } } return $file; } else { return ''; } }
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $userState = UserState::load(O::app()->user->id, $this->rec->id); ?> <div id="division-summary"> <h3><?php echo CHtml::link(O::t('oprecx', 'Division Choices'), $this->getURL('division', array('edit' => 1))); ?> </h3> <?php renderDivisionChoices($userState->getDivisionChoices()); ?> </div><!-- #division-summary --> <div id="form-summary"> <h3><?php echo CHtml::link(O::t('oprecx', 'Form'), $this->getURL('form', array('edit' => 1))); ?> </h3> <?php renderFormStatus($userState->getFormStatus()); ?> </div><!-- #form-summary --> <div id="intslot-summary"> <h3><?php echo O::t('oprecx', 'Interview Slot');
function chooseFunctionNum($keyword, $yixin) { $reply = ''; if (key_exists($keyword, cons::$FUNCTION_STR_ARRAY)) { $reply = $yixin->makeText(cons::$FUNCTION_STR_ARRAY[$keyword]); UserState::setUserState($yixin->msg['FromUserName'], $keyword, ''); } else { $reply = $yixin->makeText(cons::$WELCOME_STR); } return $reply; }
/** * @param UserState $state * * @return int */ public function serialize(UserState $state) { return file_put_contents($this->path, json_encode(['completed_exercises' => $state->getCompletedExercises(), 'current_exercise' => $state->getCurrentExercise()])); }
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; }