Projet

Général

Profil

Révision 7e72b748

Ajouté par Assos Assos il y a plus de 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ctools/includes/export.inc
4 4
 * @file
5 5
 * Contains code to make it easier to have exportable objects.
6 6
 *
7
 * Documentation for exportable objects is contained in help/export.html
7
 * Documentation for exportable objects is contained in help/export.html.
8 8
 */
9 9

  
10 10
/**
......
126 126
 *   If TRUE, the static cache of all objects will be flushed prior to
127 127
 *   loading all. This can be important on listing pages where items
128 128
 *   might have changed on the page load.
129
 *
129 130
 * @return
130 131
 *   An array of all loaded objects, keyed by the unique IDs of the export key.
131 132
 */
......
328 329

  
329 330
}
330 331

  
331

  
332 332
/**
333 333
 * Enable a certain object.
334 334
 *
......
426 426
    }
427 427
  }
428 428

  
429
  // Build the query
429
  // Build the query.
430 430
  $query = db_select($table, 't__0')->fields('t__0');
431 431
  $alias_count = 1;
432 432
  if (!empty($schema['join'])) {
......
451 451
  if ($type == 'names') {
452 452
    $query->condition($export['key'], $args, 'IN');
453 453
  }
454
  else if ($type == 'conditions') {
454
  elseif ($type == 'conditions') {
455 455
    foreach ($args as $key => $value) {
456 456
      if (isset($schema['fields'][$key])) {
457 457
        $query->condition($key, $value);
......
499 499
  if ($defaults) {
500 500
    foreach ($defaults as $object) {
501 501
      if ($type == 'conditions') {
502
        // if this does not match all of our conditions, skip it.
502
        // If this does not match all of our conditions, skip it.
503 503
        foreach ($args as $key => $value) {
504 504
          if (!isset($object->$key)) {
505 505
            continue 2;
......
509 509
              continue 2;
510 510
            }
511 511
          }
512
          else if ($object->$key != $value) {
512
          elseif ($object->$key != $value) {
513 513
            continue 2;
514 514
          }
515 515
        }
516 516
      }
517
      else if ($type == 'names') {
517
      elseif ($type == 'names') {
518 518
        if (!in_array($object->{$export['key']}, $args)) {
519 519
          continue;
520 520
        }
......
561 561
    }
562 562
  }
563 563

  
564
  // For conditions,
565 564
  return $return;
566 565
}
567 566

  
......
807 806
function _ctools_export_unpack_object($schema, $data, $object = 'stdClass') {
808 807
  if (is_string($object)) {
809 808
    if (class_exists($object)) {
810
      $object = new $object;
809
      $object = new $object();
811 810
    }
812 811
    else {
813
      $object = new stdClass;
812
      $object = new stdClass();
814 813
    }
815 814
  }
816 815

  
......
873 872
      $output .= $prefix . ')';
874 873
    }
875 874
  }
876
  else if (is_object($var) && get_class($var) === 'stdClass') {
875
  elseif (is_object($var) && get_class($var) === 'stdClass') {
877 876
    // var_export() will export stdClass objects using an undefined
878 877
    // magic method __set_state() leaving the export broken. This
879 878
    // workaround avoids this by casting the object as an array for
880 879
    // export and casting it back to an object when evaluated.
881 880
    $output = '(object) ' . ctools_var_export((array) $var, $prefix);
882 881
  }
883
  else if (is_bool($var)) {
882
  elseif (is_bool($var)) {
884 883
    $output = $var ? 'TRUE' : 'FALSE';
885 884
  }
886 885
  else {
......
959 958
    }
960 959
  }
961 960

  
962
  // And bottom additions here
961
  // And bottom additions here.
963 962
  foreach ($additions2 as $field => $value) {
964 963
    $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . ctools_var_export($value, $indent) . ";\n";
965 964
  }
......
987 986
    // simply hasn't been cached. If we've been asked, let's force the
988 987
    // issue.
989 988
    if (!$schema || empty($schema['export'])) {
990
      // force a schema reset:
989
      // Force a schema reset:
991 990
      $schema = drupal_get_schema($table, TRUE);
992 991
    }
993 992

  
......
999 998
      return array();
1000 999
    }
1001 1000

  
1002
    // Add some defaults
1001
    // Add some defaults.
1003 1002
    $schema['export'] += array(
1004 1003
      'key' => 'name',
1005 1004
      'key name' => 'Name',
......
1107 1106
  $export = $schema['export'];
1108 1107
  $status = variable_get($export['status'], array());
1109 1108

  
1110
  // Compare
1109
  // Compare.
1111 1110
  if (!$new_status && $object->export_type & EXPORT_IN_DATABASE) {
1112 1111
    unset($status[$object->{$export['key']}]);
1113 1112
  }
......
1150 1149
  $schema = ctools_export_get_schema($table);
1151 1150
  $export = $schema['export'];
1152 1151

  
1153
  $object = new $export['object'];
1152
  $object = new $export['object']();
1154 1153
  foreach ($schema['fields'] as $field => $info) {
1155 1154
    if (isset($info['object default'])) {
1156 1155
      $object->$field = $info['object default'];
1157 1156
    }
1158
    else if (isset($info['default'])) {
1157
    elseif (isset($info['default'])) {
1159 1158
      $object->$field = $info['default'];
1160 1159
    }
1161 1160
    else {
......
1180 1179
function ctools_export_to_hook_code(&$code, $table, $names = array(), $name = 'foo') {
1181 1180
  $schema = ctools_export_get_schema($table);
1182 1181
  $export = $schema['export'];
1183
  // Use the schema-specified function for generating hook code, if one exists
1182
  // Use the schema-specified function for generating hook code, if one exists.
1184 1183
  if (function_exists($export['to hook code callback'])) {
1185 1184
    $output = $export['to hook code callback']($names, $name);
1186 1185
  }
1187
  // Otherwise, the following code generates basic hook code
1186
  // Otherwise, the following code generates basic hook code.
1188 1187
  else {
1189 1188
    $output = ctools_export_default_to_hook_code($schema, $table, $names, $name);
1190 1189
  }
......
1236 1235

  
1237 1236
  return $output;
1238 1237
}
1238

  
1239 1239
/**
1240 1240
 * Default function for listing bulk exportable objects.
1241 1241
 */

Formats disponibles : Unified diff