tablesort_example.install 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Install and uninstall functions for the tablesort example module.
  5. *
  6. * This file contains the functions required to perform install and
  7. * uninstall operations.
  8. */
  9. /**
  10. * Implements hook_install().
  11. *
  12. * @ingroup tablesort_example
  13. */
  14. function tablesort_example_install() {
  15. // Let's fill the database with some values for sorting.
  16. $rows = array(
  17. array('numbers' => 1, 'alpha' => 'e', 'random' => '912cv21'),
  18. array('numbers' => 2, 'alpha' => 'a', 'random' => '0kuykuh'),
  19. array('numbers' => 3, 'alpha' => 'm', 'random' => 'fuye8734h'),
  20. array('numbers' => 4, 'alpha' => 'w', 'random' => '80jsv772'),
  21. array('numbers' => 5, 'alpha' => 'o', 'random' => 'd82sf-csj'),
  22. array('numbers' => 6, 'alpha' => 's', 'random' => 'au832'),
  23. array('numbers' => 7, 'alpha' => 'e', 'random' => 't982hkv'),
  24. );
  25. if (db_table_exists('tablesort_example')) {
  26. foreach ($rows as $row) {
  27. db_insert('tablesort_example')->fields($row)->execute();
  28. }
  29. }
  30. }
  31. /**
  32. * Implements hook_uninstall().
  33. *
  34. * It's good to clean up after ourselves
  35. *
  36. * @ingroup tablesort_example
  37. */
  38. function tablesort_example_uninstall() {
  39. db_drop_table('tablesort_example');
  40. }
  41. /**
  42. * Implements hook_schema().
  43. *
  44. * @ingroup tablesort_example
  45. */
  46. function tablesort_example_schema() {
  47. $schema['tablesort_example'] = array(
  48. 'description' => 'Stores some values for sorting fun.',
  49. 'fields' => array(
  50. 'numbers' => array(
  51. 'description' => 'This column simply holds numbers values',
  52. 'type' => 'varchar',
  53. 'length' => 2,
  54. 'not null' => TRUE,
  55. ),
  56. 'alpha' => array(
  57. 'description' => 'This column simply holds alpha values',
  58. 'type' => 'varchar',
  59. 'length' => 2,
  60. 'not null' => TRUE,
  61. ),
  62. 'random' => array(
  63. 'description' => 'This column simply holds random values',
  64. 'type' => 'varchar',
  65. 'length' => 12,
  66. 'not null' => TRUE,
  67. ),
  68. ),
  69. 'primary key' => array('numbers'),
  70. );
  71. return $schema;
  72. }