You are here

function simpleanswer_answers in Answers 5.2

Implementation of AnswersAPI.

Parameters

$op: operations are: answersinfo - returns name of answer module answerbuttons - returns a Add answer link settings - returns from elements that are added to the Answers Settings page add - returns an add from embedded - returns an answer as it will appear in a list of questions

$nid: node id of the quest

$answercount: current number of answers in the quest

File

simpleanswer/simpleanswer.module, line 154
Adds a simple form to post a response/answer to questions using the answers module. This module does not display its content directly and requires the answers module to show its content.

Code

function simpleanswer_answers($op, $nid = NULL, $answercount = 0) {
  switch ($op) {
    case 'answersinfo':
      $info['simpleanswer'] = 'Simple Answer Response';
      return $info;
      break;
    case 'answerbuttons':
      if ($answercount == 0) {
        return user_access('create responses') ? l(t('Be the first to add an Answer'), 'node/add/simpleanswer/' . $nid, array(
          'class' => 'postanswer',
        )) : '';
      }
      else {
        return user_access('create responses') ? l(t('Add an Answer'), 'node/add/simpleanswer/' . $nid, array(
          'class' => 'postanswer',
        )) : '';
      }
      break;
    case 'settings':
      $form['simpleanswer'] = array(
        '#type' => 'fieldset',
        '#description' => t('Simple Answer lets users post answers using a single textarea.'),
        '#title' => t('Simple Answer Module'),
      );
      $form['simpleanswer'][ANSWERS_TYPE . 'simpleanswer'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use Simple Answer'),
        '#return_value' => 1,
        '#default_value' => variable_get(ANSWERS_TYPE . 'simpleanswer', '0'),
      );
      $form['simpleanswer'][ANSWERS_TYPE . 'simpleanswer_editable'] = array(
        '#type' => 'checkbox',
        '#title' => t('Make Simple Answers editable'),
        '#description' => t('Allow users to edit their Simple Answers.'),
        '#return_value' => 1,
        '#default_value' => variable_get(ANSWERS_TYPE . 'simpleanswer_editable', '0'),
      );
      return $form;
      break;
    case 'add':
      return simpleanswer_form();
      break;
    case 'embedded':
      $shownode = node_load($nid);
      $shownode = node_prepare($shownode);
      $rendered = node_teaser($shownode->body);
      return $rendered;
      break;
  }
}