Project

General

Profile

« Previous | Next » 

Revision efa372e9

Added by Andreas Kohlbecker almost 6 years ago

fix #4497 simple exclusion of all areas with absent status from taxon search

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.module
1419 1419
 *   The UUID of the CDM Term Vocabulary
1420 1420
 * @param $term_label_callback
1421 1421
 *   An optional call back function which can be used to modify the term label
1422
 * @param $default_option
1422
 * @param bool $default_option
1423 1423
 *   An additional element do be placed at the beginning og the list. This element will be the default option.
1424 1424
 *   In order to put an empty element the begining of the options pass an " " as argument.
1425
 * @param $order_by
1425
 * @param array $include_filter
1426
 *   An associative array consisting of a field name an regular expression. All term matching
1427
 *   these filter are included. The value of the field is converted to a String by var_export()
1428
 *   so a boolean 'true' can be matched by '/true/'
1429
 * @param string $order_by
1426 1430
 *   One of the order by constants defined in this file
1431
 * @return mixed
1427 1432
 */
1428
function cdm_vocabulary_as_option($vocabulary_uuid, $term_label_callback = NULL, $default_option = FALSE, $order_by = CDM_ORDER_BY_ORDER_INDEX_ASC) {
1433
function cdm_vocabulary_as_option($vocabulary_uuid, $term_label_callback = NULL, $default_option = FALSE,
1434
                                  array $include_filter = null, $order_by = CDM_ORDER_BY_ORDER_INDEX_ASC) {
1435

  
1429 1436
  static $vocabularyOptions = array();
1430 1437

  
1431 1438
  if (!isset($vocabularyOptions[$vocabulary_uuid])) {
......
1434 1441
        'orderBy' => $order_by
1435 1442
      )
1436 1443
    );
1444

  
1445
    // apply the include filter
1446
    if($include_filter != null){
1447
      $included_terms = array();
1448

  
1449
      foreach ($terms as $term){
1450
        $include = true;
1451
        foreach ($include_filter as $field=>$regex){
1452
          $include =  preg_match($regex, var_export($term->$field, true)) === 1;
1453
          if(!$include){
1454
            break;
1455
          }
1456
        }
1457
        if($include){
1458
          $included_terms[] = $term;
1459
        }
1460
      }
1461

  
1462
      $terms = $included_terms;
1463
    }
1464

  
1465
    // make options list
1437 1466
    $vocabularyOptions[$vocabulary_uuid] = cdm_terms_as_options($terms, $term_label_callback);
1438 1467
  }
1439 1468

  

Also available in: Unified diff