You are here

function workbench_email_get_workbench_access_sections in Workbench Email 7.3

Returns the section selected by the user.

Parameters

string $op: The operation being performed.

array $data: The data in which to retrieve information from.

Return value

array The sections selected by the user.

2 calls to workbench_email_get_workbench_access_sections()
workbench_email_get_all_transition_users in ./workbench_email.module
Returns all available users for an email transition.
workbench_email_notification_validate in ./workbench_email.form.inc
Validates the options chosen.

File

./workbench_email.module, line 1039
Code for the Workbench Email Module.

Code

function workbench_email_get_workbench_access_sections($op = 'node', $data = array()) {
  $sections = array();
  if ($op == 'form') {

    // Can be either menu or taxonomy.
    $workbench_access = variable_get('workbench_access');
    if ($workbench_access == 'menu') {

      // Type is a boolean to determine if the user has chosen a
      // "Require a Workbench Access form element" which means,
      // a custom way of displaying the WA form or using the standard
      // node form.
      $type = variable_get('workbench_access_custom_form');
      if ($type) {
        if (isset($data['data']['form_state']['values']['workbench_access']) && $data['data']['form_state']['values']['workbench_access']) {
          $sections = $data['data']['form_state']['values']['workbench_access'];
        }
      }
      else {
        if (isset($data['data']['form_state']['values']['menu']['parent'])) {
          $sections_menu = $data['data']['form_state']['values']['menu']['parent'];
          $sections_list = explode(":", $sections_menu);
          $sections[$sections_list[1]] = $sections_list[1];
        }
      }
    }
    else {
      if ($workbench_access == 'taxonomy') {
        $type = variable_get('workbench_access_custom_form');
        if ($type) {
          if (isset($data['data']['form_state']['values']['workbench_access']) && $data['data']['form_state']['values']['workbench_access']) {
            $sections = $data['data']['form_state']['values']['workbench_access'];
          }
        }
        else {

          // In this case, a custom field was provided, so loop around the fields
          // and store the tids this user has chosen.
          if (!empty($data['data']['form_state']['values']['workbench_access_fields'])) {
            $values = $data['data']['form_state']['values'];
            $sections = array();
            $lang = $values['language'];
            foreach ($values['workbench_access_fields'] as $field) {
              if (!empty($values[$field][$lang])) {
                foreach ($values[$field][$lang] as $term) {
                  if (!empty($term['tid'])) {
                    $sections[$term['tid']] = $term['tid'];
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  else {
    if (isset($data['data']->workbench_access) && $data['data']->workbench_access) {
      $sections = $data['data']->workbench_access;
    }
  }
  return $sections;
}