21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 426 Views |
-
News Articles read by members.

12 June 2009 at 4:40am
I need a way to list a range of news articles so that articles a logged in member has not read show up bold and ones they have read are not bold.
I suppose that this can be done with some sort of database relationship, but I am not sure the best way to do this.
I was thinking of making the News Articles have a static $belongs_many_many relationship to the members but I am not sure how I would set this up so that when a member reads an article it gets put in the belongs_many_many table.
But that is just a guess.
-
Re: News Articles read by members.

12 June 2009 at 9:58am
You'd modify the "index" method of your article controller. You'd also want a 'has current member read this' method. In this example, I'm assuming that the relation is called "MembersRead" Eg:
function index() {
if(Member::currentUser() && !$this->HasBeenRead()) {
$components = $this->MembersRead();
$components->add(Member::currentUser());
$components->write();
}
}function HasBeenRead() {
if(Member::currentUser())
return in_array(array_keys(Member::currentUser()->ID, $this->MembersRead()->getIdList()));
else
return false;
}This is untested, but should give you a head start.
-
Re: News Articles read by members.

13 June 2009 at 3:58am
@Hamish,
Thanks for the tip. I was wondering what the index() function is specifically. It seems that it is run when the controller is instantiated just like init() but it must be different.
| 426 Views | ||
|
Page:
1
|
Go to Top |


