You are here

public function PartyController::getDataSetController in Party 7

Get the data set controller for a given entity and data set.

Parameters

Party $party: The party to get the data set for.

$data_set_name: The name of a data set.

Return value

The controller class, without attached entities loaded yet.

File

includes/party.entity.inc, line 226
Contains the controller classes for Party entities.

Class

PartyController
The API controller class for the Party entity.

Code

public function getDataSetController($entity, $data_set_name) {

  // If we don't already have our data set, load it.
  if (!isset($entity->data_set_controllers[$data_set_name])) {
    $sets = party_get_data_set_info();
    if (empty($sets[$data_set_name])) {
      throw new Exception(t("Party data set '@data_set_name' does not exist.", array(
        '@data_set_name' => $data_set_name,
      )));
    }
    else {
      if (!($class = $sets[$data_set_name]['class']) || !class_exists($class)) {
        throw new Exception(t("Party data controller '@class' for data set '@data_set_name' does not exist.", array(
          '@class' => $class,
          '@data_set_name' => $data_set_name,
        )));
      }
    }
    $entity->data_set_controllers[$data_set_name] = new $class($data_set_name, $entity);
  }
  return $entity->data_set_controllers[$data_set_name];
}