本文整理汇总了PHP中Topic::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::find方法的具体用法?PHP Topic::find怎么用?PHP Topic::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$topic = Topic::find($id);
$topic->increment('views');
$posts = $topic->posts;
return View::make('topic')->with('topic', $topic)->with('posts', $posts);
}
示例2: beforeSave
public function beforeSave($options = array())
{
//parent::beforeSave($options);
//print_r($this->data);
$loggedInUser = AuthComponent::user();
$found = false;
$userId = $loggedInUser['user_id'];
$this->data['Post']['post_by'] = $userId;
$this->data['Post']['post_date'] = (new DateTime())->format('Y-m-d');
//format('Y-m-d H:i:s')
if (!empty($this->data['Topic']['topic_subject'])) {
$str = $this->data['Topic']['topic_subject'];
$num = $this->data['Post']['post_cat'];
$subject = new Topic();
$found = $subject->find('first', array('conditions' => array('Topic.topic_subject LIKE' => $str, 'Topic.topic_cat =' => $num)));
if (!$found) {
$subject->create();
//create topic
$subject->save(array('topic_subject' => $this->data['Topic']['topic_subject'], 'topic_date' => (new DateTime())->format('Y-m-d'), 'topic_cat' => $this->data['Post']['post_cat'], 'topic_by' => $userId));
//see also save associated model method cakephp
$this->data['Post']['post_topic'] = $this->Topic->getLastInsertId();
return true;
}
$this->data['Post']['post_topic'] = $found['Topic']['topic_id'];
return true;
}
//nothing
return true;
}
示例3: show
public function show($id = null)
{
$data = [];
$data['topic'] = Topic::find($id);
$data['answers'] = $data['topic']->answers()->orderBy('created_at', 'desc')->get();
return View::make('forum::topic_show', $data);
}
示例4: topicDetail
public function topicDetail()
{
$topic_id = Input::get('topic_id');
$topic = Topic::find($topic_id);
if (!isset($topic)) {
return Response::view('errors.missing');
}
//预载入
$gifts = Gift::where('topic_id', $topic->id)->with(['giftPosters' => function ($query) {
$query->orderBy('created_at', 'asc');
}])->get();
$number = 1;
foreach ($gifts as $gift) {
$gift->img = $gift->giftPosters[0]->url;
$gift->number = $number++;
}
// $gifts = Gift::where('topic_id', '=', $topic->id)->get();
// if(isset($gifts))
// { $number = 1;
// foreach($gifts as $gift)
// {
// $url = GiftPoster::where('gift_id','=',$gift->id)->first()->url;
// // $gift->img = StaticController::imageWH($url);
// $gift->img = $url;
// $gift->number = $number++;
// }
// }
$gifts = $this->isGiftLike($gifts);
$type = $this->isTopicLike($topic_id);
return View::make('pc.subject')->with(array('topic' => $topic, 'gifts' => $gifts, 'type' => $type));
}
示例5: getTopicCommentMore
public function getTopicCommentMore()
{
$topic_id = Input::get('topic_id');
$topic = Topic::find($topic_id);
$comments = $topic->hasManyTopicComments;
return View::make('话题评论内容')->with('comments', $comments)->with('links', $this->link());
}
示例6: getDayTopViewPosts
public static function getDayTopViewPosts($start = 0, $limit = 10)
{
Counter::checkAll(Topic::ENTITY_TYPE);
$query = Topic::find()->join("user")->join("group")->join("rating")->join("counter");
$query = $query->order("desc", "[Counter.dayCount]")->where("[Counter.dayCount]>0");
$results = $query->range($start, $limit);
return $results;
}
示例7: test_find
function test_find()
{
$name = "Writing";
$test_topic = new Topic($name);
$test_topic->save();
$name2 = "Interview";
$test_topic2 = new Topic($name2);
$test_topic2->save();
$result = Topic::find($test_topic->getId());
$this->assertEquals($test_topic, $result);
}
示例8: createOrDelete
public function createOrDelete($id)
{
$topic = Topic::find($id);
if (Favorite::isUserFavoritedTopic(Auth::user(), $topic)) {
Auth::user()->favoriteTopics()->detach($topic->id);
} else {
Auth::user()->favoriteTopics()->attach($topic->id);
Notification::notify('topic_favorite', Auth::user(), $topic->user, $topic);
}
Flash::success(lang('Operation succeeded.'));
return Redirect::route('topics.show', $topic->id);
}
示例9: addMessage
/**
* addMessage-funktio lähettää User mallille käskyn lisätä uusi viesti parametrina saatuun keskusteluun,jos viesti on tyhjä lähetetään virheilmoitus
*/
public static function addMessage($id)
{
$params = $_POST;
if ($params['content'] != null && !ctype_space($params['content'])) {
$message = Message::createMessage($id, $params['content']);
$messages = Message::all($id);
$topic = Topic::find($id);
View::make('keskustelu.html', array('topic' => $topic, 'messages' => $messages));
}
$messages = Message::all($id);
$topic = Topic::find($id);
View::make('keskustelu.html', array('topic' => $topic, 'messages' => $messages, 'error' => 'Viestisi oli tyhjä'));
}
示例10: createOrDelete
public function createOrDelete($id)
{
$topic = Topic::find($id);
if (Attention::isUserAttentedTopic(Auth::user(), $topic)) {
$message = lang('Successfully remove attention.');
Auth::user()->attentTopics()->detach($topic->id);
} else {
$message = lang('Successfully_attention');
Auth::user()->attentTopics()->attach($topic->id);
Notification::notify('topic_attent', Auth::user(), $topic->user, $topic);
}
Flash::success($message);
return Redirect::route('topics.show', $topic->id);
}
示例11: getActivePostsCount
/**
* TODO: how to define active posts?
*
* Now the method count all posts in a given category
* @param null $categoryId
* @return mixed
*/
public function getActivePostsCount($categoryId = null)
{
$query = Topic::find()->join("group");
if ($categoryId !== null) {
$this->id = $categoryId;
$subs = $this->children();
$where = "[Group.categoryId] IN (?";
$args = [$categoryId];
for ($i = 0, $count = count($subs); $i < $count; $i++) {
$where .= ',?';
$args[] = $subs[$i]->id;
}
$where .= ')';
$query = $query->where($where, $args);
}
return $query->count();
}
示例12: actionDetail
/**
* View group detail
* @param $groupId
*/
public function actionDetail($groupId)
{
$group = Group::get($groupId);
RAssert::not_null($group);
$group->category = Category::get($group->categoryId);
$group->groupCreator = User::get($group->creator);
$counter = $group->increaseCounter();
// get latest 20 posts in the group
$posts = Topic::find("groupId", $groupId)->join("user")->order_desc("createdTime")->range(0, 20);
$data = ['group' => $group, 'counter' => $counter->totalCount, 'latestPosts' => $posts];
$isLogin = Rays::isLogin();
$data['hasJoined'] = $isLogin && GroupUser::isUserInGroup(Rays::user()->id, $group->id);
$data['isManager'] = $isLogin && $group->creator == Rays::user()->id;
$this->setHeaderTitle($group->name);
$this->addCss("/public/css/post.css");
$this->render('detail', $data, false);
}
示例13: forumIdWrite
public function forumIdWrite($id)
{
$json = Input::get('json');
$data = json_decode($json);
$writer = Student::where('auth', '=', $data->auth)->first();
$sn = Topic::max('sn') + 1;
$body = base64_decode($data->body);
$topics = Topic::find($id);
$topics->sn = $sn;
$topics->save();
$commit = new Commit();
$commit->stu_id = $writer->id;
$commit->topic_id = $id;
$commit->body = $body;
$commit->day = date("Y/m/d");
$commit->save();
return "suc";
}
示例14: getUserPlusTopics
public static function getUserPlusTopics($userId, $start = 0, $limit = 0)
{
$ratings = Rating::find(["entityType", Topic::ENTITY_TYPE, "userId", $userId, "valueType", self::VALUE_TYPE, "value", self::VALUE, "tag", self::TAG])->all();
if ($ratings == null || empty($ratings)) {
return array();
}
$query = Topic::find()->join("user")->join("group")->order_desc("id");
if ($ratings != null && !empty($ratings)) {
$where = "[id] in (";
$args = array();
for ($count = count($ratings), $i = 0; $i < $count; $i++) {
$where .= "?" . ($i < $count - 1 ? "," : "");
$args[] = $ratings[$i]->entityId;
}
unset($ratings);
$where .= ")";
$query = $query->where($where, $args);
}
return $start != 0 || $limit != 0 ? $query->range($start, $limit) : $query->all();
}
示例15: getUserLikePosts
public static function getUserLikePosts($userId, $start = 0, $limit = 0)
{
$likes = RatingLike::find(["entityType", Topic::ENTITY_TYPE, "userId", $userId])->all();
$query = Topic::find()->order_desc("id");
if (!empty($likes)) {
$args = [];
$where = "[id] in (";
for ($i = 0, $count = count($likes); $i < $count; $i++) {
$args[] = $likes[$i]->entityId;
$where .= '?' . ($i < $count - 1) ? "," : "";
}
unset($likes);
$where .= ")";
$query = $query->where($where, $args);
}
if ($start != 0 || $limit != 0) {
return $query->range($start, $limit);
} else {
return $query->all();
}
}