Skip to content
ProLoser edited this page Sep 14, 2010 · 7 revisions

Checking Ownership (Controller Function)

function _owner($id)

Checks to see if the current user is the owner of the record and sets a boolean variable to the view

  • $id int The record id to be checked for ownership of. Only checks the current model

Checking Subscription (Controller Function)

function _subscriber($id)

Checks to see if the current user is a subscriber and sends subscription info to the view

  • $id int The record id to be checked for subscription to. Only checks on the current model

Granting Points (Model Function)

function grantPoints($event, $userId, $foreignId = null)

Function for granting a user points via a point event. Requires that you pass a string id key for the point event and the target user’s id.

  • $event string The PointEvent.id key that the user is being given points for
  • $userId int The User.id key that is being given points
  • $foreignId int Optional primary id of the related model-record that earned the points

Example in the User model

function afterSave($created) {
	if ($created) {
		$this->grantPoints(
			'user-register',
			$this->id
		);
	}
}

Example in the Review model

function afterSave($created) {
	if ($created) {
		$this->User->grantPoints(
			'create-review', 
			$this->data['Review']['user_id'],
			$this->id
		);
	}
}

Clone this wiki locally