| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* @file
|
| 4 |
* submit, view, and manage AA items items and lists
|
| 5 |
*/
|
| 6 |
|
| 7 |
define(AA_CONFIG_FILE,"/include/config.php3");
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help()
|
| 11 |
* Display help text for the aaitem module
|
| 12 |
*/
|
| 13 |
function aaitem_help($section) {
|
| 14 |
switch ($section) {
|
| 15 |
case 'admin/help#aaitem':
|
| 16 |
$o .= '<p>' . t('Submit, view and manage aaitem lists.') . '</p>';
|
| 17 |
return $o;
|
| 18 |
case 'admin/modules#description':
|
| 19 |
return t('Allows viewing and editing of ActionApps items as if they were Drupal nodes.');
|
| 20 |
case 'node/add#aaitem':
|
| 21 |
return t('Add a ActionApps item by item id here');
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Implementation of hook_perm().
|
| 27 |
* Define the permissions this module uses
|
| 28 |
*/
|
| 29 |
function aaitem_perm() {
|
| 30 |
return array('create aaitem items', 'manage own aaitem items');
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Implementation of hook_access().
|
| 35 |
*/
|
| 36 |
function aaitem_access($op, $node) {
|
| 37 |
global $user;
|
| 38 |
|
| 39 |
if ($op == 'create') {
|
| 40 |
return user_access('create aaitem items');
|
| 41 |
}
|
| 42 |
|
| 43 |
if ($op == 'update' || $op == 'delete') {
|
| 44 |
if (user_access('manage own aaitem items') && ($user->uid == $node->uid)) {
|
| 45 |
return TRUE;
|
| 46 |
}
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Implementation of hook_menu().
|
| 52 |
*/
|
| 53 |
function aaitem_menu($may_cache) {
|
| 54 |
$items = array();
|
| 55 |
|
| 56 |
if ($may_cache) {
|
| 57 |
$items[] = array('path' => 'node/add/aaitem', 'title' => t('aaitem'),
|
| 58 |
'access' => user_access('create aaitem items'));
|
| 59 |
}
|
| 60 |
|
| 61 |
return $items;
|
| 62 |
}
|
| 63 |
/**
|
| 64 |
* Implementation of hook_node_info().
|
| 65 |
* Define the node type
|
| 66 |
*/
|
| 67 |
function aaitem_node_info() {
|
| 68 |
return array('aaitem' => array('name' => t('ActionApps Item'), 'base' => 'aaitem'));
|
| 69 |
}
|
| 70 |
function aaitem_form(&$node) {
|
| 71 |
|
| 72 |
$form['title'] = array('#type' => 'textfield',
|
| 73 |
'#title' => t('Item ID'),
|
| 74 |
'#required' => TRUE,
|
| 75 |
'#default_value' => $node->title,
|
| 76 |
'#weight' => -5,
|
| 77 |
'#description' => t('ActionApps Item ID')
|
| 78 |
);
|
| 79 |
|
| 80 |
if(! preg_match("/[0-9A-Fa-f]{32}/",$node->title))
|
| 81 |
return $form;
|
| 82 |
// $form['title']['#disabled'] = true;
|
| 83 |
// $form['title']['#attributes'] = array('style'=>'display: none');
|
| 84 |
$form['title']['#attributes'] = array('disabled'=>'disabled');
|
| 85 |
drupal_set_message(t("ActionApps Item ID"));
|
| 86 |
// drupal_set_message(var_export($node,true));
|
| 87 |
$fields_mappings = _get_field_mappings();
|
| 88 |
foreach($fields_mappings as $aa_field => $drupal_array) {
|
| 89 |
$form[$aa_field] = array(
|
| 90 |
'#type' => $drupal_array['type'],
|
| 91 |
'#title'=> $drupal_array['title'],
|
| 92 |
'#required' => $drupal_array['required'],
|
| 93 |
'#default_value' => $node->$aa_field,
|
| 94 |
'#description' => $drupal_array['description'],
|
| 95 |
);
|
| 96 |
}
|
| 97 |
return $form;
|
| 98 |
}
|
| 99 |
|
| 100 |
|
| 101 |
/// TODO Validate the form submission http://drupal.org/node/71959
|
| 102 |
/**
|
| 103 |
* Implementation of hook_insert (no, submit), which saves aaitem-specific information
|
| 104 |
* into the actionapps db
|
| 105 |
* @param node object
|
| 106 |
*/
|
| 107 |
function aaitem_submit($node) {
|
| 108 |
|
| 109 |
// echo(var_export($node,true));
|
| 110 |
/// is this a new node?
|
| 111 |
if(! $node->nid )
|
| 112 |
return;
|
| 113 |
|
| 114 |
$fields_mappings = _get_field_mappings();
|
| 115 |
$content = array();
|
| 116 |
foreach($fields_mappings as $aa_field => $drupal_array) {
|
| 117 |
if(!$drupal_array['type'])
|
| 118 |
continue; // not a form element
|
| 119 |
$content[$aa_field] = $node->$aa_field;
|
| 120 |
}
|
| 121 |
$aaInst = _get_aa_inst();
|
| 122 |
$aaInst->updateItem($node->title,$content);
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Implemenation of hook_load
|
| 127 |
* @param node object to load additional information for
|
| 128 |
* @return object with aa fields
|
| 129 |
*/
|
| 130 |
function aaitem_load($node) {
|
| 131 |
$aaInst = _get_aa_inst();
|
| 132 |
$aaitem = $aaInst->getItem($node->title);
|
| 133 |
if(!$aaitem)
|
| 134 |
drupal_set_message(t("problem loading content for item ").$node->title);
|
| 135 |
// drupal_set_message(t("loaded ").$node->title);
|
| 136 |
// var_dump($aaitem);
|
| 137 |
$t = $aaitem->getFieldsArray();
|
| 138 |
return $t;
|
| 139 |
}
|
| 140 |
|
| 141 |
/**
|
| 142 |
* Implementation of hook_view, add our node specific information
|
| 143 |
* @param node object to display
|
| 144 |
* @param boolean is this a teaser or full node?
|
| 145 |
* @param boolean is this displaying on its own page
|
| 146 |
*/
|
| 147 |
function aaitem_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 148 |
|
| 149 |
$fields_mappings = _get_field_mappings();
|
| 150 |
foreach($fields_mappings as $aafield=>$drupal_array) {
|
| 151 |
$node->$drupal_array['field'] = $node->$aafield;
|
| 152 |
}
|
| 153 |
|
| 154 |
$node = node_prepare($node, $teaser);
|
| 155 |
|
| 156 |
// if($node->headline)
|
| 157 |
// $node->title = $node->headline;
|
| 158 |
|
| 159 |
|
| 160 |
$aaitem_info = theme('aaitem_basic_view', $node);
|
| 161 |
$node->body .= $aaitem_info;
|
| 162 |
$node->teaser .= $aaitem_info;
|
| 163 |
|
| 164 |
|
| 165 |
}
|
| 166 |
|
| 167 |
/**
|
| 168 |
* Theme function to display additional node data
|
| 169 |
* @param node to display
|
| 170 |
* @return HTML string with additional node information
|
| 171 |
*/
|
| 172 |
function theme_aaitem_basic_view($node) {
|
| 173 |
|
| 174 |
$interesting_fields = array(
|
| 175 |
'unpacked_id.....' => 'ActionApps Item ID: ',
|
| 176 |
'short_id........' => 'ActionApps Short ID: ',
|
| 177 |
|
| 178 |
);
|
| 179 |
$output = "";
|
| 180 |
foreach($interesting_fields as $key=>$text) {
|
| 181 |
$short_key = str_replace(".","",$key);
|
| 182 |
$output .= "<div class=\"aaitem_view_$short_key\">";
|
| 183 |
$output .= t($text . '%value',array('%value'=>$node->$key));
|
| 184 |
$output .= '</div>';
|
| 185 |
}
|
| 186 |
return $output;
|
| 187 |
}
|
| 188 |
/** $fields_mappings from actionapps fields
|
| 189 |
to drupal fields
|
| 190 |
this is used in various places
|
| 191 |
(a) field overwrites the drupal property in view
|
| 192 |
(b) type is used for the form generation and saving
|
| 193 |
-> if no type is given the field will not be saved
|
| 194 |
**/
|
| 195 |
///TODO make this configurable
|
| 196 |
|
| 197 |
function _get_field_mappings() {
|
| 198 |
return array(
|
| 199 |
'headline........' => array(
|
| 200 |
'field' => 'title',
|
| 201 |
'title' => t('Headline'),
|
| 202 |
'type' => 'textfield'
|
| 203 |
),
|
| 204 |
'abstract........' => array(
|
| 205 |
'field' => 'teaser',
|
| 206 |
'title' => t('Abstract'),
|
| 207 |
'type' => 'textarea'
|
| 208 |
),
|
| 209 |
'full_text.......' => array(
|
| 210 |
'field' =>'body',
|
| 211 |
'title' => t('Full Text'),
|
| 212 |
'type' => 'textarea'
|
| 213 |
),
|
| 214 |
'publish_date....' => array('field' =>'revision_timestamp'),
|
| 215 |
'created_by......' => array('field' =>'name'),
|
| 216 |
'status_code.....' => array('field' => 'status')
|
| 217 |
);
|
| 218 |
|
| 219 |
}
|
| 220 |
|
| 221 |
function _get_aa_inst() {
|
| 222 |
static $aaInst = false;
|
| 223 |
if($aaInst)
|
| 224 |
return $aaInst;
|
| 225 |
require_once("actionapps.inc");
|
| 226 |
$aaInst = new AAInstall(variable_get('aaview_installation_path', '').AA_CONFIG_FILE);
|
| 227 |
return $aaInst;
|
| 228 |
}
|
| 229 |
?>
|