You are here

class CaseTrackerProjectController in Case Tracker 7.2

The Controller for CaseTrackerProject entities

Hierarchy

Expanded class hierarchy of CaseTrackerProjectController

1 string reference to 'CaseTrackerProjectController'
casetracker_entity_info in ./casetracker.module

File

includes/controller/CaseTrackerProjectController.inc, line 6

View source
class CaseTrackerProjectController extends EntityAPIController {
  public function __construct() {
    parent::__construct('casetracker_project');
  }

  /**
   *
   * @param $type
   *   The machine-readable type of the project.
   *
   * @return
   *   A project object with all default fields initialized.
   */
  public function create(array $values = array()) {

    // Add values that are specific to our Project
    $values += array(
      'pid' => '',
      'is_new' => TRUE,
      'title' => '',
      'language' => '',
      'uid' => '',
      'created' => '',
      'changed' => '',
    );
    $project = parent::create($values);
    return $project;
  }

  /**
   *
   * Implements EntityAPIControllerInterface.
   *
   * Generate an array for rendering the given entities.
   *
   * @param $entities
   *   An array of entities to render.
   * @param $view_mode
   *   View mode, e.g. 'full', 'teaser'...
   * @param $langcode
   *   (optional) A language code to use for rendering. Defaults to the global
   *   content language of the current request.
   * @param $page
   *   (optional) If set will control if the entity is rendered: if TRUE
   *   the entity will be rendered without its title, so that it can be embeded
   *   in another context. If FALSE the entity will be displayed with its title
   *   in a mode suitable for lists.
   *   If unset, the page mode will be enabled if the current path is the URI
   *   of the entity, as returned by entity_uri().
   *   This parameter is only supported for entities which controller is a
   *   EntityAPIControllerInterface.
   * @return
   *   The renderable array, keyed by entity name or numeric id.
   */
  public function view($entities, $view_mode = 'full', $langcode = NULL, $page = NULL) {

    // For Field API and entity_prepare_view, the entities have to be keyed by
    // (numeric) id.
    $entities = entity_key_array_by_property($entities, $this->idKey);
    if (!empty($this->entityInfo['fieldable'])) {
      field_attach_prepare_view($this->entityType, $entities, $view_mode);
    }
    entity_prepare_view($this->entityType, $entities);
    $langcode = isset($langcode) ? $langcode : $GLOBALS['language_content']->language;
    $view = array();
    $CaseTrackerCaseController = new CaseTrackerCaseController();
    foreach ($entities as $CaseTrackerProject) {
      $build = array();
      switch ($view_mode) {
        case 'full':
          $build['view_mode_full'] = array(
            '#theme' => 'casetracker_project_full_view_mode',
            '#CaseTrackerProject' => $CaseTrackerProject,
          );
          break;
        case 'teaser':
          $project = array(
            'id' => $CaseTrackerProject->pid,
            'created' => $CaseTrackerProject->created,
            'author' => theme('username', array(
              'account' => user_load($CaseTrackerProject->uid),
            )),
            'title' => l($CaseTrackerProject->title, 'project/' . $CaseTrackerProject->pid),
            'case_totals' => array(
              'priority' => $CaseTrackerCaseController
                ->getTotalAmountByPriority($CaseTrackerProject->pid),
              'bundle' => $CaseTrackerCaseController
                ->getTotalAmountByBundle($CaseTrackerProject->pid),
            ),
          );
          $build['view_mode_teaser'] = array(
            '#theme' => 'casetracker_project_list_view_mode',
            '#project' => $project,
          );
          break;
      }
      $build[] = entity_build_content($this->entityType, $CaseTrackerProject, $view_mode, $langcode);

      //Allow modules to modify the structured entity.
      drupal_alter(array(
        $this->entityType . '_view',
        'entity_view',
      ), $build, $this->entityType);
      $key = isset($CaseTrackerProject->{$this->idKey}) ? $CaseTrackerProject->{$this->idKey} : NULL;
      $view[$this->entityType][$key] = $build;
    }
    return $view;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CaseTrackerProjectController::create public function Overrides EntityAPIController::create
CaseTrackerProjectController::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIController::view
CaseTrackerProjectController::__construct public function Overridden. Overrides EntityAPIController::__construct
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::attachLoad protected function Attaches data to entities upon loading. 4
DrupalDefaultEntityController::cacheGet protected function Gets entities from the static cache. 1
DrupalDefaultEntityController::cacheSet protected function Stores entities in the static entity cache.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
EntityAPIController::$bundleKey protected property
EntityAPIController::$cacheComplete protected property
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::buildQuery protected function Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController::buildQuery 1
EntityAPIController::delete public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::delete 1
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::export public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::export 1
EntityAPIController::import public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::import
EntityAPIController::invoke public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::invoke 1
EntityAPIController::load public function Overridden. Overrides DrupalDefaultEntityController::load 1
EntityAPIController::query public function Builds and executes the query for loading.
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController::resetCache 1
EntityAPIController::save public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::save 1
EntityAPIController::saveRevision protected function Saves an entity revision.