public function sendMsg($usra_id, $usrb_id, $msg) { $c = new CDbCriteria(); $c->addCondition('(usra_id=:usra_id AND usrb_id=:usrb_id) OR (usra_id=:usrb_id AND usrb_id=:usra_id)'); $c->params[':usra_id'] = $usra_id; $c->params[':usrb_id'] = $usrb_id; $talk = Talk::model()->find($c); if (empty($talk)) { $talk = new Talk(); $talk->usra_id = $usra_id; $talk->usrb_id = $usrb_id; $talk->content = $usra_id . '&' . $usrb_id; $talk->save(); } $path = Yii::app()->basePath . '/../assets/talks/' . $talk->content; if (file_exists($path)) { $buf = file_get_contents($path); $messages = unserialize($buf); } else { $messages = array(); } $msg = array('usr_id' => $usra_id, 'msg' => $msg, 'timestamp' => time(), 'is_read' => FALSE); array_unshift($messages, $msg); $buf = serialize($messages); file_put_contents($path, $buf); }
function approve($id) { if ($_POST) { $rs = new Talk($id); $rs->from_array($_POST); $rs->save(); } }
/** * Create a talk. * * @param Talk The talk to create. * * @return void */ public static function createTalk(Talk $talk) { Log::info('Create talk.', compact('talk')); $validator = $talk->getValidator(); if ($validator->fails()) { throw new ValidationException($validator); } $talk->created_by = Auth::user()->id; $talk->updated_by = Auth::user()->id; $talk->save(); }
/** * Deals cards to players based on hand size, * will deal entire deck if handSize is 0. Has scope for * dealing different sized hands as required * * @param int $handSize */ protected function deal($handSize = 0) { Talk::say('Dealing...'); if ($handSize == 0) { // If handSize is 0 then we'll deal all the cards to all players $counter = floor($this->deck->undealtCount() / count($this->players)); } else { if ($this->deck->undealtCount() >= count($this->players) * $handSize) { // Else if theres enough cards we'll deal the appropriate handSize $counter = $handSize; } else { // But if theres not enough cards we'll exit $counter = 0; } } // If we've got players if (!empty($this->players)) { // And the counter allows it while ($counter > 0) { // Deal a card to each player foreach ($this->players as $player) { $player->takeCard($this->deck->deal()); } // Decrement the counter $counter--; } } }
function __construct($controller, $name, $talkID) { // Email Address Field $EmailAddressField = new TextField('Email', "Speaker's Email Address"); $formData = Session::get("FormInfo.Form_CallForSpeakersRegistrationForm.data"); if ($formData['Email']) { $email = $formData['Email']; } else { $email = Member::currentUser()->Email; } $EmailAddressField->setValue($email); // Talk ID $TalkField = new HiddenField('TalkID', "TalkID", $talkID); $fields = new FieldList($EmailAddressField, $TalkField); $talk = NULL; if ($talkID != NULL) { // Look to see if the presentation has at least one speaker attached $talkID = Convert::raw2sql($talkID); $talk = Talk::get()->byID($talkID); } if ($talk && $talk->HasSpeaker()) { $actions = new FieldList(new FormAction('addAction', 'Add New Speaker'), new FormAction('done', 'Done Editing Speakers')); } else { $actions = new FieldList(new FormAction('addAction', 'Add First Speaker')); } parent::__construct($controller, $name, $fields, $actions); }
public function talks($day) { $talks = Talk::get()->filter(array('Day' => $day))->sort('Start ASC'); if ($day === 'Sat') { $talks = GroupedList::create($talks->sort('Start ASC, Room ASC')); } return $talks; }
/** * @param string $year * @param string $month * @param $key * @return Talk */ public function fetchTalk($year, $month, $key) { $month = strtolower($month); $talk = $this->talks[$year][$month][$key]; if (!isset($talk)) { return null; } return Talk::createFromArray($year, $month, $talk); }
public function start() { $r = Yii::app()->db->createCommand('SELECT aid, name, type, tx, d_rq FROM dc_animal ORDER BY d_rq DESC')->queryAll(); $prev_rank = Yii::app()->cache->get('d_rq_rank_report'); if (isset($prev_rank)) { foreach ($r as $k => $v) { $rank[$v['aid']] = $k; if (isset($prev_rank[$v['aid']]) && $prev_rank[$v['aid']] > $k) { $r[$k]['change'] = 1; } else { if (isset($prev_rank[$v['aid']]) && $prev_rank[$v['aid']] < $k) { $r[$k]['change'] = -1; } else { $r[$k]['change'] = 0; } } } } else { foreach ($r as $k => $v) { $rank[$v['aid']] = $k; $r[$k]['change'] = 0; } } //奖励计算 $total_member = Yii::app()->db->createCommand('SELECT COUNT(*) FROM dc_user')->queryScalar(); $total_a = Yii::app()->db->createCommand('SELECT COUNT(aid), SUM(d_rq) FROM dc_animal')->queryRow(); $all_gold = $total_member * RANK_REWARD_E; $total_popularity = $total_a['SUM(d_rq)']; $reward_count = round($total_a['COUNT(aid)'] * 30 / 100); for ($i = 0; $i < $reward_count; $i++) { $aid = $r[$i]['aid']; $single_popularity = $r[$i]['d_rq']; $total_gold = $all_gold * $single_popularity / $total_popularity; if ($total_gold != 0) { $circles = Circle::model()->findAllByAttributes(array('aid' => $aid)); foreach ($circles as $circle) { $result_money = round($total_gold * $circle->d_contri / $single_popularity); $user = User::model()->findByPk($circle->usr_id); $user->gold += $result_money; $user->saveAttributes(array('gold')); $self_rank = $i + 1; $msg = "您的王国/家族在人气日排行榜中获得第" . $self_rank . "名,您获得" . $result_money . "金币奖励"; Talk::model()->sendMsg(NPC_SYSTEM_USRID, $user->usr_id, $msg); } } } Yii::app()->cache->set('d_rq_rank_report', $rank, 3600 * 24); Yii::app()->cache->set('d_rq_rank', $r, 3600 * 24); }
public function run() { TalkRevision::truncate(); Talk::truncate(); $author = User::first(); $greatTalk = $author->talks()->create([]); $terribleTalk = $author->talks()->create([]); $author->talks()->saveMany([$greatTalk, $terribleTalk]); $greatTalk->revisions()->create(['title' => 'My great talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-29 15:54:41']); $greatTalk->revisions()->create(['title' => 'My awesome talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-27 15:54:41']); $terribleTalk->revisions()->create(['title' => 'My awesome talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-28 15:54:41']); // Add a talk for user 2 for testing purposes $author = User::find(2); $superTalk = $author->talks()->create([]); $spiffyTalk = $author->talks()->create([]); $author->talks()->saveMany([$superTalk, $spiffyTalk]); $superTalk->revisions()->create(['title' => 'My Super talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-27 15:54:41']); $spiffyTalk->revisions()->create(['title' => 'My Spiffy talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-28 15:54:41']); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Topic(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Topic'])) { $model->attributes = $_POST['Topic']; $start_time = $_POST['Topic']['start_time']; $end_time = $_POST['Topic']['end_time']; if (!empty($start_time)) { $model->start_time = strtotime("{$start_time}"); } if (!empty($end_time)) { if ($end_time < $start_time) { $end_time = $start_time; } $model->end_time = strtotime("{$end_time}"); } $model->create_time = time(); if ($model->save()) { $file = CUploadedFile::getInstance($model, 'img'); if (isset($file)) { $path = Yii::app()->basePath . '/../images/topic/' . $model->topic_id . '.' . $file->getExtensionName(); $file->saveAs($path); $model->img = $model->topic_id . '.' . $file->getExtensionName(); $model->saveAttributes(array('img')); } $users = User::model()->findAll(); foreach ($users as $user) { Talk::model()->sendMsg(NPC_SYSTEM_USRID, $user->usr_id, "汪汪!宠物星球开展了一个" . $model->topic . "活动!参加的宠物有机会得到礼品哦~羡慕死汪了,快去看看吧~"); } $this->redirect(array('view', 'id' => $model->topic_id)); } } $this->render('create', array('model' => $model)); }
/** * Echos out a summary of current player card counts */ private function playerSummary() { foreach ($this->players as $player) { Talk::say($player->getName() . " now has " . $player->cardCount() . " cards", 0); } Talk::say('', 0); }
public function find($id) { return Talk::findOrFail($id); }
} } /** * talk */ class Talk { use A, B { B::smallTalk insteadof A; A::bigTalk insteadof B; } } /** * al */ class AliasedTalk { use A, B { B::smallTalk insteadof A; A::bigTalk insteadof B; B::bigTalk as talk; } } $t = new Talk(); $t->smallTalk(); $t->bigTalk(); echo "\r\n"; $aT = new AliasedTalk(); $aT->smallTalk(); $aT->bigTalk(); $aT->talk();
public function testCannotFetchOneTalkForOtherUser() { $talkId = Talk::where('author_id', 2)->first()->id; $response = $this->call('GET', 'api/talks/' . $talkId); $this->assertEquals(404, $response->getStatusCode()); }
public function actionRegisterApi($aid = NULL, $name, $gender, $age, $type, $u_name, $u_gender, $u_city, $code) { /* if (empty($name)) { throw new PException('注册信息不完整'); } */ $session = Yii::app()->session; $session->open(); $id = $session['id']; if (empty($id)) { $this->response->setExpired(); //重新登录 $this->response->render(); return; } $device = Device::model()->findByPk($id); if (empty($device)) { $this->response->setExpired(); //重新登录 $this->response->render(); return; } $pattern = '/^[a-zA-Z0-9\\x{30A0}-\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FBF}]+$/u'; if (empty($aid)) { //$namelen = (strlen($name)+mb_strlen($name,"UTF8"))/2; $namelen = mb_strlen($name, "UTF8"); if ($namelen > 8) { throw new PException('宠物昵称超过最大长度'); } if (!preg_match($pattern, $name)) { throw new PException('宠物昵称含有特殊字符'); } } //$u_namelen = (strlen($u_name)+mb_strlen($u_name,"UTF8"))/2; $u_namelen = mb_strlen($u_name, "UTF8"); if ($u_namelen > 8) { throw new PException('用户名超过最大长度'); } if (User::model()->isNameExist(trim($u_name))) { throw new PException('用户名已被注册'); } if (!preg_match($pattern, $u_name)) { throw new PException('用户名含有特殊字符'); } if ($code != '') { if (!($inviter = User::model()->getUserIdByCode(strtolower(trim($code))))) { throw new PException('邀请ID不存在'); } } $transaction = Yii::app()->db->beginTransaction(); try { $user = $device->register($aid, trim($name), $gender, $age, $type, trim($u_name), $u_gender, $u_city, empty($invter) ? NULL : $inviter); $session['usr_id'] = $device->usr_id; $session['not_registered'] = FALSE; $user->login(); Talk::model()->sendMsg(NPC_SYSTEM_USRID, $user->usr_id, "HI~我是的汪汪大使,欢迎来到宠物星球,以后星球上的新鲜事,汪汪会光速传达你,放心交给我吧,汪汪"); $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); throw $e; } $this->echoJsonData(array('isSuccess' => true)); }
<?php require_once "../App.class.php"; App::loadMod("User"); App::loadMod("Talk"); App::loadMod("Eassy"); $app = new App(); $user = new User(); $talk = new Talk(); $eassy = new Eassy(); if (!$user->isLogin()) { redirect("Location: status.php?action=login"); } if (isset($_GET['action']) || isset($_GET['id'])) { if ($_GET['action'] == "delete") { if (!$user->str_check($_GET['id'])) { redirect("Location: error.php"); } $t = $talk->getTalk($_GET['id']); $e = $eassy->getEassy($t['tid']); if ($user->getPower() != 0) { if ($user->getUser() != $e['author']) { redirect("Location: error.php"); } } $talk->delete($_GET['id']); echo "<script language=\"javascript\">alert('删除成功!');history.back(-1);</script>"; die; } } $tid = isset($_GET['tid']) ? $_GET['tid'] : "";
public function actionSearchApi($usr_id) { $c = new CDbCriteria(); $c->addCondition('(usra_id=:usra_id AND usrb_id=:usrb_id) OR (usra_id=:usrb_id AND usrb_id=:usra_id)'); $c->params[':usra_id'] = $this->usr_id; $c->params[':usrb_id'] = $usr_id; $talk = Talk::model()->find($c); if (empty($talk)) { $talk = new Talk(); $talk->usra_id = $this->usr_id; $talk->usrb_id = $usr_id; $talk->content = $this->usr_id . '&' . $usr_id; $talk->save(); } $this->echoJsonData(array('talk_id' => $talk->talk_id)); }
public function actionCommentApi() { $img_id = $_POST['img_id']; $body = $_POST['body']; $image = Image::model()->findByPk($img_id); $user = User::model()->findByPk($this->usr_id); $ex_gold = $user->gold; $ex_exp = $user->exp; $ex_lv = $user->lv; /* $comment = array( 'usr_id' => $this->usr_id, 'name' => $user->name, 'body' => $body, 'create_time' => time(), ); */ if (isset($_POST['reply_id'])) { $image->comments = 'usr_id:' . $this->usr_id . ',' . 'name:' . $user->name . ',' . 'reply_id:' . $_POST['reply_id'] . ',' . 'reply_name:' . $_POST['reply_name'] . ',' . 'body:' . $body . ',' . 'create_time:' . time() . ';' . $image->comments; //PMail::create($_POST['reply_id'], $user, $user->name.'在'.$image->img_id.'回复了你'); } else { $image->comments = 'usr_id:' . $this->usr_id . ',' . 'name:' . $user->name . ',' . 'body:' . $body . ',' . 'create_time:' . time() . ';' . $image->comments; } if ($image->saveAttributes(array('comments'))) { $animal = Animal::model()->findByPk($image->aid); $animal->t_rq += 5; $animal->d_rq += 5; $animal->w_rq += 5; $animal->m_rq += 5; $animal->saveAttributes(array('t_rq', 'd_rq', 'w_rq', 'm_rq')); $session = Yii::app()->session; if (isset($session['comment_count'])) { $session['comment_count'] += 1; } else { $session['comment_count'] = 1; } if ($session['comment_count'] <= 15) { $user->comment(); } if (isset($_POST['reply_id'])) { Talk::model()->sendMsg(NPC_IMAGE_USRID, $_POST['reply_id'], "[" . $image->img_id . "]" . $user->name . "回复了你:" . $body); } else { Talk::model()->sendMsg(NPC_IMAGE_USRID, $animal->master_id, "[" . $image->img_id . "]" . $user->name . "评论了你:" . $body); } $this->echoJsonData(array('exp' => $user->exp - $ex_exp, 'gold' => $user->gold - $ex_gold, 'lv' => $user->lv - $ex_lv)); } }
$exits = new Exits(); list($response->action, $response->data) = $exits->go_to($verb); break; case __('INVENTORY_VERB'): $inventory = new Inventory(); list($response->action, $response->data) = $inventory->show(); break; case __('LOOK_VERB'): $room = new Room(); list($response->action, $response->data) = $room->look($words); break; case __('TAKE_VERB'): $room = new Room(); list($response->action, $response->data) = $room->take($words); break; case __('TALK_VERB'): $talk = new Talk(); list($response->action, $response->data) = $talk->with($words); break; case __('DROP_VERB'): $inventory = new Inventory(); list($response->action, $response->data) = $inventory->drop($words); break; default: // chat savechat(CURRENT_ROOM, $data); $response->action = 'chat'; break; } file_put_contents("profiler.txt", memory_get_usage() . ' => ' . (microtime(1) - $time)); print_r(json_encode($response));
/** * @param string $month * @param string $year * @param array $data * @return Talk */ public static function createFromArray($year, $month, array $data) { $talk = new Talk(); $talk->setAbstract(isset($data['abstract']) ? $data['abstract'] : ''); $talk->setAvatar(isset($data['avatar']) ? $data['avatar'] : ''); $talk->setDate(isset($data['twitter']) ? new \DateTime($data['date'], new \DateTimeZone('Europe/London')) : null); $talk->setFeedbackUrl(isset($data['feedbackUrl']) ? $data['feedbackUrl'] : ''); $talk->setMonth($month); $talk->setPdf("/pdfs/{$year}_{$month}.pdf"); $talk->setResources(isset($data['resources']) ? $data['resources'] : []); $talk->setSpeaker(isset($data['speaker']) ? $data['speaker'] : ''); $talk->setTitle(isset($data['title']) ? $data['title'] : ''); $talk->setVideo(isset($data['video']) ? $data['video'] : ''); $talk->setTwitter(isset($data['twitter']) ? $data['twitter'] : ''); $talk->setYear($year); if (isset($data['cues'])) { $talk->setCues(array_map(function ($cue) { list($mins, $secs) = explode(':', $cue); return $mins * 60 + $secs; }, $data['cues'])); } return $talk; }