You are here

function _drupalgap_resource_content_types_list in DrupalGap 6

Same name and namespace in other branches
  1. 7.2 drupalgap.resource.inc \_drupalgap_resource_content_types_list()
  2. 7 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_resource_content_types_user_permissions in ./drupalgap.resource.inc
Returns a collection of permissions from content types for the current user.
_drupalgap_resource_system_connect in ./drupalgap.resource.inc
Performs service calls to various resources and bundles them all up so the mobile device gets results, settings and permissions in one request.
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 37
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 ";
  $result = db_query($sql);
  if ($result) {
    $content_types = array();
    while ($data = db_fetch_object($result)) {
      $content_types[] = $data;
    }
    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} ";
      $sql .= " WHERE name IN (" . db_placeholders($names, 'text') . ")";

      // Retrieve the comment settings variables.
      $variable_results = db_query($sql, $names);
      if ($variable_results) {

        // Extract comment settings variables and attach to content type result.
        while ($variable = db_fetch_object($variable_results)) {

          // Strip the '_type' from the end.
          $end = drupal_strlen($variable->name);
          $end -= 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;
  }
}