예제 #1
0
<?php

belongs_to('user');
before('validation', 'normalize_name');
validates('name', array('uniqueness' => true));
# TODO: conditions.
has_many('pool_posts', array('model_name' => 'PoolPost', 'order' => 'CAST(sequence AS UNSIGNED), post_id'));
// , 'conditions' => "pools_posts.active"
has_many('all_pool_posts', array('model_name' => 'PoolPost', 'order' => 'CAST(sequence AS UNSIGNED), post_id'));
// m.versioned :name
// m.versioned :description, :default => ""
// m.versioned :is_public, :default => true
// m.versioned :is_active, :default => true
// m.after_undo :update_pool_links
// m.after_save :expire_cache
class Pool extends ActiveRecord
{
    function _construct()
    {
        $this->is_public = !empty($this->is_public);
        $this->is_active = !empty($this->is_active);
    }
    function can_be_updated_by($user)
    {
        return (bool) $this->is_public || $user->has_permission($this);
    }
    static function get_pool_posts_from_posts($posts)
    {
        // post_ids = posts.map { |post| post.id }
        $post_ids = array();
        foreach ($posts as $post) {
예제 #2
0
<?php

belongs_to('creator', array('model_name' => "User", 'foreign_key' => 'creator_id'));
after('create', 'initialize_last_updated_by, update_parent_on_create');
before('validation', 'validate_title, validate_lock');
validates(array('body' => array('length' => array('>1', 'message' => "You need to enter a body"))));
before('destroy', 'update_parent_on_destroy');
has_many('children', array('model_name' => "ForumPost", 'foreign_key' => 'parent_id', 'order' => "id"));
belongs_to('parent_post', array('model_name' => "ForumPost", 'foreign_key' => 'parent_id'));
class ForumPost extends ActiveRecord
{
    static function lock($id)
    {
        # Run raw SQL to skip the lock check
        db::update("forum_posts SET is_locked = TRUE WHERE id = ?", $id);
    }
    static function unlock($id)
    {
        # Run raw SQL to skip the lock check
        db::update("forum_posts SET is_locked = FALSE WHERE id = ?", $id);
    }
    function validate_lock()
    {
        if ($this->root && $this->root->is_locked) {
            $this->record_errors->add_to_base("Thread is locked");
            return false;
        }
        return true;
    }
    static function stick($id)
    {
예제 #3
0
has_one('flag_detail', array('model_name' => "FlaggedPostDetail"));
has_many('notes', array('order' => 'id DESC', 'conditions' => array('is_active = 1')));
before('save', 'commit_tags');
before('create', 'before_creation, set_index_timestamp');
after('create', 'after_creation');
after('delete', 'clear_avatars, give_favorites_to_parent');
has_many('comments', array('order' => "id"));
// m.after_save :save_post_history
// m.has_many :tag_history, :model_name => "PostTagHistory", :table_name => "post_tag_histories", :order => "id desc"
// m.versioned :source, :default => ""
// m.versioned :cached_tags
/* Parent parameters */
after('save', 'update_parent');
// m.validate :validate_parent
// m.versioned :parent_id, :default => nil
has_many('children', array('model_name' => 'Post', 'order' => 'id', 'foreign_key' => 'parent_id', 'conditions' => array("status != 'deleted'")));
before('validation_on_create', 'download_source, ensure_tempfile_exists, determine_content_type, validate_content_type, generate_hash, set_image_dimensions, set_image_status, check_pending_count, generate_sample, generate_jpeg, generate_preview, move_file');
class Post extends ActiveRecord
{
    function _construct()
    {
        $prefix = !CONFIG::download_filename_prefix ? null : CONFIG::download_filename_prefix . ' ';
        $abmd5 = substr($this->md5, 0, 2);
        if ($this->id) {
            $row = DB::select_row("u.name AS author, GROUP_CONCAT(CONCAT(t.name,':',t.tag_type) SEPARATOR ' ') AS cached_tags\n        FROM posts p\n        JOIN posts_tags pt ON p.id = pt.post_id\n        JOIN tags t ON pt.tag_id = t.id\n        JOIN users u ON p.user_id = u.id\n        WHERE pt.post_id = " . $this->id);
            $this->cached_tags = $row['cached_tags'];
            $this->author = $row['author'];
        }
        $this->parsed_cached_tags = $this->parse_cached_tags();
        $this->tags = $this->tag_names();
        $this->parent_id = $this->parent_id ? (int) $this->parent_id : null;