Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. /*
  2. *Implements hook_schema().
  3. */
  4. function basketstats_schema() {
  5. $schema = array();
  6. $schema['bs_games'] = array(
  7. 'description' => t('Games'),
  8. 'fields' => array(
  9. 'id' => array(
  10. 'description' => t('Primary key of the Game entity.'),
  11. 'type' => 'serial',
  12. 'not null' => TRUE,
  13. ),
  14. 'season' => array(
  15. 'description' => t('Season year'),
  16. 'type' => 'int',
  17. 'not null' => TRUE,
  18. ),
  19. 'week' => array(
  20. 'description' => t('Week number'),
  21. 'type' => 'int',
  22. 'not null' => TRUE,
  23. ),
  24. //....
  25. //....
  26. //more columns here, irrelevant to the question
  27. //....
  28. //....
  29. ),
  30. 'primary key' => array('id'),
  31. 'unique keys' => array(
  32. 'game' => array('season', 'week', 'host', 'visitor', 'host_score', 'visitor_score', 'day')
  33. ),
  34. 'indexes' => array(
  35. 'host' => array('host'),
  36. 'visitor' => array('visitor'),
  37. ),
  38. );
  39. return $schema;
  40. );
  41.  
  42.  
  43. /*
  44. * Implements hook_entity_info().
  45. */
  46. function basketstats_entity_info() {
  47. $entity_info = array();
  48. $entity_info['game'] = array(
  49. 'label' => t('Game'),
  50. 'plural label' => t('Games'),
  51. 'entity class' => 'BasketStatsGame',
  52. 'controller class' => 'BasketStatsGameController',
  53. 'base table' => 'bs_games',
  54. 'fieldable' => FALSE,
  55. 'entity keys' => array(
  56. 'id' => 'id',
  57. ),
  58. 'module' => 'basketstats',
  59. 'label callback' => 'entity_class_label',
  60. 'uri callback' => 'entity_class_uri',
  61. 'access callback' => 'basketstats_entity_access',
  62. 'view modes' => array(
  63. 'full' => array(
  64. 'label' => t('Full content'),
  65. 'custom settings' => FALSE,
  66. ),
  67. 'teaser' => array(
  68. 'label' => t('Teaser'),
  69. 'custom settings' => TRUE,
  70. ),
  71. ),
  72. 'admin ui' => array(
  73. 'path' => $info['admin ui path'],
  74. 'controller class' => 'BasketStatsEntityUIController',
  75. ),
  76. 'views controller class' => 'GameViewsController',
  77. );
  78. return $entity_info;
  79. }
  80.  
  81. /*
  82. * Implements hook_entity_property_info_alter()
  83. */
  84. function basketstats_entity_property_info_alter(&$info) {
  85. // Game properties
  86. $game_props = &$info['game']['properties'];
  87. // Play Off
  88. $game_props['playoff'] = array(
  89. 'type' => 'boolean',
  90. 'label' => t('Play-Off'),
  91. 'computed' => TRUE,
  92. 'entity views field' => TRUE,
  93. //'queryable' => TRUE,
  94. //'query callback' => 'playoff_property_query',
  95. 'description' => t('Whether the game is for Play Offs'),
  96. 'getter callback' => 'playoff_property_get',
  97. );
  98. }
  99.  
  100.  
  101. function playoff_property_get($data, array $options, $name, $type, $info) {
  102. return $data->playoff;
  103. }
  104.  
  105.  
  106. class BasketStatsGame extends Entity {
  107. public function defaultLabel() {
  108. $teams = array_values(entity_load('team', array($this->host, $this->visitor)));
  109. return $teams[0]->defaultLabel() . t(' vs ') . $teams[1]->defaultLabel();
  110. }
  111.  
  112. protected function defaultUri() {
  113. return array('path' => 'game/' . $this->identifier());
  114. }
  115.  
  116. public $playoff = false;
  117.  
  118. public function __construct(array $values = array(), $entityType = NULL) {
  119. parent::__construct($values, $entityType);
  120. $this->playoff = $this->week < 0;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement