| 1 |
<?php |
<?php |
| 2 |
// $Id: og_collections.module,v 1.2.2.6 2008/04/05 20:22:31 sdboyer Exp $ |
// $Id: og_collections.module,v 1.2.2.7 2008/04/05 20:30:34 sdboyer Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file og_collections.module |
* @file og_collections.module |
| 13 |
*/ |
*/ |
| 14 |
|
|
| 15 |
class og_collection { |
class og_collection { |
| 16 |
public $pcpanels, $version; |
public $version, $grouptype; |
| 17 |
var $argument = NULL; |
private $modified; |
| 18 |
|
// make usedefault private? |
| 19 |
|
|
| 20 |
// saves changes to the default collection |
// saves changes to the default collection |
| 21 |
function og_collection_save() { |
function __construct($grouptype, $pcpid = NULL) { |
| 22 |
|
if (is_null($pcpid)) { |
| 23 |
|
$this->og_collection_load_all($grouptype); |
| 24 |
|
} |
| 25 |
|
else { |
| 26 |
|
$this->og_collection_load($grouptype, $pcpid); |
| 27 |
|
} |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
// reduce to single, using private variable and sleep function. |
| 31 |
|
function og_collection_save_all() { // @TODO add some verification? |
| 32 |
|
foreach ($this as $member => $value) { |
| 33 |
|
if ($member == ('version' || 'grouptype')) { |
| 34 |
|
continue; |
| 35 |
|
} |
| 36 |
|
$this->og_collection_save($value); |
| 37 |
|
} |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
// saves an individual collection |
| 41 |
|
function og_collection_save($pcpid) { |
| 42 |
|
db_query("UPDATE {og_collections} SET pcpid_%d = '%s' WHERE grouptype = '%s'", $pcpid, serialize($this->$pcpid), $this->grouptype); |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
// loads the relevant pcpanel data into the default collection |
// loads the relevant pcpanel data into the default collection |
| 46 |
function og_collection_load() { |
function og_collection_load_all($grouptype = 'default') { |
| 47 |
|
$result = db_fetch_array(db_query("SELECT * FROM {og_collections} WHERE grouptype = '%s'", $grouptype)); |
| 48 |
|
foreach ($result as $field => $settings) { |
| 49 |
|
if ($field == ('version' || 'grouptype')) { |
| 50 |
|
continue; |
| 51 |
|
} |
| 52 |
|
$pcpid = (int) substr($field, 6); |
| 53 |
|
unserialize($settings); |
| 54 |
|
$this->$pcpid = new og_pcpanel(); |
| 55 |
|
$this->$pcpid->og_pcpanel_load($settings['did']); |
| 56 |
|
foreach ($settings as $setting => $val) { |
| 57 |
|
$this->$pcpid->$setting = $val; |
| 58 |
|
} |
| 59 |
|
} |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
function og_collection_load($grouptype, $pcpid) { |
| 63 |
|
$result = unserialize(db_result(db_query("SELECT pcpid_%d FROM {og_collections} WHERE grouptype = '%s'", $pcpid, $grouptype))); |
| 64 |
|
foreach ($result as $setting => $val) { |
| 65 |
|
$this->$pcpid->$setting = $val; |
| 66 |
|
} |
| 67 |
} |
} |
| 68 |
|
|
| 69 |
// performs the instantiation routine |
// performs the instantiation routine |
| 71 |
|
|
| 72 |
} |
} |
| 73 |
|
|
| 74 |
} |
// @TODO need to do this. This will need to record version data on not only the pcpanel's abstracted data, but the displays themselves... |
| 75 |
|
function og_collection_new_version() { |
| 76 |
|
|
| 77 |
|
} |
| 78 |
|
} // end og_collection class declaration |
| 79 |
|
|
| 80 |
class og_typed_collection extends og_collection { |
class og_typed_collection extends og_collection { |
| 81 |
|
|
| 90 |
$path, |
$path, |
| 91 |
$published, |
$published, |
| 92 |
$show_blocks, |
$show_blocks, |
|
$pcpid, |
|
| 93 |
$did, |
$did, |
| 94 |
$display, |
$display, |
| 95 |
$context, |
$context, |
| 96 |
$content_types, |
$content_types, |
| 97 |
$grouptype, |
$grouptype, |
| 98 |
$version; |
$version; |
| 99 |
|
private $sleep_container, $pcpid; |
| 100 |
// @FIXME This is an ugly hack way of accomplishing this, surely something in php's OOP would accomodate a better method? Can't figure out how, though... |
// @FIXME This is an ugly hack way of accomplishing this, surely something in php's OOP would accomodate a better method? Can't figure out how, though... |
| 101 |
/** |
/** |
| 102 |
* |
* |
| 105 |
*/ |
*/ |
| 106 |
function __construct($new = FALSE) { |
function __construct($new = FALSE) { |
| 107 |
if ($new === 'add_new') { |
if ($new === 'add_new') { |
| 108 |
self::add_new(); |
$this->add_new(); |
| 109 |
} |
} |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
|
// There remain some oustanding issues with PHP's __sleep() magic method related to including protected/private variables. |
| 113 |
|
// See http://us.php.net/manual/en/language.oop5.magic.php#81492 for workaround details. |
| 114 |
|
function __sleep() { |
| 115 |
|
$this->sleep_container = $this->display; |
| 116 |
|
return array('default', 'enabled', 'weight', 'page_title', 'path', 'published', 'show_blocks', 'did'); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
// Doing it this way requires some double query-ness. Is this avoidable? |
| 120 |
|
function __wakeup() { |
| 121 |
|
$this->og_pcpanel_load(); |
| 122 |
|
} |
| 123 |
|
|
| 124 |
// Adds a new pcpanel. ONLY called by the constructor, never directly |
// Adds a new pcpanel. ONLY called by the constructor, never directly |
| 125 |
private function og_pcpanel_new() { |
private function og_pcpanel_new() { |
| 126 |
$this->pcpid = db_next_id("{og_collections_pcpanel}_pcpid"); |
$this->pcpid = db_next_id("{og_collections_pcpanel}_pcpid"); |
| 127 |
$display = panels_save_display(panels_new_display()); |
$display = panels_save_display(panels_new_display()); |
| 128 |
$this->did = $display->did; |
$this->did = $display->did; |
| 129 |
|
$this->display = $display; |
| 130 |
$this->grouptype = 'default'; |
$this->grouptype = 'default'; |
| 131 |
db_query("INSERT INTO {og_collections_pcpanel} (did, pcpid, grouptype, version) VALUES (%d, %d, '%s', %d", $this->did, $this->pcpid, $this->grouptype, 0); |
db_query("INSERT INTO {og_collections_pcpanel} (did, pcpid, grouptype, version) VALUES (%d, %d, '%s', %d", $this->did, $this->pcpid, $this->grouptype, 0); |
| 132 |
} |
} |
| 146 |
} |
} |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
|
function og_pcpanel_fill() { |
| 150 |
|
$pcpid = $this->pcpid; |
| 151 |
|
$collection = new og_collection($this->grouptype, $pcpid); // TODO kind of an inelegant hack. Any better way of doing this? |
| 152 |
|
$this = $collection->$pcpid; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
function __get($member) { |
function __get($member) { |
| 156 |
if ($member == 'did' && isset($this->pcpid, $this->grouptype)) { |
switch ($member) { |
| 157 |
return db_result(db_query("SELECT did FROM {og_collections_pcpanel} WHERE pcpid = %d AND grouptype = '%s'", $this->pcpid, $this->grouptype)); |
case 'did': |
| 158 |
|
if (isset($this->pcpid, $this->grouptype)) { |
| 159 |
|
return db_result(db_query("SELECT did FROM {og_collections_pcpanel} WHERE pcpid = %d AND grouptype = '%s'", $this->pcpid, $this->grouptype)); |
| 160 |
|
} |
| 161 |
|
else { |
| 162 |
|
$exception = 'Not enough information to get retrieve pcpanel data (missing pcpid or grouptype).'; // TODO what about default? |
| 163 |
|
} |
| 164 |
|
break; |
| 165 |
|
|
| 166 |
|
case 'pcpid': |
| 167 |
|
case 'grouptype': |
| 168 |
|
if (isset($this->did)) { |
| 169 |
|
return db_result(db_query("SELECT '%s' FROM {og_collections_pcpanel} WHERE did = %d", $member, $this->did)); |
| 170 |
|
} |
| 171 |
|
else { |
| 172 |
|
$exception = 'Not enough information to get retrieve pcpanel data (missing did).'; |
| 173 |
|
} |
| 174 |
|
break; |
| 175 |
|
|
| 176 |
|
case 'display': |
| 177 |
|
|
| 178 |
|
break; |
| 179 |
|
|
| 180 |
|
case 'context': |
| 181 |
|
|
| 182 |
|
break; |
| 183 |
|
|
| 184 |
|
case 'content_types': |
| 185 |
|
|
| 186 |
|
break; |
| 187 |
} |
} |
| 188 |
if (($member == 'pcpid ' || $member == 'grouptype') && isset($this->did)) { |
if (isset($exception)) { |
| 189 |
return db_result(db_query("SELECT '%s' FROM {og_collections_pcpanel} WHERE did = %d", $member, $this->did)); |
throw new Exception($exception); |
| 190 |
} |
} |
| 191 |
} |
} |
| 192 |
} |
} // end og_pcpanel class declaration |
| 193 |
|
|
| 194 |
/** |
/** |
| 195 |
* Implementation of hook_help() |
* Implementation of hook_help() |