You are here

public function QuizQuestion::checkContextAccess in OG Quiz 7

Check user permissions based on the context (inside a group or global).

Parameters

$permission:

Return value

bool

1 call to QuizQuestion::checkContextAccess()
QuizQuestion::getNodeForm in includes/og_quiz_question.php
Returns a node form to quiz_question_form

File

includes/og_quiz_question.php, line 75
Classes used in the Quiz Question module.

Class

QuizQuestion
A base implementation of a quiz_question, adding a layer of abstraction between the node API, quiz API and the question types.

Code

public function checkContextAccess($permission) {

  // Must we check this node, or the parent quiz ?
  if (!isset($this->checkWhat)) {
    if (isset($this->node->nid) && og_is_group_content_type('node', $this->node->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') {

    // When in group context, the node permission "edit any/own type content" becomes "update any/own type content".
    if (preg_match('/^edit (any|own) [a-z\\_]+ content/', $permission)) {
      $permission = preg_replace('/^edit/', 'update', $permission);
    }
    if ($this->checkWhat == 'parent') {
      $node = $this
        ->getParentQuiz();
    }
    else {
      $node = clone $this->node;
    }
    $access = og_quiz_ogs_access($node, $permission);
  }
  return isset($access) ? $access : user_access($permission);
}