| 1 |
<?php
|
| 2 |
/** AA Abstraction Layer
|
| 3 |
* developed for the actionkit project
|
| 4 |
*
|
| 5 |
* All accesses to AA objects etc should be handled by this
|
| 6 |
*
|
| 7 |
* (C)2006 Michael Moritz mimo/at/gn.apc.org
|
| 8 |
* version 0.2 2006/08
|
| 9 |
*
|
| 10 |
*/
|
| 11 |
class AASlice
|
| 12 |
{
|
| 13 |
///public:
|
| 14 |
/* function AASlice($slice_id,$slice_name) {
|
| 15 |
$this->_slice_id = unpack_id128($slice_id);
|
| 16 |
$this->_slice_name = $slice_name;
|
| 17 |
}*/
|
| 18 |
function AASlice($dbobject) {
|
| 19 |
$this->_slice_id = unpack_id128($dbobject->f('id'));
|
| 20 |
$this->_slice_name = $dbobject->f('name');
|
| 21 |
}
|
| 22 |
function getName() {
|
| 23 |
return $this->_slice_name;
|
| 24 |
}
|
| 25 |
function addToArray(&$arr) {
|
| 26 |
// return array($this->_slice_id=>$this->_slice_name);
|
| 27 |
$arr[$this->_slice_id] = $this->_slice_name;
|
| 28 |
}
|
| 29 |
function getID() { return $this->_slice_id; }
|
| 30 |
///private:
|
| 31 |
// unpacked id
|
| 32 |
var $_slice_id;
|
| 33 |
// slice name (string)
|
| 34 |
var $_slice_name;
|
| 35 |
};
|
| 36 |
class AAView
|
| 37 |
{
|
| 38 |
///public:
|
| 39 |
function AAView($dbobject) {
|
| 40 |
$this->_id = $dbobject->f('id');
|
| 41 |
$this->_name = $dbobject->f('name');
|
| 42 |
$this->_type = $dbobject->f('type');
|
| 43 |
$this->_slice_id = unpack_id128($dbobject->f('slice_id'));
|
| 44 |
}
|
| 45 |
function addToArray(&$arr) {
|
| 46 |
$arr[$this->_id] = $this->_id." - ".$this->_name;
|
| 47 |
}
|
| 48 |
function getArray() {
|
| 49 |
return array($this->_id => $this->_name.", ".$this->_type);
|
| 50 |
// return array($this->_id."-".$this->_slice_id => $this->_name.", ".$this->_type);
|
| 51 |
}
|
| 52 |
function getID() { return $this->_id; }
|
| 53 |
function getSliceID() { return $this->_slice_id; }
|
| 54 |
function getName() { return $this->_name; }
|
| 55 |
/**
|
| 56 |
*
|
| 57 |
* Find out whether this view is part of a slice or not
|
| 58 |
*
|
| 59 |
**/
|
| 60 |
function isInSlice($slice_object) { return $this->_slice_id == $slice_object->getID(); }
|
| 61 |
///private:
|
| 62 |
var $_id;
|
| 63 |
var $_name;
|
| 64 |
var $_type;
|
| 65 |
var $_slice_id;
|
| 66 |
};
|
| 67 |
class AAField
|
| 68 |
{
|
| 69 |
///public:
|
| 70 |
function AAField($name,$value) {
|
| 71 |
$this->_name = $name;
|
| 72 |
$this->_value = $value;
|
| 73 |
}
|
| 74 |
function getName() { return $this->_name; }
|
| 75 |
function getValue() { return $this->_value; }
|
| 76 |
///private:
|
| 77 |
var $_name;
|
| 78 |
var $_value;
|
| 79 |
};
|
| 80 |
class AAItem
|
| 81 |
{
|
| 82 |
function AAItem($item_id) {
|
| 83 |
// drupal_set_message("AA Item $item_id");
|
| 84 |
// $GLOBALS['debug'] = true;
|
| 85 |
$content = GetItemContent($item_id);
|
| 86 |
// huhl($content);
|
| 87 |
if(!is_array($content) || count($content) === 0)
|
| 88 |
return false;
|
| 89 |
foreach($content[$item_id] as $field_id => $value) {
|
| 90 |
// huhl($value);
|
| 91 |
// $field_id = str_replace('.',"",$field_id);
|
| 92 |
$this->_fields[] = new AAField($field_id,$value[0]['value']);
|
| 93 |
// drupal_set_message("$field_id -> $value");
|
| 94 |
}
|
| 95 |
}
|
| 96 |
function getFieldsArray() {
|
| 97 |
$names = array();
|
| 98 |
foreach($this->_fields as $aaitem) {
|
| 99 |
$names[$aaitem->getName()] = $aaitem->getValue();
|
| 100 |
}
|
| 101 |
return $names;
|
| 102 |
}
|
| 103 |
var $_fields = array();
|
| 104 |
};
|
| 105 |
class AAInstall
|
| 106 |
{
|
| 107 |
///public:
|
| 108 |
function AAInstall($path) {
|
| 109 |
$this->_path = $path;
|
| 110 |
}
|
| 111 |
/**
|
| 112 |
*
|
| 113 |
* Return an array of AASlice objects
|
| 114 |
*
|
| 115 |
*/
|
| 116 |
function listSlices() {
|
| 117 |
if(!empty($this->_slices))
|
| 118 |
return $this->_slices;
|
| 119 |
$this->_init();
|
| 120 |
$slices = array();
|
| 121 |
|
| 122 |
///TODO is there an AA api function for this?
|
| 123 |
$SQL = "SELECT `name`,`id` FROM slice ORDER BY `name`";
|
| 124 |
$db = getDB();
|
| 125 |
$db->query($SQL);
|
| 126 |
while ($db->next_record()) {
|
| 127 |
$slices[] = new AASlice($db);
|
| 128 |
}
|
| 129 |
freeDB($db);
|
| 130 |
$this->_slices = $slices;
|
| 131 |
return $slices;
|
| 132 |
}
|
| 133 |
/**
|
| 134 |
*
|
| 135 |
* Return an array of AAView objects
|
| 136 |
* @param slice AASlice object
|
| 137 |
*
|
| 138 |
*/
|
| 139 |
/*
|
| 140 |
function listViews($slice_object) {
|
| 141 |
$views = array();
|
| 142 |
$this->_getViews();
|
| 143 |
foreach($this->_views as $view_object) {
|
| 144 |
if($view_object->isInSlice($slice_object))
|
| 145 |
$views[] = $view_object;
|
| 146 |
}
|
| 147 |
return $views;
|
| 148 |
*/
|
| 149 |
function listViews($slice_id) {
|
| 150 |
$this->_init();
|
| 151 |
// $views = array();
|
| 152 |
// drupal_set_message($slice);
|
| 153 |
///TODO is there an AA api function for this?
|
| 154 |
$SQL = "SELECT `id`,`name`,`type`,`slice_id` FROM view";
|
| 155 |
$SQL .= ($slice != -1) ? " WHERE `slice_id`='".q_pack_id($slice_id)."'" : "";
|
| 156 |
$SQL .= " ORDER BY `id`";
|
| 157 |
// drupal_set_message($SQL);
|
| 158 |
$db = getDB();
|
| 159 |
$db->query($SQL);
|
| 160 |
while ($db->next_record()) {
|
| 161 |
$views[] = new AAView($db);
|
| 162 |
}
|
| 163 |
freeDB($db);
|
| 164 |
return $views;
|
| 165 |
}
|
| 166 |
/**
|
| 167 |
*
|
| 168 |
* Return an ActionApps view - the HTML output
|
| 169 |
* @param slice_id AASliceID (not used)
|
| 170 |
* @param view_id AAViewID
|
| 171 |
* @param $params Parameters passed to the view (like vid=)
|
| 172 |
* @return HTML for the view
|
| 173 |
*/
|
| 174 |
function getView($slice_id,$view_id,$params) {
|
| 175 |
global $AA_INC_PATH, $AA_BASE_PATH, $AA_INSTAL_PATH,
|
| 176 |
$spareDBs,$tracearr,$traceall,$allviews,$VIEW_SORT_DIRECTIONS,$MODULES,
|
| 177 |
$QuoteArray,$UnQuoteArray,$debug;
|
| 178 |
$debug = false;
|
| 179 |
$this->_init();
|
| 180 |
$this->_viewinit();
|
| 181 |
/// convert the url params into param array (AA API)
|
| 182 |
if($params && strlen($params))
|
| 183 |
$params = ParseViewParameters($params);
|
| 184 |
|
| 185 |
/// add the view_id
|
| 186 |
$params['vid'] = $view_id;
|
| 187 |
|
| 188 |
$output = GetView($params);
|
| 189 |
return $output;
|
| 190 |
}
|
| 191 |
/**
|
| 192 |
*
|
| 193 |
* Return an ActionApps item object
|
| 194 |
* @param item_id AA item ID
|
| 195 |
* @return AAItem Object or false if not found
|
| 196 |
*/
|
| 197 |
function getItem($item_id) {
|
| 198 |
$this->_init();
|
| 199 |
return new AAItem($item_id);
|
| 200 |
}
|
| 201 |
/**
|
| 202 |
*
|
| 203 |
* Store an ActionApps item object
|
| 204 |
* @param item_id AA item ID
|
| 205 |
* @param content_array content (key=>value)
|
| 206 |
* @return item_id or false if failed
|
| 207 |
*/
|
| 208 |
function updateItem($item_id,$content_array) {
|
| 209 |
global $event, $itemvarset, $db, $debug;
|
| 210 |
$debug = false;
|
| 211 |
$debugsi = false;
|
| 212 |
$this->_init();
|
| 213 |
$item = new ItemContent($item_id);
|
| 214 |
// huhl($content_array);
|
| 215 |
foreach($content_array as $key=>$val) {
|
| 216 |
$item->setValue($key,$val);
|
| 217 |
}
|
| 218 |
// huhl($item);
|
| 219 |
// die;
|
| 220 |
require_once $GLOBALS["AA_INC_PATH"]."event.class.php3";
|
| 221 |
require_once $GLOBALS["AA_INC_PATH"]."itemfunc.php3";
|
| 222 |
if ( !is_object($event) )
|
| 223 |
$event = new aaevent;
|
| 224 |
return $item->storeItem( "update" );
|
| 225 |
}
|
| 226 |
/**
|
| 227 |
*
|
| 228 |
* Return an array of names
|
| 229 |
*
|
| 230 |
*/
|
| 231 |
function getArrayFromArray(&$arr) {
|
| 232 |
$names = array();
|
| 233 |
if(!is_array($arr))
|
| 234 |
return $names;
|
| 235 |
foreach($arr as $item) {
|
| 236 |
// $names[] = $item->getArray();
|
| 237 |
$item->addToArray($names);
|
| 238 |
}
|
| 239 |
return $names;
|
| 240 |
}
|
| 241 |
///private:
|
| 242 |
var $_slices;
|
| 243 |
var $_views;
|
| 244 |
var $_path;
|
| 245 |
function _init() {
|
| 246 |
static $s_initialised = false;
|
| 247 |
if($s_initialised)
|
| 248 |
return;
|
| 249 |
global $AA_INC_PATH, $AA_BASE_PATH, $AA_INSTAL_PATH,
|
| 250 |
$spareDBs,$tracearr,$traceall,$allviews,$VIEW_SORT_DIRECTIONS,$MODULES,
|
| 251 |
$QuoteArray,$UnQuoteArray,$debug;
|
| 252 |
require_once($this->_path);
|
| 253 |
// // now mess around with the globals
|
| 254 |
require_once $GLOBALS['AA_INC_PATH'].'easy_scroller.php3';
|
| 255 |
require_once $GLOBALS['AA_INC_PATH'].'util.php3';
|
| 256 |
require_once $GLOBALS["AA_INC_PATH"]."item.php3";
|
| 257 |
require_once $GLOBALS["AA_INC_PATH"]."view.php3";
|
| 258 |
require_once $GLOBALS["AA_INC_PATH"]."discussion.php3";
|
| 259 |
require_once $GLOBALS["AA_INC_PATH"]."pagecache.php3";
|
| 260 |
require_once $GLOBALS["AA_INC_PATH"]."searchlib.php3";
|
| 261 |
require_once $GLOBALS["AA_INC_PATH"]."locsessi.php3";
|
| 262 |
$s_initialised = true;
|
| 263 |
// huhl($MODULES);
|
| 264 |
}
|
| 265 |
function _viewinit() {
|
| 266 |
/* require_once($this->_path);
|
| 267 |
// now mess around with the globals
|
| 268 |
require_once $GLOBALS['AA_INC_PATH'].'easy_scroller.php3';
|
| 269 |
require_once $GLOBALS['AA_INC_PATH'].'util.php3';
|
| 270 |
require_once $GLOBALS["AA_INC_PATH"]."item.php3";
|
| 271 |
require_once $GLOBALS["AA_INC_PATH"]."view.php3";
|
| 272 |
require_once $GLOBALS["AA_INC_PATH"]."discussion.php3";
|
| 273 |
require_once $GLOBALS["AA_INC_PATH"]."pagecache.php3";
|
| 274 |
require_once $GLOBALS["AA_INC_PATH"]."searchlib.php3";
|
| 275 |
require_once $GLOBALS["AA_INC_PATH"]."locsessi.php3";*/
|
| 276 |
}
|
| 277 |
|
| 278 |
function _getViews() {
|
| 279 |
if(! empty($this->_views))
|
| 280 |
return;
|
| 281 |
$this->_init();
|
| 282 |
$SQL = "SELECT `id`,`name`,`type`,`slice_id` FROM view";
|
| 283 |
$db = getDB();
|
| 284 |
$db->query($SQL);
|
| 285 |
while ($db->next_record()) {
|
| 286 |
$this->_views[] = new AAView($db);
|
| 287 |
}
|
| 288 |
freeDB($db);
|
| 289 |
}
|
| 290 |
};
|
| 291 |
|
| 292 |
?>
|