/[drupal]/contributions/modules/refcolab/includes/db_schema_meta.inc
ViewVC logotype

Diff of /contributions/modules/refcolab/includes/db_schema_meta.inc

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

revision 1.1, Fri Jun 13 02:26:39 2008 UTC revision 1.2, Tue Jun 17 03:55:52 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: db_schema_meta.inc,v 1.1 2008/06/13 02:26:39 herc Exp $
3    
4  require_once './'. drupal_get_path('module', 'refcolab') .'/includes/fields_meta.inc';  require_once './'. drupal_get_path('module', 'refcolab') .'/includes/fields_meta.inc';
5  require_once './'. drupal_get_path('module', 'refcolab') .'/includes/reference_types_meta.inc';  require_once './'. drupal_get_path('module', 'refcolab') .'/includes/reference_types_meta.inc';
6    
7  /**  /**
8   * Return the DB schema used to store the meta data for   * Return the DB schema used to store the meta data for
9   * reference types - fields relationship.   * reference types - fields relationship.
10   */   */
11  function _refcolab_db_schema_meta() {  function _refcolab_db_schema_meta() {
12    $meta['refcolab_meta_types'] = array(    $meta['refcolab_meta_types'] = array(
# Line 29  function _refcolab_db_schema_meta() { Line 29  function _refcolab_db_schema_meta() {
29          'type' => 'varchar',          'type' => 'varchar',
30          'not null' => TRUE,          'not null' => TRUE,
31          'length' => 255,          'length' => 255,
32        ),        ),
33        'user_defined' => array(        'user_defined' => array(
34          'description' => t('Indicates whether the reference type is define by the user.'),          'description' => t('Indicates whether the reference type is define by the user.'),
35          'type' => 'int',          'type' => 'int',
36          'unsigned' => TRUE,          'unsigned' => TRUE,
37          'not null' => TRUE,          'not null' => TRUE,
38          'default' => 0,          'default' => 0,
39        ),        ),
40      ),      ),
41      'primary key' => array('type_name'),      'primary key' => array('type_name'),
42    );    );
   
43    $meta['refcolab_meta_fields'] = array(    $meta['refcolab_meta_fields'] = array(
44      'description' => t('Reference fields.'),      'description' => t('Reference\'s fields.'),
45      'fields' => array(      'fields' => array(
46        'field_name' => array(        'field_name' => array(
47          'description' => t('Primary Key: Unique field name.'),          'description' => t('Primary Key: Unique field name.'),
# Line 55  function _refcolab_db_schema_meta() { Line 54  function _refcolab_db_schema_meta() {
54          'type' => 'varchar',          'type' => 'varchar',
55          'not null' => TRUE,          'not null' => TRUE,
56          'length' => 128,          'length' => 128,
57        ),        ),
58        'description' => array(        'description' => array(
59          'description' => t('Field description.'),          'description' => t('Field description.'),
60          'type' => 'varchar',          'type' => 'varchar',
# Line 66  function _refcolab_db_schema_meta() { Line 65  function _refcolab_db_schema_meta() {
65          'description' => t('A serialized array containing the widge data for the field.'),          'description' => t('A serialized array containing the widge data for the field.'),
66          'type' => 'text',          'type' => 'text',
67          'not null' => FALSE,          'not null' => FALSE,
68          'size' => 'big',          'size' => 'big',
69        ),        ),
70      ),      ),
71      'primary key' => array('field_name'),      'primary key' => array('field_name'),
72      );
73      $meta['refcolab_meta_creators'] = array(
74        'description' => t('Reference\'s creators fields.'),
75        'fields' => array(
76          'creator' => array(
77            'description' => t('Primary Key: Unique creator name.'),
78            'type' => 'varchar',
79            'not null' => TRUE,
80            'length' => 32,
81          ),
82          'creator_title' => array(
83            'description' => t('Field title.'),
84            'type' => 'varchar',
85            'not null' => TRUE,
86            'length' => 128,
87          ),
88          'description' => array(
89            'description' => t('Field description.'),
90            'type' => 'varchar',
91            'not null' => TRUE,
92            'length' => 255,
93          ),
94        ),
95        'primary key' => array('creator'),
96    );    );
   
