/** * Process posting a reply to an existing thread */ public function post_reply() { // validate data $data = Input::get(); $rules = array('thread_id' => 'required', 'reply' => 'required'); $val = Validator::make($data, $rules); if ($val->fails()) { Session::flash('status', 'reply-fail'); return Redirect::to('/'); } else { // make the post $post = new Post(); $user = Auth::user(); // add the info $post->user_id = $user->id; $post->thread_id = $data['thread_id']; $post->body = $data['reply']; $post->save(); // add to the users posts count $user->posts++; $user->save(); // add to the reply count in the thread $thread = Thread::find($data['thread_id']); $thread->postcount++; $thread->save(); // notification for user Session::flash('status', 'new-post'); // we are done, go back to the thread return Redirect::to('thread/view/' . $data['thread_id']); } }
/** * testGroupBy method * * These tests will never pass with Postgres or Oracle as all fields in a select must be * part of an aggregate function or in the GROUP BY statement. * * @access public * @return void */ function testGroupBy() { $db = ConnectionManager::getDataSource('test'); $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle', 'sqlite')); $message = '%s Postgres and Oracle have strict GROUP BY and are incompatible with this test.'; if ($this->skipIf($isStrictGroupBy, $message)) { return; } $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); $Thread = new Thread(); $Product = new Product(); $result = $Thread->find('all', array('group' => 'Thread.project_id', 'order' => 'Thread.id ASC')); $expected = array(array('Thread' => array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), 'Project' => array('id' => 1, 'name' => 'Project 1'), 'Message' => array(array('id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1'))), array('Thread' => array('id' => 3, 'project_id' => 2, 'name' => 'Project 2, Thread 1'), 'Project' => array('id' => 2, 'name' => 'Project 2'), 'Message' => array(array('id' => 3, 'thread_id' => 3, 'name' => 'Thread 3, Message 1')))); $this->assertEqual($result, $expected); $rows = $Thread->find('all', array('group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total'))); $result = array(); foreach ($rows as $row) { $result[$row['Thread']['project_id']] = $row[0]['total']; } $expected = array(1 => 2, 2 => 1); $this->assertEqual($result, $expected); $rows = $Thread->find('all', array('group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), 'order' => 'Thread.project_id')); $result = array(); foreach ($rows as $row) { $result[$row['Thread']['project_id']] = $row[0]['total']; } $expected = array(1 => 2, 2 => 1); $this->assertEqual($result, $expected); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id')); $expected = array(array('Thread' => array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), 'Project' => array('id' => 1, 'name' => 'Project 1'), 'Message' => array(array('id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1')))); $this->assertEqual($result, $expected); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id, Project.id')); $this->assertEqual($result, $expected); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => 'project_id')); $this->assertEqual($result, $expected); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => array('project_id'))); $this->assertEqual($result, $expected); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => array('project_id', 'Project.id'))); $this->assertEqual($result, $expected); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => array('Thread.project_id', 'Project.id'))); $this->assertEqual($result, $expected); $expected = array(array('Product' => array('type' => 'Clothing'), array('price' => 32)), array('Product' => array('type' => 'Food'), array('price' => 9)), array('Product' => array('type' => 'Music'), array('price' => 4)), array('Product' => array('type' => 'Toy'), array('price' => 3))); $result = $Product->find('all', array('fields' => array('Product.type', 'MIN(Product.price) as price'), 'group' => 'Product.type', 'order' => 'Product.type ASC')); $this->assertEqual($result, $expected); $result = $Product->find('all', array('fields' => array('Product.type', 'MIN(Product.price) as price'), 'group' => array('Product.type'), 'order' => 'Product.type ASC')); $this->assertEqual($result, $expected); }
/** * testGroupBy method * * These tests will never pass with Postgres or Oracle as all fields in a select must be * part of an aggregate function or in the GROUP BY statement. * * @return void */ public function testGroupBy() { $db = ConnectionManager::getDataSource('test'); $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver; $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.'; $this->skipIf($isStrictGroupBy, $message); $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); $Thread = new Thread(); $Product = new Product(); $result = $Thread->find('all', array('group' => 'Thread.project_id', 'order' => 'Thread.id ASC')); $expected = array(array('Thread' => array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), 'Project' => array('id' => 1, 'name' => 'Project 1'), 'Message' => array(array('id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1'))), array('Thread' => array('id' => 3, 'project_id' => 2, 'name' => 'Project 2, Thread 1'), 'Project' => array('id' => 2, 'name' => 'Project 2'), 'Message' => array(array('id' => 3, 'thread_id' => 3, 'name' => 'Thread 3, Message 1')))); $this->assertEquals($expected, $result); $rows = $Thread->find('all', array('group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total'))); $result = array(); foreach ($rows as $row) { $result[$row['Thread']['project_id']] = $row[0]['total']; } $expected = array(1 => 2, 2 => 1); $this->assertEquals($expected, $result); $rows = $Thread->find('all', array('group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), 'order' => 'Thread.project_id')); $result = array(); foreach ($rows as $row) { $result[$row['Thread']['project_id']] = $row[0]['total']; } $expected = array(1 => 2, 2 => 1); $this->assertEquals($expected, $result); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id')); $expected = array(array('Thread' => array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), 'Project' => array('id' => 1, 'name' => 'Project 1'), 'Message' => array(array('id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1')))); $this->assertEquals($expected, $result); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id, Project.id')); $this->assertEquals($expected, $result); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => 'project_id')); $this->assertEquals($expected, $result); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => array('project_id'))); $this->assertEquals($expected, $result); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => array('project_id', 'Project.id'))); $this->assertEquals($expected, $result); $result = $Thread->find('all', array('conditions' => array('Thread.project_id' => 1), 'group' => array('Thread.project_id', 'Project.id'))); $this->assertEquals($expected, $result); $expected = array(array('Product' => array('type' => 'Clothing'), array('price' => 32)), array('Product' => array('type' => 'Food'), array('price' => 9)), array('Product' => array('type' => 'Music'), array('price' => 4)), array('Product' => array('type' => 'Toy'), array('price' => 3))); $result = $Product->find('all', array('fields' => array('Product.type', 'MIN(Product.price) as price'), 'group' => 'Product.type', 'order' => 'Product.type ASC')); $this->assertEquals($expected, $result); $result = $Product->find('all', array('fields' => array('Product.type', 'MIN(Product.price) as price'), 'group' => array('Product.type'), 'order' => 'Product.type ASC')); $this->assertEquals($expected, $result); }
public static function check_thread_rights($thread_id) { $user = self::get_user_logged_in(); $thread = new Thread(Thread::find($thread_id)); $id = $thread->user_id; if ($user->userrole != 'ADMIN' && $user->id != $id) { Redirect::to('/', array('message' => 'You have no authority to perform that action.')); } }
public static function addMessage($thread_id) { $params = $_POST; $time = date('Y-m-d G:i:s'); $attributes = array('content' => $params['content'], 'created' => $time, 'user_id' => $_SESSION['user'], 'thread_id' => $thread_id); $message = new Message($attributes); $errors = $message->errors(); if (count($errors) == 0) { $message->save(); //Updating lastpost of thread $thread = new Thread(Thread::find($thread_id)); $thread->updateLastpost($time); //Updating participants list $user = new ForumUser(ForumUser::find($_SESSION['user'])); ForumUser::changePostAmount($user->id, $thread_id, 1); Redirect::to('/thread/' . $thread_id); } else { $thread = new Thread(Thread::find($thread_id)); View::make('message/message_create.html', array('thread' => $thread, 'errors' => $errors, 'attributes' => $attributes)); } }
public function managepost($id, $name) { $id_len = strlen($id); $forum_id = substr($id, 0, 1); $thread_id = substr($id, 1, $id_len - 1); $thread = Thread::find($thread_id); $user_id = Session::get('WebUserId'); if (Input::get('submit') == 'post') { if (Input::get('text') != '') { $post = new Post(); $post->text = Input::get('text'); $post->webuser_id = $user_id; $post->thread_id = $thread_id; $post->save(); $thread->updated_at = time(); $thread->lastuser_id = $user_id; $thread->save(); $view = ForumViewCount::find($forum_id); $view->post = $view->post + 1; $view->save(); } } elseif (Input::get('submit') == 'manage') { if (Input::get('action') == 'close') { $thread->status = 1; $thread->icon = 'lock'; $thread->save(); } else { if (Input::get('action') == 'open') { $thread->status = 2; $thread->icon = 'lock-open'; $thread->save(); } else { if (Input::get('action') == 'stick') { $thread->status = 3; $thread->icon = 'publish'; $thread->save(); } else { if (Input::get('action') == 'unstick') { $thread->status = 2; $thread->icon = 'chat'; $thread->save(); } else { if (Input::get('action') == 'del') { $thread->status = 0; $thread->save(); return Redirect::to('/dien-dan.html'); } } } } } } elseif (Input::get('postid') != NULL) { $postedit = Post::find(Input::get('postid')); $postedit->text = Input::get('text'); $postedit->save(); } elseif (Input::get('submit') == 'editthread') { $thread->title = Input::get('title'); $thread->forum = Input::get('destination'); $thread->save(); } return Redirect::to("/dien-dan/" . $id . "/" . $name); }
function get_thread_status($threadid) { //--Konunun Açık,Kapalı,Silinmiş ya da görünmez olduğunu öğrenmek için. $thread = Thread::find($threadid)->first(); return $thread->type; }
public function get_id($id = 0) { if (!empty($id)) { $entry = Post::with('author')->where_id($id)->first(); } /*Getting the thread*/ $thread = Thread::find($entry->thread_id); if (Request::ajax()) { $view = View::make('entry.one-entryajax'); $view->entry = $entry; $view->thread = $thread; return $view; } else { $view = View::make('entry.one-entry'); $view->title = '#' . $entry->id . ' ' . substr(strip_tags(trim(strtolower($entry->entry))), 0, 20) . " ... "; $view->entry = $entry; $view->thread = $thread; return $view; } }
public static function destroyThread($id) { $thread = new Thread(Thread::find($id)); $thread->delete(); Redirect::to('/thread', array('message' => 'Thread deleted.')); }