You are here

public function ContentTypeGroup::__construct in Content type groups 7

Same name and namespace in other branches
  1. 7.2 content_type_groups.class.inc \ContentTypeGroup::__construct()

File

./content_type_groups.module, line 148
Module file for the Content type groups module.

Class

ContentTypeGroup
Utility class to handle content type groups

Code

public function __construct($type = NULL) {
  $this->type = check_plain($type);

  // If a type is passed in, we're assuming that there's a
  // matching content type group, so go find it
  if ($type) {
    $result = db_select(self::$table_groups, 'g')
      ->fields('g', array(
      'name',
    ))
      ->condition('type', $type, '=')
      ->execute()
      ->fetchAssoc();
    if ($result) {
      $this->name = $result['name'];

      // Get the content types in this group
      $result = db_select(self::$table_types, 't')
        ->fields('t', array(
        'content_type',
        'weight',
      ))
        ->condition('group_type', $type, '=')
        ->orderBy('weight', 'ASC')
        ->execute();
      if ($result) {
        $all_node_types = node_type_get_names();
        foreach ($result as $row) {
          $this->content_types[$row->content_type] = array(
            'name' => $all_node_types[$row->content_type],
            'weight' => $row->weight,
          );
        }
      }
    }
  }
}