function workbench_scheduler_schedules_load in Workbench Scheduler 7.2
Retrieve an array of schedule data by sid.
Parameters
mixed $sid: Sid of the schedule or an array of sids (optional).
Return value
mixed An array of schedule data or boolean FALSE.
11 calls to workbench_scheduler_schedules_load()
- workbench_scheduler_admin_edit_revision_schedule in ./
workbench_scheduler.admin.inc - Form to edit the schedule for an existing node revision.
- workbench_scheduler_admin_edit_schedule in ./
workbench_scheduler.admin.inc - Display a form for adding/editing a schedule.
- workbench_scheduler_admin_manage_node_schedules in ./
workbench_scheduler.admin.inc - Tableselect form for current schedules applied to a node.
- workbench_scheduler_admin_page in ./
workbench_scheduler.admin.inc - Display a table of workbench schedule for administration.
- workbench_scheduler_form_node_form_alter in ./
workbench_scheduler.module - Implements hook_form_FORM_ID_alter().
3 string references to 'workbench_scheduler_schedules_load'
- workbench_scheduler_delete_schedules in ./
workbench_scheduler.module - Delete schedule(s) add associated data from the database.
- workbench_scheduler_features_rebuild in ./
workbench_scheduler.features.inc - Implements COMPONENT_features_rebuild().
- workbench_scheduler_save_schedule in ./
workbench_scheduler.module - Inserts/updates a schedule.
File
- ./
workbench_scheduler.module, line 1127 - Content scheduling for Workbench.
Code
function workbench_scheduler_schedules_load($sids = FALSE) {
$schedules =& drupal_static(__FUNCTION__);
// Boolean to check if only retrieving a single schedule.
$get_single = FALSE;
// make sure we only use $schedules with an "transition" attribute
if ($schedules) {
$schedules = array_filter($schedules, function ($schedule) {
return property_exists($schedule, 'transition');
});
}
if ($schedules) {
// Create an array of the schedules names already retrieved.
$retrieved_sids = array_keys($schedules);
}
// Passed sids of schedules to retrieve?
if ($sids) {
// Passed a single schedule name?
if (!is_array($sids)) {
// Retrieving a single.
$get_single = $sids;
// Make it an array.
$sids = array(
$sids,
);
}
// Find out which of the schedules have not already been retrieved.
if (isset($retrieved_sids)) {
$missing_sids = array_diff($sids, $retrieved_sids);
}
else {
$missing_sids = $sids;
}
}
// Only need to query the DB if noe schedules, no names or missing names.
if (!$schedules || count($schedules) < 1 || !isset($missing_sids) || count($missing_sids) > 0) {
// Build query to retrieve schedules.
$schedules_query = db_select('workbench_scheduler_schedules', 'wss');
// Left join the types table to get related content types based on.
// Schedule machine names.
$schedules_query
->leftjoin('workbench_scheduler_types', 'wst', 'wss.name = wst.name');
// Retrieve all the fields for a schedule.
$schedules_query
->fields('wss')
->fields('wst', array(
'type',
));
// Have missing names we want to only retrieve?
if (isset($missing_sids)) {
// Add condition to only retrieve these schedules.
$schedules_query
->condition('wss.sid', $missing_sids, 'IN');
}
// Have previously retrieved schedules?
if (isset($retrieved_sids)) {
// Add condition not to retrieve these.
$schedules_query
->condition('wss.name', $retrieved_sids, 'NOT IN');
}
// Perform the query.
$retrieved_schedules = $schedules_query
->execute();
// Were results returned?
if ($retrieved_schedules
->rowCount()) {
// Loop through the results.
foreach ($retrieved_schedules as $schedule) {
// Already retrieved the schedule?
if (isset($schedules[$schedule->sid]) && !in_array($schedule->type, $schedules[$schedule->sid]->types)) {
// Yes, then just add this content type to it.
$schedules[$schedule->sid]->types[] = $schedule->type;
}
else {
// No, add to schedules array.
$schedules[$schedule->sid] = $schedule;
// Add an array for the content types.
$schedules[$schedule->sid]->types = array(
$schedule->type,
);
// Do not need the type attribute.
unset($schedules[$schedule->sid]->type);
}
}
}
}
// Have schedules to return?
if ($schedules && count($schedules) > 0) {
// Have a specific sub set of schedules ?
if ($sids) {
// Flip names to make it assoc.
$sids = array_flip($sids);
// Take only a sub section of the returned schedules.
$return_schedules = array_intersect_key($schedules, $sids);
// Only want a single schedule?
if ($get_single) {
// Is it present in the array?
if (isset($return_schedules[$get_single])) {
// Return just that schedule.
return $return_schedules[$get_single];
}
}
elseif (count($return_schedules) > 0) {
return $return_schedules;
}
}
else {
// Return all of the retrieved schedules.
return $schedules;
}
}
// No schedules fetched, return boolean FALSE.
return FALSE;
}