class CaseTrackerCaseController in Case Tracker 7.2
The Controller for CaseTrackerCase entities
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
- class \CaseTrackerCaseController
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of CaseTrackerCaseController
1 string reference to 'CaseTrackerCaseController'
File
- includes/
controller/ CaseTrackerCaseController.inc, line 6
View source
class CaseTrackerCaseController extends EntityAPIController {
public function __construct() {
parent::__construct('casetracker_case');
}
/**
*
* @param $type
* The machine-readable type of the case.
*
* @return
* A case object with all default fields initialized.
*/
public function create(array $values = array()) {
// Add values that are specific to our Case
$values += array(
'pid' => '',
'is_new' => TRUE,
'title' => '',
'language' => '',
'uid' => '',
'created' => '',
'changed' => '',
);
$case = parent::create($values);
return $case;
}
/**
*
* 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();
foreach ($entities as $entity) {
$build = $this
->themeEntity($entity);
$build[] = entity_build_content($this->entityType, $entity, $view_mode, $langcode);
//Allow modules to modify the structured entity.
drupal_alter(array(
$this->entityType . '_view',
'entity_view',
), $build, $this->entityType);
$key = isset($entity->{$this->idKey}) ? $entity->{$this->idKey} : NULL;
$view[$this->entityType][$key] = $build;
}
return $view;
}
/**
* Define how an entity will be themed and return the build array with it.
* @param CaseTrackerCase $entity
* @return array
*/
protected function themeEntity($entity) {
$build = array();
$build['view_mode_full'] = array(
'#theme' => 'casetracker_case_full_view_mode',
'#CaseTrackerCase' => $entity,
);
return $build;
}
/**
* Sums the amount of Cases grouped by priority and optionally filter by project.
* @param int $project_id
* @return array of CaseTrackerCase
*/
public function getTotalAmountByPriority($project_id = NULL) {
$query = "SELECT p.field_casetracker_case_priority_value priority, count(c.cid) total\n FROM {casetracker_case} c\n JOIN {field_data_field_casetracker_case_priority} p ON p.entity_type = 'casetracker_case' AND p.entity_id = c.cid\n ";
if ($project_id != NULL) {
$query .= " JOIN {field_data_field_casetracker_project_ref} proj ON proj.entity_type = 'casetracker_case' AND proj.entity_id = c.cid AND proj.field_casetracker_project_ref_target_id = :pid";
}
$query .= " GROUP BY priority";
if ($project_id != NULL) {
$results = db_query($query, array(
':pid' => $project_id,
))
->fetchAll();
}
else {
$results = db_query($query)
->fetchAll();
}
return $results;
}
/**
* Sums the amount of Cases grouped by bundle and optionally filter by project.
* @param int $project_id
* @return array of CaseTrackerCase
*/
public function getTotalAmountByBundle($project_id = NULL) {
$query = "SELECT t.label bundle, count(c.cid) total\n FROM {casetracker_case} c\n INNER JOIN {casetracker_case_type} t ON t.type = c.type";
if ($project_id != NULL) {
$query .= " JOIN {field_data_field_casetracker_project_ref} proj ON proj.entity_type = 'casetracker_case' AND proj.entity_id = c.cid AND proj.field_casetracker_project_ref_target_id = :pid";
}
$query .= " GROUP BY c.type";
if ($project_id != NULL) {
$results = db_query($query, array(
':pid' => $project_id,
))
->fetchAll();
}
else {
$results = db_query($query)
->fetchAll();
}
return $results;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CaseTrackerCaseController:: |
public | function |
Overrides EntityAPIController:: |
|
CaseTrackerCaseController:: |
public | function | Sums the amount of Cases grouped by bundle and optionally filter by project. | |
CaseTrackerCaseController:: |
public | function | Sums the amount of Cases grouped by priority and optionally filter by project. | |
CaseTrackerCaseController:: |
protected | function | Define how an entity will be themed and return the build array with it. | |
CaseTrackerCaseController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIController:: |
|
CaseTrackerCaseController:: |
public | function |
Overridden. Overrides EntityAPIController:: |
|
DrupalDefaultEntityController:: |
protected | property | Whether this entity type should use the static cache. | |
DrupalDefaultEntityController:: |
protected | property | Static cache of entities, keyed by entity ID. | |
DrupalDefaultEntityController:: |
protected | property | Array of information about the entity. | |
DrupalDefaultEntityController:: |
protected | property | Entity type for this controller instance. | |
DrupalDefaultEntityController:: |
protected | property | Additional arguments to pass to hook_TYPE_load(). | |
DrupalDefaultEntityController:: |
protected | property | Name of the entity's ID field in the entity database table. | |
DrupalDefaultEntityController:: |
protected | property | Name of entity's revision database table field, if it supports revisions. | |
DrupalDefaultEntityController:: |
protected | property | The table that stores revisions, if the entity supports revisions. | |
DrupalDefaultEntityController:: |
protected | function | Attaches data to entities upon loading. | 4 |
DrupalDefaultEntityController:: |
protected | function | Gets entities from the static cache. | 1 |
DrupalDefaultEntityController:: |
protected | function | Stores entities in the static entity cache. | |
DrupalDefaultEntityController:: |
protected | function | Ensures integer entity IDs are valid. | |
DrupalDefaultEntityController:: |
protected | function | Callback for array_filter that removes non-integer IDs. | |
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
protected | function |
Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController:: |
1 |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
EntityAPIController:: |
public | function |
Overridden. Overrides DrupalDefaultEntityController:: |
1 |
EntityAPIController:: |
public | function | Builds and executes the query for loading. | |
EntityAPIController:: |
protected | function | Renders a single entity property. | |
EntityAPIController:: |
public | function |
Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController:: |
1 |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
EntityAPIController:: |
protected | function | Saves an entity revision. |