You are here

drupalgap_flag.module in DrupalGap 7

File

modules/drupalgap_flag/drupalgap_flag.module
View source
<?php

/**
 * Implements hook_services_request_postprocess_alter().
 */
function drupalgap_flag_services_request_postprocess_alter($controller, $args, &$result) {
  if ($controller['callback'] == '_system_resource_connect') {

    // Add flag data to the result.
    $flags = db_select('flag', 'f')
      ->fields('f')
      ->execute()
      ->fetchAll();
    if (isset($flags)) {
      foreach ($flags as $flag) {
        $result->flag[$flag->fid] = $flag;
        $result->flag[$flag->fid]->options = unserialize($flag->options);
        $types = db_select('flag_types', 'ft')
          ->condition('fid', $flag->fid)
          ->fields('ft', array(
          'type',
        ))
          ->execute();
        if (isset($types)) {
          $result->flag[$flag->fid]->types = array();
          foreach ($types as $type) {
            $result->flag[$flag->fid]->types[] = $type->type;
          }
        }
      }
    }
  }
}