| 1 |
<?php
|
| 2 |
// $Id: views_scheduler_process.inc,v 1.9 2006/09/21 17:33:07 flk Exp $
|
| 3 |
|
| 4 |
function views_scheduler_process_schedule($type){
|
| 5 |
//retrieve any scheduled views
|
| 6 |
$scheduled_views = views_scheduler_select_views();
|
| 7 |
|
| 8 |
//if there are no scheduled views
|
| 9 |
if (!$scheduled_views) return ;
|
| 10 |
|
| 11 |
// If there are scheduled views, iterate through it.
|
| 12 |
foreach ($scheduled_views as $views) {
|
| 13 |
|
| 14 |
$schedules = views_scheduler_select_schedules($type, $views['vschedule_id']);
|
| 15 |
|
| 16 |
//Is the scheduled-time <=time(), if so retreive view an carry out actions
|
| 17 |
if ( views_scheduler_activate($schedules['next']) ) {
|
| 18 |
|
| 19 |
$nodes = $views['node'];
|
| 20 |
$name = views_get_view($views ['view']);
|
| 21 |
$viewresult = views_build_view('items', $name, NULL, 0, $nodes, 0 );
|
| 22 |
|
| 23 |
//retrieve each node one at a time.
|
| 24 |
foreach( $viewresult['items'] as $key => $value ){
|
| 25 |
$nid=$viewresult['items'][$key]->nid;
|
| 26 |
//carry out the actions
|
| 27 |
views_scheduler_carry_out_actions($views[vschedule_id],$nid);
|
| 28 |
}
|
| 29 |
//turn the array into object since some versions of
|
| 30 |
//schedule do not accept arrays
|
| 31 |
//$schedules = objectify_an_array($schedules);
|
| 32 |
|
| 33 |
//set new schedule time
|
| 34 |
schedule_set_next_publication_time($schedules);
|
| 35 |
|
| 36 |
}
|
| 37 |
}
|
| 38 |
}
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
function objectify_an_array($arg_array) {
|
| 43 |
$tmp = new stdClass; // start off a new (empty) object
|
| 44 |
foreach ($arg_array as $key => $value) {
|
| 45 |
if (is_array($value)) { // if its multi-dimentional, keep going :)
|
| 46 |
$tmp->$key = arr2obj($value);
|
| 47 |
} else {
|
| 48 |
if (is_numeric($key)) { // can't do it with numbers :(
|
| 49 |
die("Cannot turn numeric arrays into objects!");
|
| 50 |
}
|
| 51 |
$tmp->$key = $value;
|
| 52 |
}
|
| 53 |
}
|
| 54 |
return $tmp; // return the object!
|
| 55 |
}
|
| 56 |
//to be worked on more later
|
| 57 |
//this is to allow for people who want more control to be able
|
| 58 |
//to run scheduled views using actions.
|
| 59 |
/*
|
| 60 |
function action_views_scheduler_run($op, $edit = array(), &$node) {
|
| 61 |
switch($op) {
|
| 62 |
case 'do':
|
| 63 |
views_scheduler_cron();
|
| 64 |
break;
|
| 65 |
|
| 66 |
case 'metadata':
|
| 67 |
return array(
|
| 68 |
'description' => t('Run the scheduled view'),
|
| 69 |
'type' => t('View'),
|
| 70 |
'batchable' => false,
|
| 71 |
'configurable' => false,
|
| 72 |
);
|
| 73 |
|
| 74 |
}
|
| 75 |
}
|
| 76 |
*/
|