Projet

Général

Profil

Révision 950416da

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

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/rules/modules/data.eval.inc
5 5
 * Contains rules integration for the data module needed during evaluation.
6 6
 *
7 7
 * @addtogroup rules
8
 *
8 9
 * @{
9 10
 */
10 11

  
......
43 44
  if ($wrapper = $element->applyDataSelector($element->settings['data:select'])) {
44 45
    $info = $wrapper->info();
45 46
    $element_info['parameter']['value']['type'] = $wrapper->type();
46
    $element_info['parameter']['value']['options list']  = !empty($info['options list']) ? 'rules_data_selector_options_list' : FALSE;
47
    $element_info['parameter']['value']['options list'] = !empty($info['options list']) ? 'rules_data_selector_options_list' : FALSE;
47 48
  }
48 49
}
49 50

  
......
62 63
    case '+':
63 64
      $result = $input1 + $input2;
64 65
      break;
66

  
65 67
    case '-':
66 68
      $result = $input1 - $input2;
67 69
      break;
70

  
68 71
    case '*':
69 72
      $result = $input1 * $input2;
70 73
      break;
74

  
71 75
    case '/':
72 76
      $result = $input1 / $input2;
73 77
      break;
78

  
74 79
    case 'min':
75 80
      $result = min($input1, $input2);
76 81
      break;
82

  
77 83
    case 'max':
78 84
      $result = max($input1, $input2);
79 85
      break;
......
142 148
    if ($type = entity_property_list_extract_type($wrapper->type())) {
143 149
      $info = $wrapper->info();
144 150
      $element_info['parameter']['item']['type'] = $type;
145
      $element_info['parameter']['item']['options list']  = !empty($info['options list']) ? 'rules_data_selector_options_list' : FALSE;
151
      $element_info['parameter']['item']['options list'] = !empty($info['options list']) ? 'rules_data_selector_options_list' : FALSE;
146 152
    }
147 153
  }
148 154
}
......
197 203
      case 'up':
198 204
        $arguments['value'] = ceil($arguments['value']);
199 205
        break;
206

  
200 207
      case 'down':
201 208
        $arguments['value'] = floor($arguments['value']);
202 209
        break;
210

  
203 211
      default:
204 212
      case 'round':
205 213
        $arguments['value'] = round($arguments['value']);
......
211 219
    case 'decimal':
212 220
      $result = floatval($arguments['value']);
213 221
      break;
222

  
214 223
    case 'integer':
215 224
      $result = intval($arguments['value']);
216 225
      break;
226

  
217 227
    case 'text':
218 228
      $result = strval($arguments['value']);
219 229
      break;
230

  
220 231
    case 'token':
221 232
      $result = strval($arguments['value']);
222 233
      break;
......
233 244
  if (isset($element->settings['type']) && $type = $element->settings['type']) {
234 245
    $element_info['provides']['conversion_result']['type'] = $type;
235 246

  
236
    if ($type != 'integer') {
237
      // Only support the rounding behavior option for integers.
247
    // Only support the rounding behavior option for integers.
248
    if ($type == 'integer') {
249
      $element_info['parameter']['rounding_behavior'] = array(
250
        'type' => 'token',
251
        'label' => t('Rounding behavior'),
252
        'description' => t('The rounding behavior the conversion should use.'),
253
        'options list' => 'rules_action_data_convert_rounding_behavior_options',
254
        'restriction' => 'input',
255
        'default value' => 'round',
256
        'optional' => TRUE,
257
      );
258
    }
259
    else {
238 260
      unset($element_info['parameter']['rounding_behavior']);
239 261
    }
240 262

  
......
243 265
      case 'integer':
244 266
        $sources = array('decimal', 'text', 'token', 'uri', 'date', 'duration', 'boolean');
245 267
        break;
268

  
246 269
      case 'decimal':
247 270
        $sources = array('integer', 'text', 'token', 'uri', 'date', 'duration', 'boolean');
248 271
        break;
272

  
249 273
      case 'text':
250 274
        $sources = array('integer', 'decimal', 'token', 'uri', 'date', 'duration', 'boolean');
251 275
        break;
276

  
252 277
      case 'token':
253 278
        $sources = array('integer', 'decimal', 'text', 'uri', 'date', 'duration', 'boolean');
254 279
        break;
......
296 321
    if (isset($type_info['property info'])) {
297 322
      // Add the data type's properties as parameters.
298 323
      foreach ($type_info['property info'] as $property => $property_info) {
299
        // Prefix parameter names to avoid name clashes with existing parameters.
324
        // Prefix parameter names to avoid name clashes with
325
        // existing parameters.
300 326
        $element_info['parameter']['param_' . $property] = array_intersect_key($property_info, array_flip(array('type', 'label', 'allow null')));
301 327
        if (empty($property_info['required'])) {
302 328
          $element_info['parameter']['param_' . $property]['optional'] = TRUE;
......
329 355
        return (isset($data) && isset($value)) || (!isset($data) && !isset($value));
330 356
      }
331 357
      return $data == $value;
358

  
332 359
    case '<':
333 360
      return $data < $value;
361

  
334 362
    case '>':
335 363
      return $data > $value;
336
      // Note: This is deprecated by the text comparison condition and IN below.
364

  
365
    // Note: This is deprecated by the text comparison condition and IN below.
337 366
    case 'contains':
338 367
      return is_string($data) && strpos($data, $value) !== FALSE || is_array($data) && in_array($value, $data);
368

  
339 369
    case 'IN':
340 370
      return is_array($value) && in_array($data, $value);
341 371
  }
......
352 382
  if ($wrapper = $element->applyDataSelector($element->settings['data:select'])) {
353 383
    $info = $wrapper->info();
354 384
    $element_info['parameter']['value']['type'] = $element->settings['op'] == 'IN' ? 'list<' . $wrapper->type() . '>' : $wrapper->type();
355
    $element_info['parameter']['value']['options list']  = !empty($info['options list']) ? 'rules_data_selector_options_list' : FALSE;
385
    $element_info['parameter']['value']['options list'] = !empty($info['options list']) ? 'rules_data_selector_options_list' : FALSE;
356 386
  }
357 387
}
358 388

  
......
374 404
}
375 405

  
376 406
/**
377
* Condition: List count comparison.
378
*/
407
 * Condition: List count comparison.
408
 */
379 409
function rules_condition_data_list_count_is($list, $op = '==', $value) {
380 410
  switch ($op) {
381 411
    case '==':
382 412
      return count($list) == $value;
383
    case '<';
413

  
414
    case '<':
384 415
      return count($list) < $value;
385
    case '>';
416

  
417
    case '>':
386 418
      return count($list) > $value;
387 419
  }
388 420
}
......
415 447
  switch ($op) {
416 448
    case 'contains':
417 449
      return strpos($text, $text2) !== FALSE;
450

  
418 451
    case 'starts':
419 452
      return strpos($text, $text2) === 0;
453

  
420 454
    case 'ends':
421
     return strrpos($text, $text2) === (strlen($text) - strlen($text2));
455
      return strrpos($text, $text2) === (strlen($text) - strlen($text2));
456

  
422 457
    case 'regex':
423
     return (bool) preg_match('/'. str_replace('/', '\\/', $text2) .'/', $text);
458
      return (bool) preg_match('/' . str_replace('/', '\\/', $text2) . '/', $text);
424 459
  }
425 460
}
461

  
462
/**
463
 * @}
464
 */

Formats disponibles : Unified diff