Exemplo n.º 1
0
 /**
  * Add a Newsfeed item.
  *
  * @static
  * @param   Model_User  $user
  * @param   string      $class  e.g. 'user'
  * @param   string      $type   e.g. 'login'
  * @param   array       $data   Data to be user with item
  * @return  boolean
  */
 protected static function add(Model_User $user, $class, $type, array $data = null)
 {
     $item = AutoModeler::factory('newsfeeditem');
     $item->set_fields(array('user_id' => $user->id, 'class' => $class, 'type' => $type, 'data' => $data, 'stamp' => time()));
     $item->save();
     return $item->loaded();
 }
Exemplo n.º 2
0
Arquivo: topic.php Projeto: anqh/forum
 /**
  * Action: index
  */
 public function action_index()
 {
     // Go to post?
     $topic_id = (int) $this->request->param('topic_id');
     if ($topic_id) {
         $post_id = (int) $this->request->param('id');
     } else {
         $topic_id = (int) $this->request->param('id');
     }
     // Load topic
     /** @var  Model_Forum_Private_Topic|Model_Forum_Topic  $topic */
     $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
     if (!$topic->loaded()) {
         throw new Model_Exception($topic, $topic_id);
     }
     Permission::required($topic, Model_Forum_Topic::PERMISSION_READ, self::$user);
     // Did we request single post with ajax?
     if (($this->ajax || $this->internal) && isset($post_id)) {
         $this->history = false;
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded()) {
             throw new Model_Exception($topic, $topic_id);
         }
         // Permission is already checked by the topic, no need to check for post
         $this->response->body($this->section_post($topic, $post));
         return;
     }
     // Update counts
     if ($this->private) {
         $topic->mark_as_read(self::$user);
     }
     if (!self::$user || $topic->author_id != self::$user->id) {
         $topic->read_count++;
         $topic->save();
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title_html = Forum::topic($topic);
     $this->view->subtitle = __($topic->post_count == 1 ? ':posts post' : ':posts posts', array(':posts' => Num::format($topic->post_count, 0)));
     $this->view->tab = 'topic';
     $this->page_actions['topic'] = array('link' => Route::model($topic), 'text' => '<i class="icon-comment icon-white"></i> ' . __('Topic'));
     // Public topic extras
     if (!$this->private) {
         // Quotes are supported only in public forum as we get notifications anyway in private
         if (self::$user) {
             $quotes = Model_Forum_Quote::factory()->find_by_user(self::$user);
             if (count($quotes)) {
                 foreach ($quotes as $quote) {
                     if ($topic->id == $quote->forum_topic_id) {
                         $quote->delete();
                         break;
                     }
                 }
             }
         }
         // Facebook
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', $topic->name);
             Anqh::open_graph('url', URL::site(Route::url('forum_topic', array('id' => $topic->id, 'action' => '')), true));
         }
         Anqh::share(true);
         // Model binding
         $area = $topic->area();
         if ($area->type == Model_Forum_Area::TYPE_BIND && $topic->bind_id) {
             if ($bind = Model_Forum_Area::get_binds($area->bind)) {
                 $model = AutoModeler::factory($bind['model'], $topic->bind_id);
                 if ($model->loaded()) {
                     // Set actions
                     $this->page_actions[] = array('link' => Route::model($model), 'text' => $bind['link']);
                     // Set views
                     foreach ((array) $bind['view'] as $view) {
                         $this->view->add(View_Page::COLUMN_SIDE, View_Module::factory($view, array($bind['model'] => $model)), Widget::TOP);
                     }
                 }
             }
         }
     }
     // Public topic extras
     // Set actions
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $this->view->actions[] = array('link' => Request::current_uri() . '#reply', 'text' => '<i class="icon-comment icon-white"></i> ' . __('Reply to topic'), 'class' => 'btn btn-primary topic-post');
     }
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($topic, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit topic'));
     }
     // Breadcrumbs
     $this->page_breadcrumbs[] = HTML::anchor(Route::url('forum_group'), __('Forum'));
     $this->page_breadcrumbs[] = HTML::anchor(Route::model($topic->area()), $topic->area()->name);
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination = $this->section_pagination($topic));
     $this->view->subtitle .= ', ' . __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0)));
     $this->view->subtitle .= ', ' . __($topic->read_count == 1 ? ':views view' : ':views views', array(':views' => Num::format($topic->read_count, 0)));
     // Go to post?
     if (isset($post_id)) {
         $pagination->item($topic->get_post_number($post_id) + 1);
         // We need to set pagination urls manually if jumped to a post
         $pagination->base_url = Route::model($topic);
     }
     // Recipients
     if ($this->private) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_recipients($topic));
         $this->view->add(View_Page::COLUMN_MAIN, '<hr />');
     }
     // Posts
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_topic($topic, $pagination));
     // Reply
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $section = $this->section_post_edit(View_Forum_PostEdit::REPLY, $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory());
         $section->forum_topic = $topic;
         $this->view->add(View_Page::COLUMN_MAIN, $section);
     }
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination);
     $this->_side_views();
 }
Exemplo n.º 3
0
 /**
  * Returns all the categories to display in the template
  *
  * @return array
  */
 public function categories()
 {
     return AutoModeler::factory('vendo_product_category')->full_tree();
 }
Exemplo n.º 4
0
 /**
  * Find all objectcs
  *
  * @return  Database_Result
  */
 public function find_all()
 {
     return AutoModeler::factory(Model::model_name(get_called_class()))->load(null, null);
 }
Exemplo n.º 5
0
 /**
  * Removes a parent relationship of a belongs_to
  *
  * @param string $key the model name to look for in plural form, without Model_ prefix
  *
  * @return integer
  */
 public function remove_parent($key)
 {
     return db::delete(AutoModeler::factory(inflector::singular($key))->get_table_name() . '_' . $this->_table_name)->where(inflector::singular($this->_table_name) . '_id', '=', $this->id)->execute($this->_db);
 }
Exemplo n.º 6
0
Arquivo: shout.php Projeto: anqh/core
 /**
  * Find latest shouts
  *
  * @static
  * @param   integer  $limit
  * @return  Database_Result
  */
 public static function find_latest($limit = 10)
 {
     return AutoModeler::factory('shout')->load(DB::select()->order_by('id', 'DESC'), $limit);
 }
Exemplo n.º 7
0
Arquivo: form.php Projeto: vendo/admin
 /**
  * Gets a safe version of the product
  *
  * @return array
  */
 public function product()
 {
     return $this->product->as_array() + array('product_categories' => AutoModeler::factory('vendo_product_category')->full_tree(NULL, FALSE, $this->product));
 }
Exemplo n.º 8
0
 /**
  * Tests generating an array output for an html select list
  *
  * @test
  * @dataProvider provider_select_list
  * @covers AutoModeler::select_list
  */
 public function test_select_list($key, $display, $query, $expected)
 {
     $this->assertSame($expected, AutoModeler::factory('testuser')->select_list($key, $display, $query));
 }
Exemplo n.º 9
0
Arquivo: topic.php Projeto: anqh/anqh
 /**
  * Get bound model.
  *
  * @return  Model
  */
 public function bind_model()
 {
     if ($bind_config = $this->area()->bind_config()) {
         $model = AutoModeler::factory($bind_config['model'], $this->bind_id);
         return $model && $model->loaded() ? $model : null;
     }
     return null;
 }