<?php belongs_to('post'); belongs_to('user'); class FlaggedPostDetail extends ActiveRecord { function _construct() { // if ($this->found()) { // $this->author = $this->user->name; // } // $this->create_api_attributes(); } function flagged_by() { if (empty($this->flagged_by)) { if (empty($this->user_id)) { $this->flagged_by = "system"; } else { $this->flagged_by = User::find_name($this->user_id); } } return $this->flagged_by; } function api_attributes() { $api_attributes = array('post_id', 'reason', 'created_at', 'user_id', 'flagged_by'); $api_attributes = array_fill_keys($api_attributes, null); foreach (array_keys($api_attributes) as $attr) { if ($attr == 'flagged_by') { $this->flagged_by();
<?php belongs_to('predicate', array('model_name' => 'Tag')); belongs_to('consequent', array('model_name' => 'Tag')); before('create', 'validate_uniqueness'); class TagImplication extends ActiveRecord { function validate_uniqueness() { $this->predicate_is($this->predicate); $this->consequent_is($this->consequent); if (self::find('first', array('conditions' => array("(predicate_id = ? AND consequent_id = ?) OR (predicate_id = ? AND consequent_id = ?)", $this->predicate_id, $this->consequent_id, $this->consequent_id, $this->predicate_id)))) { $this->record_errors->add_to_base("Tag implication already exists"); return false; } } function predicate_is($name) { $t = Tag::find_or_create_by_name($name); $this->predicate_id = $t->id; } function consequent_is($name) { $t = Tag::find_or_create_by_name($name); $this->consequent_id = $t->id; } function destroy_and_notify($current_user, $reason) { # TODO: if (!empty($this->creator_id) && $this->creator_id != $current_user->id) { // msg = "A tag implication you submitted (#{predicate.name} → #{consequent.name}) was deleted for the following reason: #{reason}."
<?php $table_name = "post_votes"; belongs_to('post', array('foreign_key' => 'post_id')); belongs_to('user', array('foreign_key' => 'user_id')); class PostVotes extends ActiveRecord { function find_by_ids($user_id, $post_id) { $this->find('first', array('conditions' => array("user_id = ? AND post_id = ?", $user_id, $post_id))); } function find_or_create_by_id($user_id, $post_id) { $entry = $this->find_by_ids(array('user_id' => $user_id, 'post_id' => $post_id)); return $entry ? $entry : $this->create(array('user_id' => $user_id, 'post_id' => $post_id)); } }
<?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) {
<?php include_model('ban, tag, user_blacklisted_tag'); has_one('ban', array('foreign_key' => 'user_id')); has_one('user_blacklisted_tag'); belongs_to('avatar_post', array('model_name' => "Post", 'foreign_key' => 'avatar_post_id')); before('validation', 'commit_secondary_languages'); before('create', 'can_signup, set_role'); before('save', 'encrypt_password'); after('create', 'set_default_blacklisted_tags, increment_count'); after('save', 'commit_blacklists'); after('destroy', 'decrement_count'); validates(array('name' => array('length' => '2..20', 'format' => array('/\\A[^\\s;,]+\\Z/', 'on' => 'create', 'message' => 'cannot have whitespace, commas, or semicolons'), 'uniqueness' => array(true, 'on' => 'create')), 'password' => array('length' => array('>=5', 'if' => array('property_exists' => 'password')), 'confirmation' => true))); // # validates_format_of :name, :with => /^(Anonymous|[Aa]dministrator)/, :on => :create, :message => "this is a disallowed username" // m.after_save :update_cached_name if CONFIG["enable_caching"] // m.has_many :tag_subscriptions, :dependent => :delete_all, :order => "name" // m.validates_format_of :language, :with => /^([a-z\-]+)|$/ // m.validates_format_of :secondary_languages, :with => /^([a-z\-]+(,[a-z\0]+)*)?$/ class User extends ActiveRecord { static $current; function _construct() { if (isset($this->is_anonymous)) { return; } elseif (isset($this->id)) { $this->is_anonymous = false; } // if(CONFIG::show_samples) // $this->show_samples = false; }
<?php belongs_to('author', array('model_name' => 'User')); class NoteVersion extends ActiveRecord { function to_xml($options = array()) { // {:created_at => created_at, :updated_at => updated_at, :creator_id => user_id, :x => x, :y => y, :width => width, :height => height, :is_active => is_active, :post_id => post_id, :body => body, :version => version}.to_xml(options.reverse_merge(:root => "note_version")) } function to_json($args = null) { return to_json(array('created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'creator_id' => $this->user_id, 'x' => $this->x, 'y' => $this->y, 'width' => $this->width, 'height' => $this->height, 'is_active' => $this->is_active, 'post_id' => $this->post_id, 'body' => $this->body, 'version' => $this->version)); } }
<?php $table_name = 'pools_posts'; belongs_to('post', array('joins' => ' JOIN users ON posts.user_id = users.id JOIN posts_tags ON posts.id = posts_tags.post_id JOIN tags ON posts_tags.tag_id = tags.id ')); belongs_to('next_post', array('model_name' => "Post", 'foreign_key' => "next_post_id")); belongs_to('prev_post', array('model_name' => "Post", 'foreign_key' => "prev_post_id")); class PoolPost extends ActiveRecord { function _construct() { $this->active = true; $this->sequence = (string) $this->sequence; // $this->api_attributes = array_fill_keys($this->api_attributes, ''); } function api_attributes() { $api_attributes = array('id', 'pool_id', 'post_id', 'active', 'sequence', 'next_post_id', 'prev_post_id'); $api_attributes = array_fill_keys($api_attributes, null); foreach (array_keys($api_attributes) as $attr) { // # TODO: Don't know what 'active' is about. It's a "versioned". if (isset($this->{$attr})) { $api_attributes[$attr] = $this->{$attr}; } } return $api_attributes; } function can_change_is_public($user) { return $user->has_permission($pool); # only the owner can change is_public }