tabledrag_example.install 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * @file
  4. * Install and uninstall functions for the tabledrag example module.
  5. *
  6. * This file contains the functions required to perform install and
  7. * uninstall operations.
  8. */
  9. /**
  10. * Implements hook_schema().
  11. *
  12. * This defines the database table which will hold the example item info.
  13. *
  14. * @ingroup tabledrag_example
  15. */
  16. function tabledrag_example_schema() {
  17. $schema['tabledrag_example'] = array(
  18. 'description' => 'Stores some entries for our tabledrag fun.',
  19. 'fields' => array(
  20. 'id' => array(
  21. 'description' => 'The primary identifier for each item',
  22. 'type' => 'serial',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. ),
  26. 'name' => array(
  27. 'description' => 'A name for this item',
  28. 'type' => 'varchar',
  29. 'length' => 32,
  30. 'not null' => TRUE,
  31. 'default' => '',
  32. ),
  33. 'description' => array(
  34. 'description' => 'A description for this item',
  35. 'type' => 'varchar',
  36. 'length' => 255,
  37. 'not null' => TRUE,
  38. 'default' => '',
  39. ),
  40. 'itemgroup' => array(
  41. 'description' => 'The group this item belongs to',
  42. 'type' => 'varchar',
  43. 'length' => 32,
  44. 'not null' => TRUE,
  45. 'default' => '',
  46. ),
  47. 'weight' => array(
  48. 'description' => 'The sortable weight for this item',
  49. 'type' => 'int',
  50. 'length' => 11,
  51. 'not null' => TRUE,
  52. 'default' => 0,
  53. ),
  54. 'pid' => array(
  55. 'description' => 'The primary id of the parent for this item',
  56. 'type' => 'int',
  57. 'length' => 11,
  58. 'unsigned' => TRUE,
  59. 'not null' => TRUE,
  60. 'default' => 0,
  61. ),
  62. 'depth' => array(
  63. 'description' => 'The depth of this item within the tree',
  64. 'type' => 'int',
  65. 'size' => 'small',
  66. 'unsigned' => TRUE,
  67. 'not null' => TRUE,
  68. 'default' => 0,
  69. ),
  70. ),
  71. 'primary key' => array('id'),
  72. );
  73. return $schema;
  74. }
  75. /**
  76. * Implements hook_install().
  77. *
  78. * This datafills the example item info which will be used in the example.
  79. *
  80. * @ingroup tabledrag_example
  81. */
  82. function tabledrag_example_install() {
  83. // Ensure translations don't break at install time.
  84. $t = get_t();
  85. // Insert some values into the database.
  86. $rows = array(
  87. array(
  88. 'name' => $t('Item One'),
  89. 'description' => $t('The first item'),
  90. 'itemgroup' => $t('Group1'),
  91. ),
  92. array(
  93. 'name' => $t('Item Two'),
  94. 'description' => $t('The second item'),
  95. 'itemgroup' => $t('Group1'),
  96. ),
  97. array(
  98. 'name' => $t('Item Three'),
  99. 'description' => $t('The third item'),
  100. 'itemgroup' => $t('Group1'),
  101. ),
  102. array(
  103. 'name' => $t('Item Four'),
  104. 'description' => $t('The fourth item'),
  105. 'itemgroup' => $t('Group2'),
  106. ),
  107. array(
  108. 'name' => $t('Item Five'),
  109. 'description' => $t('The fifth item'),
  110. 'itemgroup' => $t('Group2'),
  111. ),
  112. array(
  113. 'name' => $t('Item Six'),
  114. 'description' => $t('The sixth item'),
  115. 'itemgroup' => $t('Group2'),
  116. ),
  117. array(
  118. 'name' => $t('Item Seven'),
  119. 'description' => $t('The seventh item'),
  120. 'itemgroup' => $t('Group3'),
  121. ),
  122. array(
  123. 'name' => $t('A Root Node'),
  124. 'description' => $t('This item cannot be nested under a parent item'),
  125. 'itemgroup' => $t('Group3'),
  126. ),
  127. array(
  128. 'name' => $t('A Leaf Item'),
  129. 'description' => $t('This item cannot have child items'),
  130. 'itemgroup' => $t('Group3'),
  131. ),
  132. );
  133. if (db_table_exists('tabledrag_example')) {
  134. foreach ($rows as $row) {
  135. db_insert('tabledrag_example')->fields($row)->execute();
  136. }
  137. }
  138. }
  139. /**
  140. * Implements hook_uninstall().
  141. *
  142. * This removes the example data when the module is uninstalled.
  143. *
  144. * @ingroup tabledrag_example
  145. */
  146. function tabledrag_example_uninstall() {
  147. db_drop_table('tabledrag_example');
  148. }