/[drupal]/contributions/modules/biblio/biblio.install
ViewVC logotype

Contents of /contributions/modules/biblio/biblio.install

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


Revision 1.77 - (show annotations) (download) (as text)
Thu Oct 1 01:45:42 2009 UTC (8 weeks ago) by rjerome
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.76: +16 -2 lines
File MIME type: text/x-php
merged changes from 6--1 to HEAD
1 <?PHP
2 // $Id: biblio.install,v 1.76 2009/06/25 18:23:09 rjerome Exp $
3 function biblio_install() {
4 $result = array();
5
6 drupal_install_schema('biblio');
7
8 $result[] = _add_db_field_data();
9
10 $result[] = _add_publication_types();
11
12 $result[] = _add_custom_field_data();
13
14 //_enable_biblio_keyword_vocabulary();
15
16 $result[] = _set_system_weight();
17
18 if (count($result) == count(array_filter($result))) {
19 drupal_set_message(t('The biblio module has successfully added its tables to the database.'));
20 }
21 else {
22 drupal_set_message(t('Drupal encountered some errors while attempting to install the database tables for the biblio module.'), 'error');
23 }
24 }
25
26 function biblio_enable() {
27 if (module_exists('taxonomy')) _enable_biblio_vocabularies();
28 _set_system_weight();
29 //_enable_biblio_collection_vocabulary();
30 // _add_biblio_keywords();
31 }
32
33 function _enable_biblio_vocabularies(){
34 $vids = variable_get('biblio_vocabularies', array());
35 foreach ($vids as $vid ) {
36 if (($voc = taxonomy_vocabulary_load($vid))) {
37 $voc = (array) $voc;
38 $voc['nodes']['biblio'] = 1;
39 taxonomy_save_vocabulary($voc);
40 }
41 }
42 }
43
44 function biblio_disable() {
45 if (module_exists('taxonomy')) {
46 $voc = taxonomy_get_vocabularies();
47 foreach ($voc as $vid => $vocabulary) {
48 if (isset($vocabulary->nodes['biblio'])) {
49 $vids[] = $vid;
50 }
51 }
52 variable_set('biblio_vocabularies', $vids);
53 }
54 }
55
56 function biblio_uninstall(){
57 if (module_exists('taxonomy')) {
58 $voc = taxonomy_get_vocabularies();
59 foreach ($voc as $vid => $vocabulary) {
60 if ($vocabulary->module == 'biblio') taxonomy_del_vocabulary($vid);
61 }
62 }
63
64 $result = db_query("SELECT * FROM {node} WHERE type='biblio' ");
65 while ($node = db_fetch_object($result)){
66 db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
67 db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
68
69 // Remove this node from the search index if needed.
70 if (function_exists('search_wipe')) {
71 search_wipe($node->nid, 'node');
72 }
73 }
74
75 drupal_uninstall_schema('biblio');
76
77 $vars = db_query("SELECT * FROM {variable} WHERE name LIKE 'biblio_%'");
78 while ($var = db_fetch_object($vars)) {
79 variable_del($var->name);
80 }
81
82 cache_clear_all();
83
84 }
85
86 function _set_system_weight() {
87 return update_sql("UPDATE {system} SET weight = 9 WHERE name = 'biblio'");
88 }
89
90 function _enable_biblio_keyword_vocabulary(){
91
92
93 if ($vocabulary = taxonomy_vocabulary_load(variable_get('biblio_keyword_vocabulary', 0))) {
94 // Existing install. Add back forum node type, if the biblio
95 // vocabulary still exists. Keep all other node types intact there.
96 $vocabulary = (array) $vocabulary;
97 $vocabulary['nodes']['biblio'] = 1;
98 taxonomy_save_vocabulary($vocabulary);
99 }
100 // else {
101 // // Create the biblio vocabulary if it does not exist.
102 // $vocabulary = array(
103 // 'name' => 'Biblio Keywords',
104 // 'description' => t('This is a free tag vocabulary which contains the keywords from all nodes created by the biblio module'),
105 // 'help' => t('Enter a comma separated list of words. Phrases containing commas should be enclosed in double quotes'),
106 // 'nodes' => array('biblio' => 1),
107 // 'hierarchy' => 0,
108 // 'relations' => 1,
109 // 'tags' => 1,
110 // 'multiple' => 0,
111 // 'required' => 0,
112 // 'weight' => 0,
113 // 'module' => 'biblio',
114 // );
115 // taxonomy_save_vocabulary($vocabulary);
116 // variable_set('biblio_keyword_vocabulary', $vocabulary['vid']);
117 // }
118 return $vocabulary['vid'];
119 }
120 function _enable_biblio_collection_vocabulary(){
121 if ($vocabulary = taxonomy_vocabulary_load(variable_get('biblio_collection_vocabulary', 0))) {
122 // Existing install. Add back forum node type, if the biblio
123 // vocabulary still exists. Keep all other node types intact there.
124 $vocabulary = (array) $vocabulary;
125 $vocabulary['nodes']['biblio'] = 1;
126 taxonomy_save_vocabulary($vocabulary);
127 }
128 else {
129 // Create the forum vocabulary if it does not exist. Assign the vocabulary
130 // a low weight so it will appear first in forum topic create and edit
131 // forms.
132 $vocabulary = array(
133 'name' => 'Biblio Collections',
134 'description' => 'You may organize your publications into collections by adding a collection names to this vocabulary',
135 'help' => '',
136 'nodes' => array('biblio' => 1),
137 'hierarchy' => 0,
138 'relations' => 1,
139 'tags' => 0,
140 'multiple' => 1,
141 'required' => 0,
142 'weight' => 0,
143 'module' => 'biblio',
144 );
145 taxonomy_save_vocabulary($vocabulary);
146 variable_set('biblio_collection_vocabulary', $vocabulary['vid']);
147 $default_collection = array(
148 'name' => t('Default'),
149 'description' => t("This is the collection that all biblio entries will be a part of if no other collection is selected. Deleting this term will render all your biblio entries inaccessable. (You've been warned!)" ),
150 'parent' => array(),
151 'relations' => array(),
152 'synonyms' => '',
153 'weight' => 0,
154 'vid' => variable_get('biblio_collection_vocabulary', 0),
155 );
156 taxonomy_save_term($default_collection);
157 }
158 return $vocabulary['vid'];
159
160 }
161
162 /**
163 * Copies keywords from the biblio_keyword column of the biblio table
164 * to a taxonomy vocabulary
165 *
166 * @return none
167 */
168 function _add_biblio_keywords() {
169 set_time_limit(300);
170 $kw_sep = variable_get('biblio_keyword_sep', ',');
171 $vid = ($vid = variable_get('biblio_keyword_vocabulary', 0))? $vid:_enable_biblio_keyword_vocabulary();
172 if ($vid ){
173 $db_result = db_query("SELECT b.biblio_keywords, b.nid, b.vid FROM {biblio} b");
174 $result = array();
175 while ($row = db_fetch_object($db_result)) {
176 foreach(explode($kw_sep, $row->biblio_keywords) as $keyword) {
177 $result[] = array('value' => trim($keyword), 'nid' => $row->nid, 'vid' =>$row->vid);
178 }
179 db_query('DELETE tn.* FROM {term_node} tn INNER JOIN {term_data} td ON tn.tid = td.tid WHERE nid = %d AND td.vid = %d', $row->nid, $vid);
180 }
181 $inserted = array();
182 $count = 0;
183 foreach ($result as $keywords) {
184 // See if the term exists in the chosen vocabulary
185 // and return the tid; otherwise, add a new record.
186 $possibilities = taxonomy_get_term_by_name($keywords['value']);
187 $term_tid = NULL; // tid match, if any.
188 foreach ($possibilities as $possibility) {
189 if ($possibility->vid == $vid) {
190 $term_tid = $possibility->tid;
191 }
192 }
193
194 if (!$term_tid) {
195 $term = array('vid' => $vid, 'name' => $keywords['value']);
196 $status = taxonomy_save_term($term);
197 $term_tid = $term['tid'];
198 }
199
200 // Defend against duplicate, differently cased tags
201 if (!isset($inserted[$keywords['vid']][$term_tid])) {
202 db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $keywords['nid'], $keywords['vid'], $term_tid);
203 $inserted[$keywords['vid']][$term_tid] = TRUE;
204 $count++;
205 }
206 }
207 return array('success' => TRUE, 'query' => 'Added '.$count. ' keywords to the biblio/taxonomy keyword vocabulary');
208 }
209 return array('success' => FALSE, 'query' => 'Biblio keyword vocabulary not available');
210 }
211
212
213
214 function biblio_schema() {
215 $schema['biblio'] = array (
216 'fields' => array (
217 'nid' => array (
218 'type' => 'int',
219 'not null' => TRUE,
220 'default' => 0,
221 'description' =>'',
222 ),
223 'vid' => array (
224 'type' => 'int',
225 'not null' => TRUE,
226 'default' => 0,
227 'description' =>'',
228 ),
229 'biblio_type' => array (
230 'type' => 'int',
231 'not null' => TRUE,
232 'default' => 0,
233 'description' =>'',
234 ),
235 'biblio_number' => array (
236 'type' => 'varchar',
237 'length' => '128',
238 'description' =>'',
239 ),
240 'biblio_other_number' => array (
241 'type' => 'varchar',
242 'length' => '128',
243 'description' =>'',
244 ),
245 'biblio_secondary_title' => array (
246 'type' => 'varchar',
247 'length' => '255',
248 'description' =>'',
249 ),
250 'biblio_tertiary_title' => array (
251 'type' => 'varchar',
252 'length' => '255',
253 'description' =>'',
254 ),
255 'biblio_edition' => array (
256 'type' => 'varchar',
257 'length' => '255',
258 'description' =>'',
259 ),
260 'biblio_publisher' => array (
261 'type' => 'varchar',
262 'length' => '255',
263 'description' =>'',
264 ),
265 'biblio_place_published' => array (
266 'type' => 'varchar',
267 'length' => '255',
268 'description' =>'',
269 ),
270 'biblio_year' => array (
271 'type' => 'int',
272 'not null' => TRUE,
273 'default' => 9999,
274 'description' =>'',
275 ),
276 'biblio_volume' => array (
277 'type' => 'varchar',
278 'length' => '128',
279 'description' =>'',
280 ),
281 'biblio_pages' => array (
282 'type' => 'varchar',
283 'length' => '128',
284 'description' =>'',
285 ),
286 'biblio_date' => array (
287 'type' => 'varchar',
288 'length' => '16',
289 'description' =>'',
290 ),
291 'biblio_isbn' => array (
292 'type' => 'varchar',
293 'length' => '128',
294 'description' =>'',
295 ),
296 'biblio_lang' => array (
297 'type' => 'varchar',
298 'length' => '24',
299 'default' => 'eng',
300 'description' =>'',
301 ),
302 'biblio_abst_e' => array (
303 'type' => 'text',
304 'description' =>'',
305 ),
306 'biblio_abst_f' => array (
307 'type' => 'text',
308 'description' =>'',
309 ),
310 'biblio_full_text' => array (
311 'type' => 'int',
312 'default' => 0,
313 'description' =>'',
314 ),
315 'biblio_url' => array (
316 'type' => 'varchar',
317 'length' => '255',
318 'description' =>'',
319 ),
320 'biblio_issue' => array (
321 'type' => 'varchar',
322 'length' => '128',
323 'description' =>'',
324 ),
325 'biblio_type_of_work' => array (
326 'type' => 'varchar',
327 'length' => '128',
328 'description' =>'',
329 ),
330 'biblio_accession_number' => array (
331 'type' => 'varchar',
332 'length' => '128',
333 'description' =>'',
334 ),
335 'biblio_call_number' => array (
336 'type' => 'varchar',
337 'length' => '128',
338 'description' =>'',
339 ),
340 'biblio_notes' => array (
341 'type' => 'text',
342 'description' =>'',
343 ),
344 'biblio_custom1' => array (
345 'type' => 'text',
346 'description' =>'',
347 ),
348 'biblio_custom2' => array (
349 'type' => 'text',
350 'description' =>'',
351 ),
352 'biblio_custom3' => array (
353 'type' => 'text',
354 'description' =>'',
355 ),
356 'biblio_custom4' => array (
357 'type' => 'text',
358 'description' =>'',
359 ),
360 'biblio_custom5' => array (
361 'type' => 'text',
362 'description' =>'',
363 ),
364 'biblio_custom6' => array (
365 'type' => 'text',
366 'description' =>'',
367 ),
368 'biblio_custom7' => array (
369 'type' => 'text',
370 'description' =>'',
371 ),
372 'biblio_research_notes' => array (
373 'type' => 'text',
374 'description' =>'',
375 ),
376 'biblio_number_of_volumes' => array (
377 'type' => 'varchar',
378 'length' => '128',
379 'description' =>'',
380 ),
381 'biblio_short_title' => array (
382 'type' => 'varchar',
383 'length' => '255',
384 'description' =>'',
385 ),
386 'biblio_alternate_title' => array (
387 'type' => 'varchar',
388 'length' => '255',
389 'description' =>'',
390 ),
391 'biblio_original_publication' => array (
392 'type' => 'varchar',
393 'length' => '255',
394 'description' =>'',
395 ),
396 'biblio_reprint_edition' => array (
397 'type' => 'varchar',
398 'length' => '255',
399 'description' =>'',
400 ),
401 'biblio_translated_title' => array (
402 'type' => 'varchar',
403 'length' => '255',
404 'description' =>'',
405 ),
406 'biblio_section' => array (
407 'type' => 'varchar',
408 'length' => '128',
409 'description' =>'',
410 ),
411 'biblio_citekey' => array (
412 'type' => 'varchar',
413 'length' => '255',
414 'description' =>'',
415 ),
416 'biblio_coins' => array (
417 'type' => 'text',
418 'description' =>'',
419 ),
420 'biblio_doi' => array (
421 'type' => 'varchar',
422 'length' => '255',
423 'description' =>'',
424 ),
425 'biblio_issn' => array (
426 'type' => 'varchar',
427 'length' => '128',
428 'description' =>'',
429 ),
430 'biblio_auth_address' => array (
431 'type' => 'text',
432 'description' =>'',
433 ),
434 'biblio_remote_db_name' => array (
435 'type' => 'varchar',
436 'length' => '255',
437 'description' =>'',
438 ),
439 'biblio_remote_db_provider' => array (
440 'type' => 'varchar',
441 'length' => '255',
442 'description' =>'',
443 ),
444 'biblio_label' => array (
445 'type' => 'varchar',
446 'length' => '255',
447 'description' =>'',
448 ),
449 'biblio_access_date' => array (
450 'type' => 'varchar',
451 'length' => '255',
452 'description' =>'',
453 ),
454 'biblio_md5' => array (
455 'type' => 'varchar',
456 'length' => '32',
457 'description' =>'',
458 )
459 ),
460 'primary key' => array (
461 'vid'
462 ),
463 'indexes' => array (
464 'nid' => array (
465 'nid'
466 ),
467 'md5' => array (
468 'biblio_md5'
469 ),
470 'year' => array (
471 'biblio_year'
472 )
473 ),
474
475 );
476
477 $schema['biblio_fields'] = array(
478 'fields' => array(
479 'fid' => array(
480 'type' => 'int',
481 'not null' => TRUE,
482 'unsigned' => TRUE,
483 'default' => 0,
484 'description' =>'{biblio_fields}.fid of the node',
485 ),
486 'name' => array(
487 'type' => 'varchar',
488 'length' => '128',
489 'not null' => TRUE,
490 'default' => ''
491 ),
492 'type' => array(
493 'type' => 'varchar',
494 'length' => '128',
495 'not null' => TRUE,
496 'default' => 'textfield'
497 ),
498 'size' => array(
499 'type' => 'int',
500 'not null' => TRUE,
501 'unsigned' => TRUE,
502 'default' => 60,
503 ),
504 'maxsize' => array(
505 'type' => 'int',
506 'not null' => TRUE,
507 'unsigned' => TRUE,
508 'default' => 255,
509 ),
510 ),
511 'primary key' => array('fid'),
512 );
513
514 $schema['biblio_field_type'] = array(
515 'description' => 'Relational table linking {biblio_fields} with {biblio_field_type_data}',
516 'fields' => array(
517 'tid' => array(
518 'type' => 'int',
519 'not null' => TRUE,
520 'unsigned' => TRUE,
521 'default' => 0,
522 'description' =>'{biblio_types}.tid of the node',
523 ),
524 'fid' => array(
525 'type' => 'int',
526 'not null' => TRUE,
527 'unsigned' => TRUE,
528 'default' => 0,
529 'description' =>'{biblio_fields}.fid of the node',
530 ),
531 'ftdid' => array(
532 'type' => 'int',
533 'not null' => TRUE,
534 'unsigned' => TRUE,
535 'default' => 0,
536 'description' =>'{biblio_field_type_data}.ftdid of the node, points to the current data, default or custom',
537 ),
538 'cust_tdid' => array(
539 'type' => 'int',
540 'not null' => TRUE,
541 'unsigned' => TRUE,
542 'default' => 0,
543 'description' =>'This always points to the custom data for this field. Stored so we can switch back an forth between default and custom',
544 ),
545 'common' => array(
546 'type' => 'int',
547 'not null' => TRUE,
548 'unsigned' => TRUE,
549 'default' => 0,
550 ),
551 'autocomplete' => array(
552 'type' => 'int',
553 'not null' => TRUE,
554 'unsigned' => TRUE,
555 'default' => 0,
556 ),
557 'required' => array(
558 'type' => 'int',
559 'not null' => TRUE,
560 'unsigned' => TRUE,
561 'default' => 0,
562 'description' => 'Is input required for this field'
563 ),
564 'weight' => array(
565 'type' => 'int',
566 'not null' => TRUE,
567 'default' => 0,
568 'description' => 'The weight (location) of the field on the input form'
569 ),
570 'visible' => array(
571 'type' => 'int',
572 'not null' => TRUE,
573 'unsigned' => TRUE,
574 'default' => 0,
575 'description' => 'Determines if the field is visible on the input form'
576 ),
577
578 ),
579 'primary key' => array('tid', 'fid'),
580 'indexes' => array(
581 'tid' => array('tid')
582 ),
583 );
584
585 $schema['biblio_field_type_data'] = array(
586 'description' => 'Data used to build the form elements on the input form',
587 'fields' => array(
588 'ftdid' => array(
589 'type' => 'int',
590 'not null' => TRUE,
591 'unsigned' => TRUE,
592 'default' => 0,
593 'description' =>'{biblio_field_type_data}.ftdid of the node',
594 ),
595 'title' => array(
596 'type' => 'varchar',
597 'length' => '128',
598 'not null' => TRUE,
599 'default' => '',
600 'description' => 'The title, which will be displayed on the form, for a given field'
601 ),
602 'hint' => array(
603 'type' => 'varchar',
604 'length' => '255',
605 'description' => 'The hint text printed below the input widget'
606 ),
607 ),
608 'primary key' => array('ftdid'),
609 );
610
611 $schema['biblio_types'] = array(
612 'fields' => array(
613 'tid' => array(
614 'type' => 'int',
615 'not null' => TRUE,
616 'default' => 0,
617 'description' =>'{biblio_types}.tid of the publication type',
618 ),
619 'name' => array(
620 'type' => 'varchar',
621 'length' => '64',
622 'not null' => TRUE,
623 'default' => '',
624 'description' => 'The name of the publication type'
625 ),
626 'description' => array(
627 'type' => 'varchar',
628 'not null' => FALSE,
629 'length' => '255',
630 'description' => 'Description of the publication type'
631 ),
632 'weight' => array(
633 'type' => 'int',
634 'not null' => TRUE,
635 'default' => 0,
636 'description' => 'Controls the order the types are listed in'
637 ),
638 'visible' => array(
639 'type' => 'int',
640 'not null' => TRUE,
641 'unsigned' => TRUE,
642 'default' => 1,
643 'description' => 'Determines if the publication type is visible in the list'
644 ),
645 ),
646 'primary key' => array('tid'),
647
648 );
649
650
651
652 $schema['biblio_contributor'] = array(
653 'description' => 'Relational table linking authors to biblio entries',
654 'fields' => array(
655 'nid' => array(
656 'type' => 'int',
657 'not null' => TRUE,
658 'unsigned' => TRUE,
659 'default' => 0,
660 'description' =>'{node}.nid of the node',
661 ),
662 'vid' => array(
663 'type' => 'int',
664 'not null' => TRUE,
665 'unsigned' => TRUE,
666 'default' => 0,
667 'description' =>'{node}.vid of the node',
668 ),
669 'cid' => array(
670 'type' => 'int',
671 'not null' => TRUE,
672 'unsigned' => TRUE,
673 'default' => 0,
674 'description' =>'{biblio_contributor_data}.cid of the node',
675 ),
676 'auth_type' => array(
677 'type' => 'int',
678 'not null' => TRUE,
679 'unsigned' => TRUE,
680 'default' => 1,
681 'description' =>'{biblio_contributor_type}.auth_type of the node',
682 ),
683 'auth_category' => array(
684 'type' => 'int',
685 'not null' => TRUE,
686 'unsigned' => TRUE,
687 'default' => 1,
688 'description' =>'',
689 ),
690 'rank' => array(
691 'type' => 'int',
692 'not null' => TRUE,
693 'unsigned' => TRUE,
694 'default' => 0,
695 'description' =>'Position of the author name on the publication (first,second,third...)',
696 )
697 ),
698 'primary key' => array('vid', 'cid', 'auth_type', 'rank'),
699 );
700
701 $schema['biblio_contributor_data'] = array(
702 'description' =>'Contains Author information for each publication',
703 'fields' => array(
704 'cid' => array(
705 'type' => 'serial',
706 'not null' => TRUE,
707 'unsigned' => TRUE,
708 'description' =>'Primary Key: Author ID',
709 ),
710 'aka' => array(
711 'type' => 'int',
712 'not null' => TRUE,
713 'default' => 0,
714 'unsigned' => TRUE,
715 'description' =>'Also known as, links this author entry with others so you can have variation on the name, but listing by cid will find all other (aka) author entries',
716 ),
717 'drupal_uid' => array(
718 'type' => 'int',
719 'not null' => FALSE,
720 'unsigned' => TRUE,
721 'description' =>'Drupal User ID',
722 ),
723 'name' => array(
724 'type' => 'varchar',
725 'length' => '128',
726 'not null' => TRUE,
727 'default' => '',
728 'description' =>'Author last name',
729 ),
730 'lastname' => array(
731 'type' => 'varchar',
732 'length' => '128',
733 'not null' => TRUE,
734 'default' => '',
735 'description' =>'Author last name',
736 ),
737 'firstname' => array(
738 'type' => 'varchar',
739 'length' => '128',
740 'not null' => FALSE,
741 'default' => '',
742 'description' =>'Author first name',
743 ),
744 'prefix' => array(
745 'type' => 'varchar',
746 'length' => '128',
747 'not null' => FALSE,
748 'default' => '',
749 'description' =>'Author name prefix',
750 ),
751 'suffix' => array(
752 'type' => 'varchar',
753 'length' => '128',
754 'not null' => FALSE,
755 'default' => '',
756 'description' =>'Author name suffix',
757 ),
758 'initials' => array(
759 'type' => 'varchar',
760 'length' => '10',
761 'not null' => FALSE,
762 'default' => '',
763 'description' =>'Author initials (including first name initial)',
764 ),
765 'affiliation' => array(
766 'type' => 'varchar',
767 'length' => '255',
768 'not null' => FALSE,
769 'default' => '',
770 'description' =>'Author affiliation or address',
771 ),
772 'md5' => array (
773 'type' => 'varchar',
774 'length' => '32',
775 'not null' => FALSE,
776 'description' =>'',
777 )
778
779 ),
780 'primary key' => array('cid','aka'),
781 'indexes' => array(
782 'lastname' => array('lastname'),
783 'firstname' => array('firstname'),
784 'initials' => array('initials')
785
786 )
787 );
788 $schema['biblio_contributor_type'] = array(
789 'description' =>'Contains definitions of the contributor types',
790 'fields' => array(
791 'auth_category' => array(
792 'type' => 'int',
793 'not null' => TRUE,
794 'unsigned' => TRUE,
795 'default' => 0,
796 'description' =>'There are 5 catagoies of author: Primary, Secondary, Tertiery, Subsidary and Corporate ',
797 ),
798 'biblio_type' => array(
799 'type' => 'int',
800 'not null' => TRUE,
801 'unsigned' => TRUE,
802 'default' => 0,
803 'description' =>'',
804 ),
805 'auth_type' => array(
806 'type' => 'int',
807 'not null' => TRUE,
808 'unsigned' => TRUE,
809 'default' => 0,
810 'description' =>'This is the pulication type specific verion of a particular catagory',
811 ),
812 ),
813 'primary key' => array('auth_category','biblio_type', 'auth_type'),
814
815 );
816
817 $schema['biblio_contributor_type_data'] = array(
818 'description' => 'Data used to build the form elements on the input form',
819 'fields' => array(
820 'auth_type' => array(
821 'type' => 'serial',
822 'not null' => TRUE,
823 'unsigned' => TRUE,
824 'description' =>'{biblio_contributor_type_data} ctdid of the node',
825 ),
826 'title' => array(
827 'type' => 'varchar',
828 'length' => '128',
829 'not null' => TRUE,
830 'default' => '',
831 'description' => 'The title, which will be displayed on the form, for a given field'
832 ),
833 'hint' => array(
834 'type' => 'varchar',
835 'length' => '255',
836 'description' => 'The hint text printed below the input widget'
837 ),
838 ),
839 'primary key' => array('auth_type'),
840 );
841
842 $schema['biblio_keyword'] = array(
843 'description' => t('Relational table linking keywords to biblio nodes'),
844 'fields' => array(
845 'kid' => array(
846 'type' => 'int',
847 'not null' => TRUE,
848 'unsigned' => TRUE,
849 'default' => 0,
850 'description' => t('Primary Key: The {biblio_keyword_data}.kid of the keyword of the node ')
851 ),
852 'nid' => array(
853 'type' => 'int',
854 'not null' => TRUE,
855 'unsigned' => TRUE,
856 'default' => 0,
857 'description' => t('The {node}.nid of the node.'),
858 ),
859 'vid' => array(
860 'type' => 'int',
861 'not null' => TRUE,
862 'unsigned' => TRUE,
863 'default' => 0,
864 'description' => t('Primary Key: The {node}.vid of the node.'),
865 ),
866 ),
867 'primary key' => array('kid', 'vid'),
868 'indexes' => array(
869 'vid' => array('vid'),
870 'nid' => array('nid'),
871 ),
872 );
873
874 $schema['biblio_keyword_data'] = array(
875 'description' => t('Stores the keywords related to nodes.'),
876 'fields' => array(
877 'kid' => array(
878 'type' => 'serial',
879 'not null' => TRUE,
880 'unsigned' => TRUE,
881 'description' => t('Primary Key: The id of the keyword assigned to the node ')
882 ),
883 'word' => array(
884 'type' => 'varchar',
885 'length' => 255,
886 'not null' => TRUE,
887 'default' => '',
888 'description' => t('The keyword'),
889 ),
890 ),
891 'primary key' => array('kid'),
892 'indexes' => array(
893 'kword' => array('word'),
894 ),
895 );
896 $schema['biblio_collection'] = array(
897 'description' => t('Relational table grouping biblio nodes into collections'),
898 'fields' => array(
899 'cid' => array(
900 'type' => 'int',
901 'not null' => TRUE,
902 'unsigned' => TRUE,
903 'default' => 0,
904 'description' => t('Primary Key: The {biblio_collection_data}.cid of the collection')
905 ),
906 'vid' => array(
907 'type' => 'int',
908 'not null' => TRUE,
909 'unsigned' => TRUE,
910 'default' => 0,
911 'description' => t('Primary Key: The {node}.vid of the node.'),
912 ),
913 'pid' => array(
914 'type' => 'int',
915 'not null' => TRUE,
916 'unsigned' => TRUE,
917 'default' => 0,
918 'description' => t('The parent id of the collection')
919 ),
920 'nid' => array(
921 'type' => 'int',
922 'not null' => TRUE,
923 'unsigned' => TRUE,
924 'default' => 0,
925 'description' => t('The {node}.nid of the node.'),
926 ),
927 ),
928 'primary key' => array('cid','vid'),
929 'indexes' => array(
930 'pid' => array('pid'),
931 'nid' => array('nid'),
932 ),
933 );
934 $schema['biblio_collection_type'] = array(
935 'description' => t('Descriptions of the collections.'),
936 'fields' => array(
937 'cid' => array(
938 'type' => 'int',
939 'not null' => TRUE,
940 'unsigned' => TRUE,
941 'default' => 0,
942 'description' => t('Primary Key: The id of the collection ')
943 ),
944 'name' => array(
945 'type' => 'varchar',
946 'length' => 255,
947 'not null' => TRUE,
948 'default' => '',
949 'description' => t('The name of the collection'),
950 ),
951 'description' => array(
952 'type' => 'varchar',
953 'length' => 255,
954 'not null' => TRUE,
955 'default' => '',
956 'description' => t('The description of the collection'),
957 ),
958 ),
959 'primary key' => array('cid'),
960 'indexes' => array(
961 'name' => array('name'),
962 ),
963 );
964 $schema['biblio_duplicates'] = array(
965 'description' => t('Relational table linking possible duplicate biblio nodes'),
966 'fields' => array(
967 'vid' => array(
968 'type' => 'int',
969 'not null' => TRUE,
970 'unsigned' => TRUE,
971 'default' => 0,
972 'description' => t('Primary Key: The {biblio}.nid of the original node ')
973 ),
974 'did' => array(
975 'type' => 'int',
976 'not null' => TRUE,
977 'unsigned' => TRUE,
978 'default' => 0,
979 'description' => t('The {biblio}.nid of the newly imported node which may be a duplicate.'),
980 ),
981 'type' => array(
982 'type' => 'int',
983 'not null' => TRUE,
984 'unsigned' => TRUE,
985 'default' => 0,
986 'description' => t('The type of duplicate 0=biblio, 1=author.'),
987 ),
988 ),
989 'primary key' => array('vid','did'),
990 'indexes' => array(
991 'did' => array('vid'),
992 ),
993 );
994
995 $schema['biblio_import_cache'] = array(
996 'description' => 'tables used for caching data imported from file and then batch processed',
997 'fields' => array(
998 'id' => array(
999 'type'=>'serial',
1000 'not null' => TRUE,
1001 'unsigned' => TRUE),
1002 'session_id' => array(
1003 'type' => 'varchar',
1004 'length' => 45,
1005 'not null' => TRUE),
1006 'data' => array(
1007 'description' => t('A collection of data to cache.'),
1008 'type' => 'blob',
1009 'not null' => FALSE,
1010 'size' => 'big'),
1011 ),
1012 'primary key' => array('id'));
1013
1014 return ($schema);
1015
1016 }
1017
1018 function biblio_reset_types(){
1019 $result = array();
1020
1021 db_drop_table($result, 'biblio_field_type_data');
1022 db_drop_table($result, 'biblio_field_type');
1023 db_drop_table($result, 'biblio_fields');
1024 db_drop_table($result, 'biblio_contributor_type');
1025 db_drop_table($result, 'biblio_contributor_type_data');
1026
1027 $schema = biblio_schema();
1028 db_create_table($result, 'biblio_field_type_data', $schema['biblio_field_type_data']);
1029 db_create_table($result, 'biblio_field_type', $schema['biblio_field_type']);
1030 db_create_table($result, 'biblio_fields', $schema['biblio_fields']);
1031 db_create_table($result, 'biblio_contributor_type', $schema['biblio_contributor_type']);
1032 db_create_table($result, 'biblio_contributor_type_data', $schema['biblio_contributor_type_data']);
1033
1034 variable_set('biblio_last_ftdid', 100); // reset custom field type id too
1035 //_add_db_field_data_XML();
1036 _add_db_field_data();
1037 _add_custom_field_data();
1038 }
1039
1040 function _add_publication_types()
1041 {
1042 $types[] = array(-1,'Select Type...',NULL,-10);
1043 $types[] = array(100,'Book',NULL,1);
1044 $types[] = array(101,'Book Chapter',NULL,2);
1045 $types[] = array(102,'Journal Article',NULL,3);
1046 $types[] = array(103,'Conference Paper',NULL,4);
1047 $types[] = array(104,'Conference Proceedings',NULL,5);
1048 $types[] = array(105,'Newspaper Article',NULL,6);
1049 $types[] = array(106,'Magazine Article',NULL,7);
1050 $types[] = array(107,'Web Article',NULL,8);
1051 $types[] = array(108,'Thesis',NULL,9);
1052 $types[] = array(109,'Report',NULL,10);
1053 $types[] = array(110,'Film',NULL,11);
1054 $types[] = array(111,'Broadcast',NULL,12);
1055 $types[] = array(112,'Artwork',NULL,13);
1056 $types[] = array(113,'Software',NULL,14);
1057 $types[] = array(114,'Audiovisual',NULL,15);
1058 $types[] = array(115,'Hearing',NULL,16);
1059 $types[] = array(116,'Case',NULL,17);
1060 $types[] = array(117,'Bill',NULL,18);
1061 $types[] = array(118,'Statute',NULL,19);
1062 $types[] = array(119,'Patent',NULL,20);
1063 $types[] = array(120,'Personal',NULL,21);
1064 $types[] = array(121,'Manuscript',NULL,22);
1065 $types[] = array(122,'Map',NULL,23);
1066 $types[] = array(123,'Chart',NULL,24);
1067 $types[] = array(124,'Unpublished',NULL,25);
1068 $types[] = array(125,'Database',NULL,26);
1069 $types[] = array(126,'Government Report',NULL,27);
1070 $types[] = array(127,'Classical' ,NULL,28);
1071 $types[] = array(128,'Legal Ruling' ,NULL,29);
1072 $types[] = array(129,'Miscellaneous' ,NULL,30);
1073 $types[] = array(130,'Miscellaneous Section' ,NULL,31);
1074
1075 foreach($types as $record)
1076 {
1077 $result[] = update_sql("INSERT INTO {biblio_types} (tid, name, description, weight) VALUES ('" . implode("', '", $record) . "')");
1078 }
1079 return $result;
1080 }
1081
1082 function _add_db_field_data_XML() {
1083 $next_ctdid=10; //first contributor_type_data id
1084 $schema = biblio_schema();
1085 $fieldnames = array_keys($schema['biblio_fields']['fields']);
1086 $field_type_fieldnames = array_keys($schema['biblio_field_type']['fields']);
1087 $field_type_data_fieldnames = array_keys($schema['biblio_field_type_data']['fields']);
1088 db_query("/*!40000 ALTER TABLE {biblio_field_type_data} DISABLE KEYS */;");
1089 db_query("/*!40000 ALTER TABLE {biblio_fields} DISABLE KEYS */;");
1090 for ($type = 1; $type <= 5; $type++) {
1091 for ($biblio_type = 100; $biblio_type <= 130; $biblio_type++) {
1092 db_query("INSERT INTO {biblio_contributor_type} (auth_category, biblio_type, auth_type) VALUES (%d, %d, %d)", $type, $biblio_type, $type);
1093 }
1094 }
1095 // db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", 1, "Author");
1096 // db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", 2, "Secondary Author");
1097 // db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", 3, "Tertiary Author ");
1098 // db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", 4, "Subsidiary Author ");
1099 // db_query("INSERT INTO {biblio_contributor_type_data} (auth_type, title) VALUES (%d, '%s' )", 5, "Corporate Author ");
1100 _id_by_name(NULL, NULL, NULL, array('tablename' => 'biblio_field_type_data', 'name_column' => 'title', 'id_column' => 'ftdid'));
1101 // _id_by_name(NULL, NULL, NULL, array('tablename' => 'biblio_contributor_type_data', 'name_column' => 'title', 'id_column' => 'auth_type'));
1102
1103 $xml_file = drupal_get_path('module', 'biblio') .'/field_data.xml';
1104 $xml = simplexml_load_file($xml_file);
1105 foreach($xml->field as $field){
1106 $link_data = array(0, $field['fid'], $field['fid'], $field['fid'], $field->common, $field->autocomplete, $field->required, $field->weight, $field->visible);
1107 db_query("INSERT INTO {biblio_field_type} (". implode(", ", $field_type_fieldnames) . ")
1108 VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d)", $link_data);
1109 for ($t = 100; $t <= 130; $t++)
1110 {
1111 $values = array($t, $field['fid'], $field['fid'], $field['fid'], $field->common, $field->autocomplete, $field->required, $field->weight, $field->visible);
1112 db_query("INSERT INTO {biblio_field_type} (". implode(", ", $field_type_fieldnames) . ")
1113 VALUES('" . implode("', '", $values) . "')");
1114 }
1115 $ftd = array($field['fid'], $field->default_name, $field->hint);
1116 db_query("INSERT INTO {biblio_field_type_data} (" . implode(", ", $field_type_data_fieldnames) . ")
1117 VALUES('" . implode("', '", $ftd) . "')");
1118 $field_data = array($field['fid'], $field->field_name, $field->type,