97    $meta['refcolab_meta_types_fields'] = array(    $meta['refcolab_meta_types_fields'] = array(
98      'description' => t('Reference types\' fields. Stores the reference types - fields relationship'),      'description' => t('Reference types\' fields. Stores the reference types - fields relationship'),
99      'fields' => array(      'fields' => array(
# Line 79  function _refcolab_db_schema_meta() { Line 101  function _refcolab_db_schema_meta() {
101          'description' => t('Primary Key: Unique reference type name.'),          'description' => t('Primary Key: Unique reference type name.'),
102          'type' => 'varchar',          'type' => 'varchar',
103          'not null' => TRUE,          'not null' => TRUE,
104          'length' => 32,          'length' => 32,
105        ),        ),
106        'field_name' => array(        'field_name' => array(
107          'description' => t('Primary key: Unique field name.'),          'description' => t('Primary key: Unique field name.'),
# Line 88  function _refcolab_db_schema_meta() { Line 110  function _refcolab_db_schema_meta() {
110          'length' => 32,          'length' => 32,
111        ),        ),
112        'weight' => array(        'weight' => array(
113          'description' => t('The weight of this field in relation to other fields.'),          'description' => t('The weight of this field in relation to other fields.'),
114          'type' => 'int',          'type' => 'int',
115          'not null' => TRUE,          'not null' => TRUE,
116          'default' => 0,          'default' => 0,
# Line 99  function _refcolab_db_schema_meta() { Line 121  function _refcolab_db_schema_meta() {
121          'type' => 'int',          'type' => 'int',
122          'not null' => TRUE,          'not null' => TRUE,
123          'default' => 0,          'default' => 0,
124        ),        ),
125        ),
126        'primary key' => array('type_name', 'field_name'),
127      );
128      $meta['refcolab_meta_types_creators'] = array(
129        'description' => t('Reference types\' creator fields.'),
130        'fields' => array(
131          'type_name' => array(
132            'description' => t('Primary Key: Unique reference type name.'),
133            'type' => 'varchar',
134            'not null' => TRUE,
135            'length' => 32,
136          ),
137          'creator' => array(
138            'description' => t('Primary key: The creator field name.'),
139            'type' => 'varchar',
140            'not null' => TRUE,
141            'length' => 32,
142          ),
143          'weight' => array(
144            'description' => t('The weight of this field in relation to other fields.'),
145            'type' => 'int',
146            'not null' => TRUE,
147            'default' => 0,
148            'size' => 'tiny',
149          ),
150      ),      ),
151      'primary key' => array('type_name', 'field_name'),      'primary key' => array('type_name', 'creator'),
152    );    );
153    return $meta;    return $meta;
154  }  }
155    
156  /**  /**
# Line 112  function _refcolab_db_schema_meta() { Line 159  function _refcolab_db_schema_meta() {
159  function _refcolab_type_table($type_name) {  function _refcolab_type_table($type_name) {
160    return array(    return array(
161      'refcolab_type_'. $type_name => array(      'refcolab_type_'. $type_name => array(
162        'description' => t('Stores references of type '. $type_name),        'description' => t('Stores references of type '. $type_name),
163        'fields' => array(        'fields' => array(
164          'nid' => array(          'nid' => array(
165            'description' => t('The {node}.nid of the related node.'),            'description' => t('The {node}.nid of the related node.'),
166            'type' => 'int',            'type' => 'int',
167            'unsigned' => TRUE,            'unsigned' => TRUE,
168            'not null' => TRUE,            'not null' => TRUE,
169          ),          ),
170          'vid' => array(          'vid' => array(
171            'description' => t('Primary Key: The {node}.vid of the related node.'),            'description' => t('Primary Key: The {node}.vid of the related node.'),
172            'type' => 'int',            'type' => 'int',
173            'unsigned' => TRUE,            'unsigned' => TRUE,
174            'not null' => TRUE,            'not null' => TRUE,
175          ),          ),
176        ),        ),
   
177        'primary key' => array('vid'),        'primary key' => array('vid'),
   
178      ),      ),
179    );    );
180  }  }
181    
182  /**  /**
# Line 141  function _refcolab_db_schema_dynamic() { Line 186  function _refcolab_db_schema_dynamic() {
186    $types = refcolab_reference_types_meta();    $types = refcolab_reference_types_meta();
187    $fields = refcolab_fields_meta();    $fields = refcolab_fields_meta();
188    $schema = array();    $schema = array();
189    
190    foreach($types as $type_name => $type) {    foreach($types as $type_name => $type) {
191      $type_name = strtolower($type_name);      $type_name = strtolower($type_name);
192    
193        $schema += _refcolab_type_table($type_name);
194    
     $schema += _refcolab_type_table($type_name);  
   
195      foreach($type['fields'] as $field_name) {      foreach($type['fields'] as $field_name) {
196        $schema['refcolab_type_'. $type_name]['fields'][strtolower($field_name)] = $fields[$field_name]['data'];        $schema['refcolab_type_'. $type_name]['fields'][strtolower($field_name)] = $fields[$field_name]['data'];
197      }      }
198    }    }
199    
200    return $schema;    return $schema;
201  }  }
202    
# Line 160  function _refcolab_db_schema_dynamic() { Line 205  function _refcolab_db_schema_dynamic() {
205   */   */
206  function _refcolab_install_meta() {  function _refcolab_install_meta() {
207    // Populate the {refcolab_meta_fields} table.    // Populate the {refcolab_meta_fields} table.
208    $fields = refcolab_fields_meta();    $fields = refcolab_fields_meta();
209    foreach($fields as $field_name => $field) {    foreach($fields as $field_name => $field) {
210      $widget = serialize($field['widget']);      $widget = serialize($field['widget']);
211      db_query("INSERT INTO {refcolab_meta_fields} (field_name, field_title, description, widget) VALUES ('%s', '%s', '%s', '%s')",      db_query("INSERT INTO {refcolab_meta_fields} (field_name, field_title, description, widget) VALUES ('%s', '%s', '%s', '%s')",
212        strtolower($field_name), $field['title'], $field['description'], $widget);        strtolower($field_name), $field['title'], $field['description'], $widget);
213    }    }
214    
215      // Populate the {refcolab_meta_creators} table.
216      $creators = refcolab_creators_meta();
217      foreach($creators as $creator_name  => $creator) {
218        // @TODO: add description to creators.
219        db_query("INSERT INTO {refcolab_meta_creators} (creator, creator_title) VALUES ('%s', '%s')",
220          strtolower($creator_name), $creator['title']);
221      }
222    
223    // Populate the {refcolab_meta_types} table.    // Populate the {refcolab_meta_types} table.
224    $types = refcolab_reference_types_meta();    $types = refcolab_reference_types_meta();
225    foreach($types as $type_name => $type) {    foreach($types as $type_name => $type) {
226      db_query("INSERT INTO {refcolab_meta_types} (type_name, type_title, description) VALUES ('%s', '%s', '%s')",      db_query("INSERT INTO {refcolab_meta_types} (type_name, type_title, description) VALUES ('%s', '%s', '%s')",
227        strtolower($type_name), $type['title'], $type['description']);        strtolower($type_name), $type['title'], $type['description']);
228    
229      // Generate the reference type - fields relationship;      // Generate the reference type - fields relationship.
230      $weight = 0;      $weight = 0;
231      foreach($type['fields'] as $field_name) {      foreach($type['fields'] as $field_name) {
232        db_query("INSERT INTO {refcolab_meta_types_fields} (type_name, field_name, weight) VALUES ('%s', '%s', %d)", strtolower($type_name), strtolower($field_name), $weight++);        db_query("INSERT INTO {refcolab_meta_types_fields} (type_name, field_name, weight) VALUES ('%s', '%s', %d)", strtolower($type_name), strtolower($field_name), $weight++);
233        }
234    
235        // Generate the reference type - creator fields relationship.
236        $weight = 0;
237        foreach($type['creators'] as $creator) {
238          db_query("INSERT INTO {refcolab_meta_types_creators} (type_name, creator, weight) VALUES ('%s', '%s', %d)", strtolower($type_name), strtolower($creator), $weight++);
239      }      }
240    }    }
241  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2