You are here

function workbench_scheduler_load_type_schedules in Workbench Scheduler 7

Return a list of the schedules for a given content type.

Parameters

mixed $types: A string value of a content type or an array of content types.

Return value

mixed An array of schedule objects or boolean false.

4 calls to workbench_scheduler_load_type_schedules()
workbench_scheduler_admin_edit_revision_schedule in ./workbench_scheduler.admin.inc
Form to edit the schedule for an existing node revision.
workbench_scheduler_form_node_form_alter in ./workbench_scheduler.module
Implements hook_form_FORM_ID_alter().
workbench_scheduler_schedules_action in actions/workbench_scheduler.action.inc
Implements the action that is applied to the revisions.
workbench_scheduler_schedules_action_form in actions/workbench_scheduler.action.inc
Workbench scheduler actions form.
2 string references to 'workbench_scheduler_load_type_schedules'
workbench_scheduler_delete_schedules in ./workbench_scheduler.module
Delete schedule(s) add associated data from the database.
workbench_scheduler_save_schedule in ./workbench_scheduler.module
Inserts/updates a schedule.

File

./workbench_scheduler.module, line 835
Content scheduling for Workbench.

Code

function workbench_scheduler_load_type_schedules($types) {
  $schedules =& drupal_static(__FUNCTION__);

  // Check to see if only retrieving for a single type.
  $get_single = FALSE;
  if ($schedules) {

    // Create an array of the type schedules already retrieved.
    $retrieved_types = array_keys($schedules);
  }

  // Passed a single content type?
  if (!is_array($types)) {

    // Retrieving a single.
    $get_single = $types;

    // Make it an array.
    $types = array(
      $types,
    );
  }

  // Find out which of the types have not already been retrieved.
  if (isset($retrieved_types)) {
    $missing_types = array_diff($types, $retrieved_types);
  }
  else {
    $missing_types = $types;
  }

  // Only need to perform query if no schedules or missing types.
  if (!$schedules || count($schedules) < 1 || count($missing_types) > 0) {

    // Retrieve machine name of schedules for types.
    $schedules_query = db_select('workbench_scheduler_types', 'wst')
      ->fields('wst')
      ->condition('wst.type', $missing_types, 'IN')
      ->execute();

    // Retrieved results?
    if ($schedules_query
      ->rowCount()) {

      // Add the schedules to the array.
      foreach ($schedules_query as $type_schedule) {
        $schedule = workbench_scheduler_load_schedules($type_schedule->name);
        $schedules[$type_schedule->type][$schedule->sid] = $schedule;
      }
    }
  }
  if ($schedules && count($schedules) > 0) {

    // Flip types to make it assoc.
    $types = array_flip($types);

    // Take only a subsection of what was retrieved.
    $return_schedules = array_intersect_key($schedules, $types);

    // Able to get they types?
    if (count($return_schedules) > 0) {

      // Only want a single one?
      if ($get_single) {

        // And that type exists in the array?
        if (isset($return_schedules[$get_single])) {

          // Only return schedules for that type.
          $return_schedules = $return_schedules[$get_single];
        }
      }
      return $return_schedules;
    }
  }
  return FALSE;
}