You are here

function finder::choice_repopulate in Finder 7.2

Finder choice repopulate.

Repopulate the finder_choice table for this finder, or a particular element if an element object is passed in.

1 call to finder::choice_repopulate()
finder::save in includes/finder.inc
Finder save.

File

includes/finder.inc, line 642
finder.inc

Class

finder
An object to contain all of the data to generate a finder, plus the member functions to build the finder, and render the output.

Code

function choice_repopulate($element = NULL) {
  if (!empty($element)) {
    $elements = array(
      $element,
    );
  }
  else {
    $elements =& $this->elements;
  }
  foreach ((array) $elements as $finder_element) {
    $this
      ->choice_delete($finder_element);
    $choices_style = $this
      ->esetting($finder_element, 'choices_style');
    $list = array();
    if ($choices_style == 'available_options' || $choices_style == 'available_options_php') {
      if ($choices_style == 'available_options_php') {
        finder_inc('build');
        $available_options = finder_eval($this
          ->esetting($finder_element, 'available_options_php'), array(
          'finder_element' => $finder_element,
        ));
      }
      else {
        $available_options = $this
          ->esetting($finder_element, 'available_options');
      }
      $available_options = explode("\n", $available_options);
      foreach ($available_options as $available_option) {
        if (strpos($available_option, '|') !== FALSE) {
          list($key, $value) = explode('|', $available_option);
          $list[$key] = isset($value) && $value !== '' ? $value : $key;
        }
        else {
          $list[$available_option] = $available_option;
        }
      }
    }
    foreach ($list as $choice_key => $choice_value) {

      // insert list items into table.
      db_insert('finder_choice')
        ->fields(array(
        'finder' => $this->id,
        'element' => $finder_element->id,
        'choice_key' => $choice_key,
        'choice_value' => $choice_value,
      ))
        ->execute();
    }
  }
}