예제 #1
0
/**
 * Called to update the cached reading data for given reading plan
 *
 * @param integer $post_id
 * @return object Reading Data (@see bfox_plan_reading_data() for description)
 */
function bfox_plan_update_reading_data($post_id = 0, $scheduler = null)
{
    $post = get_post($post_id);
    if (!$scheduler) {
        $scheduler = bfox_plan_scheduler_for_post($post_id);
    }
    $reading_data = new stdClass();
    $reading_data->dates = array();
    $reading_data->latest_reading_id = -1;
    $parser = new BfoxPlanParser();
    $parser->parseContent($post->post_content, "\n");
    $reading_data->refs = $parser->readingRefs;
    $reading_data->leftovers = $parser->readingLeftovers;
    if ($scheduler->startTime()) {
        $scheduler->pushNumDates(count($reading_data->refs));
        $reading_data->dates = $scheduler->dates();
        $reading_data->latest_reading_id = $scheduler->latestDateIndex();
    }
    wp_cache_set($post_id, $reading_data, 'bfox_plan_reading_data');
    return $reading_data;
}
예제 #2
0
require_once 'bfox_plan_scheduler.php';
global $showSuccess;
$showSuccess = true;
function assertArrays($a1, $a2)
{
    if (!assert($a1 == $a2)) {
        print_r($a1);
        print_r($a2);
        exit;
    }
}
/*
Test BfoxPlanParser
*/
$content = "Reading 1: Gen 1-10; Exo 1-2;\nReading 2 - 1 Sam 5 (good); 2 sam 6 (great)\nHello\nReading 3 -\n\n1 sam 7\n\n";
$parser = new BfoxPlanParser();
$parser->parseContent($content, "\n");
assertArrays($parser->readingRefStrings(), array('Genesis 1-10; Exodus 1-2', '1 Samuel 5; 2 Samuel 6', '1 Samuel 7'));
/*
Test BfoxPlanScheduler
*/
date_default_timezone_set('America/New_York');
// Suppress silly php date warnings by setting time zone manually
function outputSchedulerDates($scheduler, $numDates)
{
    print_r($scheduler->dates($numDates));
    echo "Latest Date Index: " . $scheduler->latestDateIndex . "\n";
}
function assertLatest($scheduler, $date, $targetDate, $message)
{
    global $showSuccess;