Example #1
0
File: city.php Project: anqh/core
 /**
  * Override __set() to handle JSON.
  *
  * @param   string  $key
  * @param   mixed   $value
  */
 public function __set($key, $value)
 {
     if ($key == 'i18n' && is_array($value)) {
         $value = @json_encode($value);
     }
     parent::__set($key, $value);
 }
Example #2
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();
 }
Example #3
0
 /**
  * Load country
  *
  * @param  integer|string  $id
  */
 public function __construct($id = null)
 {
     parent::__construct();
     if ($id !== null) {
         $this->load(DB::select()->where(is_numeric($id) ? 'id' : 'code', '=', $id));
     }
 }
Example #4
0
 /**
  * Override __set() to handle JSON.
  *
  * @param   string  $key
  * @param   mixed   $value
  */
 public function __set($key, $value)
 {
     if ($key == 'data' && is_array($value) && !$this->is_aggregate()) {
         $value = @json_encode($value);
     }
     parent::__set($key, $value);
 }
Example #5
0
 /**
  * overload __set() to hash a password
  *
  * @return string
  */
 public function __set($key, $value)
 {
     if ($key == 'password') {
         $this->_data[$key] = sha1($value);
         return;
     }
     return parent::__set($key, $value);
 }
Example #6
0
File: topic.php Project: 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();
 }
Example #7
0
 /**
  * Check if field value is unique
  *
  * @param   AutoModeler  $model
  * @param   mixed        $value
  * @param   string       $field
  * @return  boolean
  *
  * @throws  AutoModeler_Exception  if field not found
  */
 public static function unique(AutoModeler $model, $value, $field = null)
 {
     return !$model->unique_key_exists($value, $field);
 }
Example #8
0
 /**
  * Get/set autocommit status
  *
  * @param int $value value to set
  *
  * @return int
  */
 public static function autocommit($value = NULL)
 {
     if (is_null($value)) {
         if (is_null(AutoModeler::$_autocommit)) {
             $query = DB::query(Database::SELECT, 'SELECT @@autocommit AS autocommit');
             AutoModeler::$_autocommit = $query->as_object()->execute()->current()->autocommit;
         }
         return AutoModeler::$_autocommit;
     }
     DB::query(Database::SELECT, 'SET autocommit = ' . (int) $value);
     AutoModeler::$_autocommit = $value;
 }
Example #9
0
 /**
  * Returns all the categories to display in the template
  *
  * @return array
  */
 public function categories()
 {
     return AutoModeler::factory('vendo_product_category')->full_tree();
 }
Example #10
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);
 }
Example #11
0
File: token.php Project: anqh/core
 /**
  * Update user token
  *
  * @return  boolean
  */
 public function update()
 {
     $this->token = $this->create_token();
     return parent::save();
 }
Example #12
0
File: shout.php Project: 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);
 }
Example #13
0
File: form.php Project: 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));
 }
Example #14
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));
 }
Example #15
0
File: topic.php Project: 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;
 }