/[drupal]/contributions/modules/type_local_nids/type_local_nids.module
ViewVC logotype

Diff of /contributions/modules/type_local_nids/type_local_nids.module

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

revision 1.2, Sun Mar 23 02:48:30 2008 UTC revision 1.3, Thu Sep 24 17:50:19 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: type_local_nids.module,v 1.1.2.3 2009/04/25 21:21:50 jbrown Exp $
3    
4    
5  function _type_local_nids_generate_lnid(&$node) {  function _type_local_nids_generate_lnid($node) {
6    
7          $node->lnid = db_result(db_query("    $txn = db_transaction();
8                  SELECT next_lnid  
9                  FROM {node_lnid_next}    $node->lnid = db_select('node_lnid_next')
10                  WHERE type = '%s'      ->fields('node_lnid_next', array('next_lnid'))
11          ",      ->condition('type', $node->type)
12                  $node->type      ->execute()
13          ));      ->fetchField();
14    
15          if($node->lnid) {          if($node->lnid) {
16    
17                  db_query("      db_update('node_lnid_next')
18                          UPDATE {node_lnid_next}        ->fields(array(
19                          SET next_lnid = next_lnid + 1          'next_lnid' => $node->lnid + 1
20                          WHERE type = '%s'        ))
21                  ",        ->condition('type', $node->type)
22                          $node->type        ->execute();
                 );  
23          }          }
24          else {          else {
25                  db_query("  
26                          INSERT INTO {node_lnid_next}      db_insert('node_lnid_next')
27                          SET type = '%s',              ->fields(array(
28                          next_lnid = 2                'type' => $node->type,
29                  ",                'next_lnid' => 2
30                          $node->type              ))
31                  );              ->execute();
32    
33                  $node->lnid = 1;                  $node->lnid = 1;
34          }          }
35    
36          db_query("    db_insert('node_lnid')
37                  INSERT INTO {node_lnid}            ->fields(array(
38                  SET nid = %d,              'nid' => $node->nid,
39                          lnid = %d              'lnid' => $node->lnid
40          ",            ))
41                  $node->nid,            ->execute();
                 $node->lnid  
         );  
42  }  }
43    
44    
45  function type_local_nids_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {  /**
46    * Implement hook_node_insert().
47    */
48    function type_local_nids_node_insert($node) {
49    
50          switch ($op) {    _type_local_nids_generate_lnid($node);
51    }
                 case 'load':  
   
                         $node->lnid = db_result(db_query("  
                                 SELECT lnid  
                                 FROM {node_lnid}  
                                 WHERE nid = %d  
                         ",  
                                 $node->nid  
                         ));  
   
                 case 'insert':  
                 case 'update':  
   
                         if(!$node->lnid)  
                                 _type_local_nids_generate_lnid($node);  
   
                         break;  
52    
53    
54                  case 'delete':  /**
55    * Implement hook_node_load().
56                          db_query("  */
57                                  DELETE FROM {node_lnid}  function type_local_nids_node_load($nodes, $types) {
58                                  WHERE nid = %d  
59                          ",    $result = db_select('node_lnid', NULL, array('fetch' => PDO::FETCH_ASSOC))
60                                  $node->nid      ->fields('node_lnid')
61                          );      ->condition('nid', array_keys($nodes), 'IN')
62        ->execute();
63                          break;  
64          }    foreach($result as $record) {
65    
66        if($record['lnid'])
67          $nodes[$record['nid']]->lnid = $record['lnid'];
68        else
69                    _type_local_nids_generate_lnid($nodes[$record['nid']]);
70      }
71  }  }
72    
73    
74  function type_local_nids_node_type($op, $info) {  /**
75    * Implement hook_node_delete().
76          switch ($op){  */
77    function type_local_nids_node_delete($node) {
78    
79      db_delete('node_lnid')
80        ->condition('nid', $node->nid)
81        ->execute();
82    }
83    
                 case 'delete':  
84    
85                          db_query("  /**
86                                  DELETE FROM {node_lnid_next}  * Implement hook_node_type_update().
87                                  WHERE type = '%s'  */
88                          ",  function type_local_nids_node_type_update($info) {
                                 $node->type  
                         );  
89    
90                          break;          if(!empty($info->old_type) && $info->old_type != $info->type) {
91    
92        db_update('node_lnid_next')
93          ->fields(array(
94            'type' => $info->type
95          ))
96          ->condition('type', $info->old_type)
97          ->execute();
98            }
99    }
100    
101    
102                  case 'update':  /**
103    * Implement hook_node_type_delete().
104                          if(!empty($info->old_type) && $info->old_type != $info->type) {  */
105    function type_local_nids_node_type_delete($info) {
106                                  db_query("  
107                                          UPDATE {node_lnid_next}    db_delete('node_lnid_next')
108                                          SET type = '%s'      ->condition('type', $info->type)
109                                          WHERE type = '%s'      ->execute();
                                 ",  
                                         $info->type,  
                                         $info->old_type  
                                 );  
                         }  
   
                         break;  
         }  
110  }  }
111    
112    
113    /**
114    * Implement hook_token_values().
115    */
116  function type_local_nids_token_values($type, $object = NULL, $options = array()) {  function type_local_nids_token_values($type, $object = NULL, $options = array()) {
117    
118    if($type == 'node') {    if($type == 'node') {
# Line 126  function type_local_nids_token_values($t Line 122  function type_local_nids_token_values($t
122  }  }
123    
124    
125    /**
126    * Implement hook_token_list().
127    */
128  function type_local_nids_token_list($type = 'all') {  function type_local_nids_token_list($type = 'all') {
129    
130    if($type == 'node' || $type == 'all') {    if($type == 'node' || $type == 'all') {

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2