예제 #1
0
 public function recent_comments()
 {
     $recent = new Rails\ActiveRecord\Collection();
     # reverse_order to fetch last 6 comments
     # reversed in the last to return from lowest id
     if ($this->comments) {
         $recent->merge(array_slice($this->comments->members(), -6));
     }
     return $recent;
 }
예제 #2
0
파일: Artist.php 프로젝트: JCQS04/myimouto
 public static function find_all_by_url($url)
 {
     $url = ArtistUrl::normalize($url);
     $artists = new Rails\ActiveRecord\Collection();
     while ($artists->blank() && strlen($url) > 10) {
         $u = str_replace('*', '%', $url) . '%';
         $artists->merge(Artist::where("artists.alias_id IS NULL AND artists_urls.normalized_url LIKE ?", $u)->joins("JOIN artists_urls ON artists_urls.artist_id = artists.id")->order("artists.name")->take());
         # Remove duplicates based on name
         $artists->unique('name');
         $url = dirname($url);
     }
     return $artists->slice(0, 20);
 }
예제 #3
0
 public function index()
 {
     $this->set_title('Notes');
     if ($this->params()->post_id) {
         $this->posts = Post::where("id = ?", $this->params()->post_id)->order("last_noted_at DESC")->paginate($this->page_number(), 100);
     } else {
         $this->posts = Post::where("last_noted_at IS NOT NULL")->order("last_noted_at DESC")->paginate($this->page_number(), 16);
     }
     # iTODO:
     $this->respondTo(['html', 'xml' => function () {
         $notes = new Rails\ActiveRecord\Collection();
         foreach ($this->posts as $post) {
             $notes->merge($post->notes);
         }
         $this->render(['xml' => $notes, 'root' => "notes"]);
     }, 'json' => function () {
         // {render :json => @posts.map {|x| x.notes}.flatten.to_json}
     }]);
 }
예제 #4
0
 public function index()
 {
     $this->set_title('Comments');
     if ($this->request()->format() == "json" || $this->request()->format() == "xml") {
         $this->comments = Comment::generate_sql($this->params()->all())->order("id DESC")->paginate($this->page_number(), 25);
         $this->respond_to_list("comments");
     } else {
         $this->posts = Post::where("last_commented_at IS NOT NULL")->order("last_commented_at DESC")->paginate($this->page_number(), 10);
         $comments = new Rails\ActiveRecord\Collection();
         $this->posts->each(function ($post) use($comments) {
             $comments->merge($post->recent_comments());
         });
         $newest_comment = $comments->max(function ($a, $b) {
             return $a->created_at > $b->created_at ? $a : $b;
         });
         if (!current_user()->is_anonymous() && $newest_comment && current_user()->last_comment_read_at < $newest_comment->created_at) {
             current_user()->updateAttribute('last_comment_read_at', $newest_comment->created_at);
         }
         $this->posts->deleteIf(function ($x) {
             return !$x->can_be_seen_by(current_user(), array('show_deleted' => true));
         });
     }
 }