/** * Assigns an authorization item to a user making sure that * the user doesn't already have this assignment. * Overloads the parent method to make sure that * we do not assign already assigned items. * @param string $itemName the item name. * @param mixed $userId the user ID (see {@link IWebUser::getId}) * @param string $bizRule the business rule to be executed when {@link checkAccess} is called * for this particular authorization item. * @param mixed $data additional data associated with this assignment. * @return CAuthAssignment the authorization assignment information. * @throws CException if the item does not exist or if the item has already been assigned to the user. */ public function assign($itemName, $userId, $bizRule = null, $data = null) { // Make sure that this user doesn't already have this assignment. if ($this->getAuthAssignment($itemName, $userId) === null) { return parent::assign($itemName, $userId, $bizRule, $data); } }
/** * Removes cache before assigning a new auth item * @param string $itemName the item name * @param mixed $userId the user ID (see {@link IWebUser::getId}) * @param string $bizRule the business rule to be executed when {@link checkAccess} is called * for this particular authorization item. * @param mixed $data additional data associated with this assignment * @return CAuthAssignment the authorization assignment information. * @throws CException if the item does not exist or if the item has already been assigned to the user * @throws CExeption if the application component could not be loaded. */ public function assign($itemName, $userId, $bizRule = null, $data = null) { if (Yii::app()->getComponent($this->cacheID) !== null) { Yii::app()->getComponent($this->cacheID)->delete($this->cacheID . '_' . $itemName . '_' . $userId); return parent::assign($itemName, $userId, $bizRule, $data); } else { throw new CException('Application component ' . $this->cacheID . ' could not be loaded.'); } }