| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Creates a block that should be enabled that shows a form at the bottom of the
|
| 7 |
* question page to add directly a new answer to that question.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_block().
|
| 12 |
*/
|
| 13 |
function peerreview_answer_block_block($op = 'list', $delta = 0, $edit = array()) {
|
| 14 |
switch ($op) {
|
| 15 |
case 'list':
|
| 16 |
$blocks['node_add_answer'] = array(
|
| 17 |
'info' => t('Node add block for answers'),
|
| 18 |
);
|
| 19 |
return $blocks;
|
| 20 |
|
| 21 |
case 'view':
|
| 22 |
switch ($delta) {
|
| 23 |
default:
|
| 24 |
return peerreview_answer_block_get_block($delta);
|
| 25 |
}
|
| 26 |
}
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Generate a block containing a node entry form.
|
| 31 |
*/
|
| 32 |
function peerreview_answer_block_get_block($type) {
|
| 33 |
// Include page handler for node_add()
|
| 34 |
module_load_include('inc', 'node', 'node.pages');
|
| 35 |
// Note title before rendering of form.
|
| 36 |
global $user;
|
| 37 |
$types = node_get_types();
|
| 38 |
$type = 'answer';
|
| 39 |
// If a node type has been specified, validate its existence.
|
| 40 |
if (user_access('create answer content', $user)) {
|
| 41 |
if (isset($types[$type])) {
|
| 42 |
// Initialize settings:
|
| 43 |
$node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => '');
|
| 44 |
$output = drupal_get_form($type .'_node_form', $node);
|
| 45 |
}
|
| 46 |
return array(
|
| 47 |
'subject' => t('Aggiungi una risposta'),
|
| 48 |
'content' => $output,
|
| 49 |
);
|
| 50 |
}
|
| 51 |
else {
|
| 52 |
return;
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
function peerreview_answer_block_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
| 57 |
switch ($op) {
|
| 58 |
case 'insert':
|
| 59 |
if ($node->type == 'answer') {
|
| 60 |
$parent = node_load(arg(1));
|
| 61 |
if ($parent->type == 'question') {
|
| 62 |
$node->riat_parent['id'] = arg(1);
|
| 63 |
$node->rel_key = 'child_node';
|
| 64 |
$node->rid = '1';
|
| 65 |
$node->chid = '1';
|
| 66 |
$node->child_node = 'answer_child_node';
|
| 67 |
$node->callback = 'riat_parent_child';
|
| 68 |
$node->comment = '2';
|
| 69 |
}
|
| 70 |
}
|
| 71 |
break;
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
function peerreview_answer_block_form_alter(&$form, $form_state, $form_id) {
|
| 76 |
if ($form_id == 'answer_node_form') {
|
| 77 |
$form['#redirect'] = 'node/'.arg(1);
|
| 78 |
}
|
| 79 |
}
|