You are here

protected function GroupRoleUIController::roleTable in Group 7

Generate an overview table for group roles matching the given conditions.

Builds a tabledrag without having to write a theme function for it. See http://dropbucket.org/node/204.

Parameters

array $conditions: An array of conditions as needed by entity_load().

Return value

array A renderable array.

1 call to GroupRoleUIController::roleTable()
GroupRoleUIController::overviewForm in classes/group_role.ui_controller.inc
Builds the entity overview form.

File

classes/group_role.ui_controller.inc, line 157
Defines the Entity API UI class for group roles.

Class

GroupRoleUIController
UI class for group roles.

Code

protected function roleTable(array $conditions = array()) {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'group_role');
  $query
    ->propertyOrderBy('weight');

  // Add all conditions to query.
  foreach ($conditions as $key => $value) {
    $query
      ->propertyCondition($key, $value);
  }
  if ($this->overviewPagerLimit) {
    $query
      ->pager($this->overviewPagerLimit);
  }
  $result = $query
    ->execute();
  $rows = $weights = array();
  if (isset($result['group_role'])) {
    $group_roles = group_roles(array_keys($result['group_role']));
    foreach ($group_roles as $name => $group_role) {
      $row = $this
        ->roleTableRow($name, $group_role);
      $rows[$name] = $row;
      if ($this->tabledrag) {
        $weights[$name] = array(
          'weight' => &$rows[$name]['data']['weight']['data'],
        );
      }
    }
  }
  $table = array(
    '#theme' => 'table',
    '#header' => $this
      ->roleTableHeaders(),
    '#rows' => $rows,
    '#empty' => t('There are no group roles available.'),
  );
  if ($this->tabledrag) {
    $table['elements'] = $weights;
    $table['#attributes'] = array(
      'id' => 'group-role-table',
    );
    drupal_add_tabledrag('group-role-table', 'order', 'sibling', 'group-role-weight');
  }
  return $table;
}