/** * Determine if a user has access to a certain operation within a group context. * * For content access @see hook_og_node_access(). * * @param $op * The operation name. * @param $node * The group or group content node object. * @param $acting_user * The user object of the acting user. * @param $account * Optional; The account related to the operation. * @return * OG_ACCESS_ALLOW - if operation is allowed; * OG_ACCESS_DENY - if it should be denied; * OG_ACCESS_IGNORE - if you don't care about this operation. */ function hook_og_access($op, $node, $acting_user, $account = NULL) { if ($op == 'view') { // Show group content only if they are in a certain day, defined in the // group's data. This data is fictional, and it's up to an implementing // module to implement it. if (og_is_group_content_type($node->type)) { // Get the first node group this group content belongs to. $gids = og_get_object_groups('node', $node); $group = node_load($gids[0]); if (!empty($group->data['show day'])) { $today = date('N'); if ($group->data['show day'] == $today) { return OG_ACCESS_ALLOW; } else { return OG_ACCESS_DENY; } } else { // The group doesn't have a day definition, so we don't care about this // operation. return OG_ACCESS_IGNORE; } } } }
/** * Helper function to determine if a user has access to score a quiz. * * @param $quiz_creator * uid of the quiz creator. * * @return bool */ public function quizContextAccessToScore($quiz_creator = NULL) { // Must we check this node, or the parent quiz ? if (!isset($this->checkWhat)) { if (isset($this->question->nid) && og_is_group_content_type('node', $this->question->type)) { $groups = og_get_entity_groups('node', $this->node); if (!empty($groups)) { $this->checkWhat = 'self'; } } // If empty, check the parent quiz. if (!isset($this->checkWhat)) { // Try fetching the parent quiz, if any. $quiz = $this->getParentQuiz(); if (isset($quiz)) { $this->checkWhat = 'parent'; } else { // Use default permissions. $this->checkWhat = 'none'; } } } if ($this->checkWhat != 'none') { if ($this->checkWhat == 'parent') { $node = $this->getParentQuiz(); } else { $node = clone $this->question; } if ($quiz_creator == NULL && ($quiz = quiz_get_quiz_from_menu())) { $quiz_creator = $quiz->uid; } if (!($access = og_quiz_ogs_access($node, array('score taken quiz answer', 'score taken quiz answer')))) { $access = og_quiz_ogs_access($node, 'score own quiz'); if ($access) { global $user; $access = $access && $user->uid == $quiz_creator; } } } return isset($access) ? $access : quiz_access_to_score($quiz_creator); }