| 1 |
<?php |
<?php |
| 2 |
// $Id: buddylist_api.module,v 1.1.2.1 2008/07/21 14:46:42 nodestroy Exp $ |
// $Id: buddylist_api.module,v 1.1.2.2 2008/07/25 16:49:10 nodestroy Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 175 |
* relationobject |
* relationobject |
| 176 |
*/ |
*/ |
| 177 |
function buddylist_api_rtype_load($param = array()) { |
function buddylist_api_rtype_load($param = array()) { |
| 178 |
$rtypes = buddylist_api_rtypes_load(TRUE); |
// Get all relationtypes |
| 179 |
|
$rtypes = buddylist_api_rtypes_load(); |
| 180 |
|
|
| 181 |
|
// If there are no relationtypes, return null |
| 182 |
if (!isset($rtypes)) |
if (!isset($rtypes)) |
| 183 |
return NULL; |
return NULL; |
| 184 |
|
|
| 185 |
|
// If param is a number, return that one relationtype |
| 186 |
if (is_numeric($param)) { |
if (is_numeric($param)) { |
| 187 |
return $rtypes[$param]; |
return $rtypes[$param]; |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
|
// Search through relationtypes and return the first matching |
| 191 |
foreach ($rtypes as $type) { |
foreach ($rtypes as $type) { |
| 192 |
$found = TRUE; |
$found = TRUE; |
| 193 |
|
|
| 226 |
*/ |
*/ |
| 227 |
function buddylist_api_rtypes_load($reset = NULL) { |
function buddylist_api_rtypes_load($reset = NULL) { |
| 228 |
static $relationtypes_list = array(); |
static $relationtypes_list = array(); |
| 229 |
|
|
| 230 |
if ($reset || !sizeof($relationtypes_list)) { |
if ($reset || !sizeof($relationtypes_list)) { |
| 231 |
$results = db_query("SELECT * FROM {buddylist_relationtypes}"); |
$results = db_query("SELECT * FROM {buddylist_relationtypes}"); |
| 232 |
while ($relationtype = db_fetch_object($results)) { |
while ($relationtype = db_fetch_object($results)) { |
| 248 |
function buddylist_api_rtype_save(&$rtype) { |
function buddylist_api_rtype_save(&$rtype) { |
| 249 |
_buddylist_api_invoke('presave', $rtype, TRUE); |
_buddylist_api_invoke('presave', $rtype, TRUE); |
| 250 |
|
|
| 251 |
|
// if a rtid is set, we are in updated process |
| 252 |
|
// no rtid -> a new relationtype is inserted |
| 253 |
$op = $rtype->rtid ? 'update' : 'insert'; |
$op = $rtype->rtid ? 'update' : 'insert'; |
| 254 |
|
|
| 255 |
$existing = buddylist_api_rtype_load(array('name' => $rtype->name)); |
$existing = buddylist_api_rtype_load(array('name' => $rtype->name)); |
| 265 |
/** |
/** |
| 266 |
* Delete a Relationtype |
* Delete a Relationtype |
| 267 |
* |
* |
| 268 |
* @param $rtid |
* @param $rtype |
| 269 |
* A User Relationship type ID |
* A Relationtype object |
| 270 |
*/ |
*/ |
| 271 |
function buddylist_api_rtype_delete($rtid) { |
function buddylist_api_rtype_delete(&$rtype) { |
| 272 |
$rtype = buddylist_api_rtype_load($rtid); |
$rtype = (object)$rtype; |
| 273 |
|
|
| 274 |
|
// If the relationtype comes from an external module, we have to search for the right rtid |
| 275 |
|
if($rtype->type != 1) { |
| 276 |
|
$rtypes = buddylist_api_rtypes_load(); |
| 277 |
|
foreach($rtypes as $currenttype) { |
| 278 |
|
if($currenttype->name == $rtype->name) |
| 279 |
|
$rtype->rtid = $currenttype->rtid; |
| 280 |
|
} |
| 281 |
|
} |
| 282 |
|
|
| 283 |
db_query('DELETE FROM {buddylist_relations} WHERE rtid = %d', $rtid); |
// Delete all entries in relations table with that rtid + delete relationtype |
| 284 |
db_query('DELETE FROM {buddylist_relationtypes} WHERE rtid = %d', $rtid); |
db_query('DELETE FROM {buddylist_relations} WHERE rtid = %d', $rtype->rtid); |
| 285 |
|
db_query('DELETE FROM {buddylist_relationtypes} WHERE rtid = %d', $rtype->rtid); |
| 286 |
|
|
| 287 |
_buddylist_api_invoke('delete_rtype', $rtype, TRUE); |
_buddylist_api_invoke('delete_rtype', $rtype, TRUE); |
| 288 |
} |
} |