/** * Checks if a user has a certain permission in the given survey * * @param $iSurveyID integer The survey ID * @param $sPermission string Name of the permission * @param $sCRUD string The permission detail you want to check on: 'create','read','update','delete','import' or 'export' * @param $iUserID integer User ID - if not given the one of the current user is used * @return bool True if user has the permission */ public function hasSurveyPermission($iSurveyID, $sPermission, $sCRUD = 'read', $iUserID = null) { $oSurvey = Survey::Model()->findByPk($iSurveyID); if (!$oSurvey) { return false; } // Get global correspondance for surveys rigth $sGlobalCRUD = $sCRUD == 'create' || $sCRUD == 'delete' && $sPermission != 'survey' ? 'update' : $sCRUD; return $this->hasGlobalPermission('surveys', $sGlobalCRUD, $iUserID) || $this->hasPermission($iSurveyID, 'survey', $sPermission, $sCRUD, $iUserID); }
/** * Checks if a user has a certain permission in the given survey * * @param $iSurveyID integer The survey ID * @param $sPermission string Name of the permission * @param $sCRUD string The permission detail you want to check on: 'create','read','update','delete','import' or 'export' * @param $iUserID integer User ID - if not given the one of the current user is used * @return bool True if user has the permission */ function hasSurveyPermission($iSurveyID, $sPermission, $sCRUD = 'read', $iUserID = null) { $oSurvey = Survey::Model()->findByPk($iSurveyID); if (!$oSurvey) { return false; } $iUserID = self::getUserId($iUserID); // If you own a survey you have access to the whole survey if ($iUserID == $oSurvey->owner_id) { return true; } // Get global correspondance for surveys rigth $sGlobalCRUD = $sCRUD == 'create' || $sCRUD == 'delete' && $sPermission != 'survey' ? 'update' : $sCRUD; return $this->hasGlobalPermission('surveys', $sGlobalCRUD, $iUserID) || $this->hasPermission($iSurveyID, 'survey', $sPermission, $sCRUD, $iUserID); }
/** * Checks if a user has a certain permission in the given survey * * @param $iSurveyID integer The survey ID * @param $sPermission string Name of the permission * @param $sCRUD string The permission detail you want to check on: 'create','read','update','delete','import' or 'export' * @param $iUserID integer User ID - if not given the one of the current user is used * @return bool True if user has the permission */ public function hasSurveyPermission($iSurveyID, $sPermission, $sCRUD = 'read', $iUserID = null) { $oSurvey = Survey::Model()->findByPk($iSurveyID); if (!$oSurvey) { return false; } // If the user has the permission to update all other surveys he may import/export as well if ($this->hasGlobalPermission('surveys', 'update', $iUserID) && $sPermission == 'token' && ($sCRUD == 'import' || $sCRUD == 'export')) { $sCRUD = 'update'; } // Get global correspondance for surveys rigth $sGlobalCRUD = $sCRUD == 'create' || $sCRUD == 'delete' && $sPermission != 'survey' ? 'update' : $sCRUD; return $this->hasGlobalPermission('surveys', $sGlobalCRUD, $iUserID) || $this->hasPermission($iSurveyID, 'survey', $sPermission, $sCRUD, $iUserID); }