You are here

function _drupalgap_resource_content_types_list in DrupalGap 7

Same name and namespace in other branches
  1. 6 drupalgap.resource.inc \_drupalgap_resource_content_types_list()
  2. 7.2 drupalgap.resource.inc \_drupalgap_resource_content_types_list()

Returns a collection of content types from the {node_type} table.

It also bundles other available information about each content type with the return results.

Parameters

array $options: An array of options.

Return value

object MySQL object results from the {node_type} table

2 calls to _drupalgap_resource_content_types_list()
drupalgap_system_connect_extras in ./drupalgap.module
_drupalgap_resource_content_types_user_permissions in ./drupalgap.resource.inc
Returns a collection of permissions from content types for the current user.
1 string reference to '_drupalgap_resource_content_types_list'
drupalgap_services_resources in ./drupalgap.services.inc
Defines function signatures for resources available to services.

File

./drupalgap.resource.inc, line 45
This file implements the DrupalGap service resource call back functions.

Code

function _drupalgap_resource_content_types_list($options = array()) {

  // Grab content types.
  $sql = "SELECT * FROM {node_type} ORDER BY name ASC";
  $content_types_result = db_query($sql);
  if ($content_types_result) {
    $content_types = $content_types_result
      ->fetchAll();
    foreach ($content_types as $i => $content_type) {

      // Grab comment settings for content type.
      $names = array(
        'comment_anonymous_' . $content_type->type,
        'comment_' . $content_type->type,
        'comment_default_mode_' . $content_type->type,
        'comment_default_per_page_' . $content_type->type,
        'comment_form_location_' . $content_type->type,
        'comment_preview_' . $content_type->type,
        'comment_subject_field_' . $content_type->type,
      );
      $sql = "SELECT * FROM {variable} WHERE name IN (:names)";
      $variable_results = db_query($sql, array(
        ':names' => $names,
      ));
      if ($variable_results) {

        // Extract comment settings variables and attach to content type result.
        $variables = $variable_results
          ->fetchAll();
        foreach ($variables as $variable) {

          // Strip the '_type' from the end.
          $end = drupal_strlen($variable->name) - (drupal_strlen($content_type->type) + 1);
          $variable_name = drupal_substr($variable->name, 0, $end);
          $content_types[$i]->{$variable_name} = unserialize($variable->value);
        }
      }
    }
    return $content_types;
  }
}