/[drupal]/contributions/modules/buddylist2/buddylist_api/buddylist_api.module
ViewVC logotype

Diff of /contributions/modules/buddylist2/buddylist_api/buddylist_api.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.2, Fri Jul 25 16:49:10 2008 UTC revision 1.1.2.3, Tue Jul 29 07:30:53 2008 UTC
# Line 1  Line 1 
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
# Line 175  function buddylist_api_load_relationship Line 175  function buddylist_api_load_relationship
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    
# Line 222  function buddylist_api_rtype_load($param Line 226  function buddylist_api_rtype_load($param
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)) {
# Line 244  function buddylist_api_rtypes_load($rese Line 248  function buddylist_api_rtypes_load($rese
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));
# Line 259  function buddylist_api_rtype_save(&$rtyp Line 265  function buddylist_api_rtype_save(&$rtyp
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  }  }

Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3

  ViewVC Help
Powered by ViewVC 1.1.2