View source
<?php
include_once 'answers.features.inc';
module_load_include('inc', 'answers', 'includes/answers.notify');
module_load_include('inc', 'answers', 'includes/answers.search');
function answers_help($path, $arg) {
switch ($path) {
case "admin/help#modulename":
return '<p>' . t('Enables users to ask questions and for other users to answer them.') . '</p>';
}
}
function answers_menu($may_cache = NULL) {
$nid = (int) arg(1);
global $user;
$items['admin/config/content/answers'] = array(
'title' => 'Answers',
'description' => 'Configure how the question/answer service operates',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'answers_settings',
),
'access arguments' => array(
'administer content types',
),
'type' => MENU_NORMAL_ITEM,
);
$items['questions/start_ask'] = array(
'title' => 'Add a Question',
'description' => 'Enter a question to ask ... and start the process of asking it',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'answers_start_ask_form',
),
'access arguments' => array(
'add question',
),
'file' => 'includes/answers.search.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
return $items;
}
function answers_settings() {
$form = array_merge(array(), _answers_notify_settings());
return system_settings_form($form);
}
function answers_node_view($node, $view_mode, $langcode) {
if ($node->type == 'question') {
$field_instance = field_info_instance('node', 'field_answer_question', 'answer');
$locked_p = $node->field_question_locked_p['und'][0]['value'];
if ($locked_p == $field_instance['widget']['settings']['node_link']['full']) {
$field_instance['widget']['settings']['node_link']['full'] = $locked_p ? +0 : +1;
field_update_instance($field_instance);
}
}
}
function answers_node_insert($node) {
_answers_notify_node_insert($node);
}
function answers_node_delete($node) {
if ($node->type == 'question') {
$answer_nids = _answers_question_answers($node);
foreach ($answer_nids as $answer_nid) {
node_delete($answer_nid);
}
}
}
function _answers_question_answers($question) {
$results = array();
$qid = is_object($question) ? $question->nid : $question;
$view = views_get_view('answers_to_a_question');
$view
->set_arguments(array(
$qid,
));
$view
->execute();
foreach ($view->result as $result) {
$nid = $result->nid;
$results[$nid] = $nid;
}
return $results;
}
function answers_form_alter(&$form, &$form_state, $form_id) {
global $user;
_answers_notify_form_alter($form, $form_state, $form_id);
_answers_search_form_alter($form, $form_state, $form_id);
switch ($form_id) {
case 'question_node_form':
$form['actions']['submit']['#value'] = t('Ask Your Question');
if (isset($_GET['title'])) {
$title = check_plain($_GET['title']);
drupal_set_title(t('Add some details to your question'));
$form['title']['#default_value'] = $title;
}
$form['field_question_locked_p']['#prefix'] = '<div style="display: none;">';
$form['field_question_locked_p']['#suffix'] = '</div>';
break;
}
}