| | 137 | # journal |
|---|
| | 138 | # |
|---|
| | 139 | def my_recent_journal |
|---|
| | 140 | if @user |
|---|
| | 141 | if @used_by_owner |
|---|
| | 142 | # show public, protected, & private items |
|---|
| | 143 | @journals = JournalEntry.paginate_by_user_id(@owner.id, :order => "created_at DESC", :page => params[:page], :per_page => $ITEMS_PER_PAGE) |
|---|
| | 144 | else |
|---|
| | 145 | # show public & protected items |
|---|
| | 146 | # don't use visibility <= 3 because it won't utilize a proper index. |
|---|
| | 147 | @journals = JournalEntry.paginate(:all, |
|---|
| | 148 | :conditions => ['(visibility = ? OR visibility = ?) AND user_id=?', JournalEntry.public, JournalEntry.protected, @owner.id], |
|---|
| | 149 | :order => "created_at DESC", :page => params[:page], :per_page => $ITEMS_PER_PAGE) |
|---|
| | 150 | end |
|---|
| | 151 | else |
|---|
| | 152 | # show only public items |
|---|
| | 153 | @journals = JournalEntry.paginate(:all, :conditions => ['visibility = ? AND user_id=?', JournalEntry.public, @owner.id], |
|---|
| | 154 | :order => "created_at DESC", :page => params[:page], :per_page => $ITEMS_PER_PAGE) |
|---|
| | 155 | end |
|---|
| | 156 | render :layout => false, :partial => "journals/journal_browser", :locals => { |
|---|
| | 157 | :journal_entries => @journals, |
|---|
| | 158 | :div_id => 'my_recent_journal', |
|---|
| | 159 | :latest_url => portal_my_recent_journal_url(:username => @owner.username), |
|---|
| | 160 | :prev_url => portal_my_recent_journal_url(:username => @owner.username, :page => @page - 1), |
|---|
| | 161 | :next_url => portal_my_recent_journal_url(:username => @owner.username, :page => @page + 1), |
|---|
| | 162 | } |
|---|
| | 163 | end |
|---|
| | 164 | |
|---|
| | 165 | def my_journal_monitor |
|---|
| | 166 | |
|---|
| | 167 | if @user |
|---|
| | 168 | @journals = JournalEntry.paginate(:all, |
|---|
| | 169 | :conditions => ['(visibility = ? OR visibility = ?) AND (user_id in (?)) OR ((user_id=?) AND (visibility = ?)) OR ((user_id=?) AND (visibility = ?)) ', JournalEntry.public, JournalEntry.protected, get_following, @owner.id, JournalEntry.public, @owner.id, JournalEntry.protected], |
|---|
| | 170 | :order => "created_at DESC", :page => params[:page], :per_page => $ITEMS_PER_PAGE) |
|---|
| | 171 | else |
|---|
| | 172 | @journals = JournalEntry.paginate(:conditions => ["visibility = ? AND (user_id in (?)) OR ((user_id=?) AND (visibility = ?))", JournalEntry.public, get_following, @owner.id, JournalEntry.public], |
|---|
| | 173 | :order => "created_at DESC", :page => params[:page], :per_page => $ITEMS_PER_PAGE) |
|---|
| | 174 | end |
|---|
| | 175 | render :layout => false, :partial => "journals/journal_browser", :locals => { |
|---|
| | 176 | :journal_entries => @journals, |
|---|
| | 177 | :div_id => 'my_journal_monitor', |
|---|
| | 178 | :latest_url => portal_my_journal_monitor_url(:username => @owner.username), |
|---|
| | 179 | :prev_url => portal_my_journal_monitor_url(:username => @owner.username, :page => @page - 1), |
|---|
| | 180 | :next_url => portal_my_journal_monitor_url(:username => @owner.username, :page => @page + 1), |
|---|
| | 181 | } |
|---|
| | 182 | end |
|---|
| | 183 | |
|---|
| | 184 | def get_following |
|---|
| | 185 | l = [] |
|---|
| | 186 | if (jfriends = JournalFollowing.find_all_by_follower_id(@owner.id)) |
|---|
| | 187 | jfriends.each { |f| l << f.owner_id } |
|---|
| | 188 | end |
|---|
| | 189 | l |
|---|
| | 190 | end |
|---|
| | 191 | |
|---|