You are here

function answers_question_lock_unset in Answers 7.4

Unlock a question.

Parameters

object $question: A fully loaded question node.

string $module: The module that set the lock.

4 calls to answers_question_lock_unset()
answers_best_answer_flag in answers_best_answer/answers_best_answer.module
Implements hook_flag().
answers_best_answer_flag_flag in answers_best_answer/answers_best_answer.module
Implements hook_flag_flag().
answers_best_answer_flag_unflag in answers_best_answer/answers_best_answer.module
Implements hook_flag_unflag().
answers_lock_example_uninstall in answers_lock_example/answers_lock_example.install
Implements hook_uninstall().

File

includes/answers.lock.inc, line 107
Question locking functions for the 'Answers' module.

Code

function answers_question_lock_unset($question, $module) {
  if (in_array($module, answers_locking_modules())) {
    $items = field_get_items('node', $question, 'question_locks');

    // If the question is locked by this module, unset the lock.
    if ($items && ($delta = array_search(array(
      'value' => $module,
    ), $items) !== FALSE)) {
      $lang = field_language('node', $question, 'question_locks');
      $count = count($items);

      // Copy elements of lock array down.
      for ($i = $delta; $i < $count - 1; $i++) {
        $question->question_locks[$lang][$i] = $question->question_locks[$lang][$i + 1];
      }

      // Delete last element of lock array.
      unset($question->question_locks[$lang][$count - 1]);
      node_save($question);
    }
  }
}