src/UI/SettingsForm.php
public static function getDueDate() {
        $retval = new \stdClass();
        $retval->penaltyinfo = false;  // Details about the penalty irrespective of the current date
        $retval->message = false;
        $retval->penalty = 0;
        $retval->dayspastdue = 0;
        $retval->percent = 0;
        $retval->duedate = false;
        $retval->duedatestr = false;

        $duedatestr = Settings::linkGet('due');
        if ( $duedatestr === false ) return $retval;
        $duedate = strtotime($duedatestr);

        $diff = -1;
        $penalty = false;

        date_default_timezone_set('Pacific/Honolulu'); // Lets be generous
        if ( Settings::linkGet('timezone') ) {
            date_default_timezone_set(Settings::linkGet('timezone'));
        }

        if ( $duedate === false ) return $retval;

        $penalty_time = Settings::linkGet('penalty_time') ? Settings::linkGet('penalty_time') + 0 : 24*60*60;
        $penalty_cost = Settings::linkGet('penalty_cost') ? Settings::linkGet('penalty_cost') + 0.0 : 0.2;

        $retval->penaltyinfo = sprintf(_m("Once the due date has passed your 
            score will be reduced by %f percent and each %s after the due date, 
            your score will be further reduced by %s percent."),
                htmlent_utf8($penalty_cost*100), htmlent_utf8(self::getDueDateDelta($penalty_time)),
                htmlent_utf8($penalty_cost*100) );

        //  If it is just a date - add nearly an entire day of time...
        if ( strlen($duedatestr) <= 10 ) $duedate = $duedate + 24*60*60 - 1;
        $diff = time() - $duedate;

        $retval->duedate = $duedate;
        $retval->duedatestr = $duedatestr;
        // Should be a percentage off between 0.0 and 1.0
        if ( $diff > 0 ) {
            $penalty_exact = $diff / $penalty_time;
            $penalties = intval($penalty_exact) + 1;
            $penalty = $penalties * $penalty_cost;
            if ( $penalty < 0 ) $penalty = 0;
            if ( $penalty > 1 ) $penalty = 1;
            $retval->penalty = $penalty;
            $retval->dayspastdue = $diff / (24*60*60);
            $retval->percent = intval($penalty * 100);
            $retval->message = sprintf(
                _m("It is currently %s past the due date (%s) so your late penalty is %f percent."),
                self::getDueDateDelta($diff), htmlentities($duedatestr),$retval->percent);
        }
        return $retval;
    }
public static function getDueDate() {
        $retval = new \stdClass();
        $retval->penaltyinfo = false;  // Details about the penalty irrespective of the current date
        $retval->message = false;
        $retval->penalty = 0;
        $retval->dayspastdue = 0;
        $retval->percent = 0;
        $retval->duedate = false;
        $retval->duedatestr = false;

        $duedatestr = Settings::linkGet('due');
        if ( $duedatestr === false ) return $retval;
        $duedate = strtotime($duedatestr);

        $diff = -1;
        $penalty = false;

        date_default_timezone_set('Pacific/Honolulu'); // Lets be generous
        if ( Settings::linkGet('timezone') ) {
            date_default_timezone_set(Settings::linkGet('timezone'));
        }

        if ( $duedate === false ) return $retval;

        $penalty_time = Settings::linkGet('penalty_time') ? Settings::linkGet('penalty_time') + 0 : 24*60*60;
        $penalty_cost = Settings::linkGet('penalty_cost') ? Settings::linkGet('penalty_cost') + 0.0 : 0.2;

        $retval->penaltyinfo = sprintf(_m("Once the due date has passed your 
            score will be reduced by %f percent and each %s after the due date, 
            your score will be further reduced by %s percent."),
                htmlent_utf8($penalty_cost*100), htmlent_utf8(self::getDueDateDelta($penalty_time)),
                htmlent_utf8($penalty_cost*100) );

        //  If it is just a date - add nearly an entire day of time...
        if ( strlen($duedatestr) <= 10 ) $duedate = $duedate + 24*60*60 - 1;
        $diff = time() - $duedate;

        $retval->duedate = $duedate;
        $retval->duedatestr = $duedatestr;
        // Should be a percentage off between 0.0 and 1.0
        if ( $diff > 0 ) {
            $penalty_exact = $diff / $penalty_time;
            $penalties = intval($penalty_exact) + 1;
            $penalty = $penalties * $penalty_cost;
            if ( $penalty < 0 ) $penalty = 0;
            if ( $penalty > 1 ) $penalty = 1;
            $retval->penalty = $penalty;
            $retval->dayspastdue = $diff / (24*60*60);
            $retval->percent = intval($penalty * 100);
            $retval->message = sprintf(
                _m("It is currently %s past the due date (%s) so your late penalty is %f percent."),
                self::getDueDateDelta($diff), htmlentities($duedatestr),$retval->percent);
        }
        return $retval;
    }
public static function getDueDate ( ) { $ retval = new \ stdClass ( ) ; $ retval -> penaltyinfo = false ; // Details about the penalty irrespective of the current date $ retval -> message = false ; $ retval -> penalty = 0 ; $ retval -> dayspastdue = 0 ; $ retval -> percent = 0 ; $ retval -> duedate = false ; $ retval -> duedatestr = false ; $ duedatestr = Settings :: linkGet ( 'due' ) ; if ( $ duedatestr === false ) return $ retval ; $ duedate = strtotime ( $ duedatestr ) ; $ diff = - 1 ; $ penalty = false ; date_default_timezone_set ( 'Pacific/Honolulu' ) ; // Lets be generous if ( Settings :: linkGet ( 'timezone' ) ) { date_default_timezone_set ( Settings :: linkGet ( 'timezone' ) ) ; } if ( $ duedate === false ) return $ retval ; $ penalty_time = Settings :: linkGet ( 'penalty_time' ) ? Settings :: linkGet ( 'penalty_time' ) + 0 : 24 * 60 * 60 ; $ penalty_cost = Settings :: linkGet ( 'penalty_cost' ) ? Settings :: linkGet ( 'penalty_cost' ) + 0.0 : 0.2 ; $ retval -> penaltyinfo = sprintf ( _m ( "Once the due date has passed your 
            score will be reduced by %f percent and each %s after the due date, 
            your score will be further reduced by %s percent." ) , htmlent_utf8 ( $ penalty_cost * 100 ) , htmlent_utf8 ( self :: getDueDateDelta ( $ penalty_time ) ) , htmlent_utf8 ( $ penalty_cost * 100 ) ) ; //  If it is just a date - add nearly an entire day of time... if ( strlen ( $ duedatestr ) <= 10 ) $ duedate = $ duedate + 24 * 60 * 60 - 1 ; $ diff = time ( ) - $ duedate ; $ retval -> duedate = $ duedate ; $ retval -> duedatestr = $ duedatestr ; // Should be a percentage off between 0.0 and 1.0 if ( $ diff > 0 ) { $ penalty_exact = $ diff / $ penalty_time ; $ penalties = intval ( $ penalty_exact ) + 1 ; $ penalty = $ penalties * $ penalty_cost ; if ( $ penalty < 0 ) $ penalty = 0 ; if ( $ penalty > 1 ) $ penalty = 1 ; $ retval -> penalty = $ penalty ; $ retval -> dayspastdue = $ diff / ( 24 * 60 * 60 ) ; $ retval -> percent = intval ( $ penalty * 100 ) ; $ retval -> message = sprintf ( _m ( "It is currently %s past the due date (%s) so your late penalty is %f percent." ) , self :: getDueDateDelta ( $ diff ) , htmlentities ( $ duedatestr ) , $ retval -> percent ) ; } return $ retval ; }
Get the due data data in an object
Get the due data data in an object