Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

News Articles read by members.


Go to End


3 Posts   852 Views

Avatar
micahsheets

Community Member, 165 Posts

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.

Avatar
Hamish

Community Member, 712 Posts

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.

Avatar
micahsheets

Community Member, 165 Posts

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.