Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *Implements hook_schema().
- */
- function basketstats_schema() {
- $schema = array();
- $schema['bs_games'] = array(
- 'description' => t('Games'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('Primary key of the Game entity.'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'season' => array(
- 'description' => t('Season year'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'week' => array(
- 'description' => t('Week number'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- //....
- //....
- //more columns here, irrelevant to the question
- //....
- //....
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'game' => array('season', 'week', 'host', 'visitor', 'host_score', 'visitor_score', 'day')
- ),
- 'indexes' => array(
- 'host' => array('host'),
- 'visitor' => array('visitor'),
- ),
- );
- return $schema;
- );
- /*
- * Implements hook_entity_info().
- */
- function basketstats_entity_info() {
- $entity_info = array();
- $entity_info['game'] = array(
- 'label' => t('Game'),
- 'plural label' => t('Games'),
- 'entity class' => 'BasketStatsGame',
- 'controller class' => 'BasketStatsGameController',
- 'base table' => 'bs_games',
- 'fieldable' => FALSE,
- 'entity keys' => array(
- 'id' => 'id',
- ),
- 'module' => 'basketstats',
- 'label callback' => 'entity_class_label',
- 'uri callback' => 'entity_class_uri',
- 'access callback' => 'basketstats_entity_access',
- 'view modes' => array(
- 'full' => array(
- 'label' => t('Full content'),
- 'custom settings' => FALSE,
- ),
- 'teaser' => array(
- 'label' => t('Teaser'),
- 'custom settings' => TRUE,
- ),
- ),
- 'admin ui' => array(
- 'path' => $info['admin ui path'],
- 'controller class' => 'BasketStatsEntityUIController',
- ),
- 'views controller class' => 'GameViewsController',
- );
- return $entity_info;
- }
- /*
- * Implements hook_entity_property_info_alter()
- */
- function basketstats_entity_property_info_alter(&$info) {
- // Game properties
- $game_props = &$info['game']['properties'];
- // Play Off
- $game_props['playoff'] = array(
- 'type' => 'boolean',
- 'label' => t('Play-Off'),
- 'computed' => TRUE,
- 'entity views field' => TRUE,
- //'queryable' => TRUE,
- //'query callback' => 'playoff_property_query',
- 'description' => t('Whether the game is for Play Offs'),
- 'getter callback' => 'playoff_property_get',
- );
- }
- function playoff_property_get($data, array $options, $name, $type, $info) {
- return $data->playoff;
- }
- class BasketStatsGame extends Entity {
- public function defaultLabel() {
- $teams = array_values(entity_load('team', array($this->host, $this->visitor)));
- return $teams[0]->defaultLabel() . t(' vs ') . $teams[1]->defaultLabel();
- }
- protected function defaultUri() {
- return array('path' => 'game/' . $this->identifier());
- }
- public $playoff = false;
- public function __construct(array $values = array(), $entityType = NULL) {
- parent::__construct($values, $entityType);
- $this->playoff = $this->week < 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement