View source
<?php
include_once 'answers.features.inc';
module_load_include('inc', 'answers', 'includes/answers.search');
module_load_include('inc', 'answers', 'includes/answers.notify');
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/settings/answers'] = array(
'title' => 'Answers',
'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_CALLBACK,
);
return $items;
}
function answers_profile_page($mode) {
switch ($mode) {
case 'questions':
return views_embed_view('user_questions');
case 'answers':
return views_embed_view('user_answers');
}
}
function answers_nodeapi(&$node, $op, $teaser) {
global $user;
_answers_notify_nodeapi($node, $op, $teaser);
switch ($op) {
case 'view':
if ($node->type == 'question') {
$field = content_fields('field_answer_question', 'answer');
$locked_p = $node->field_question_locked_p[0]['value'];
if ($locked_p == $field['widget']['node_link']['full']) {
module_load_include('inc', 'content', 'includes/content.crud');
$field['widget']['node_link']['full'] = $locked_p ? +0 : +1;
content_field_instance_update($field);
}
}
break;
case 'delete':
if ($node->type == 'question') {
$answer_nids = _answers_question_answers($node);
foreach ($answer_nids as $answer_nid) {
node_delete($answer_nid);
}
}
break;
}
}
function _answers_question_answers($question) {
$results = array();
$qid = is_object($question) ? $question->nid : $question;
$view = views_get_view('question_answers');
$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['buttons']['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;
}
}