Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250706) (a6b17d8f6bd)
core\output\stored_progress_bar Class Reference
Inheritance diagram for core\output\stored_progress_bar:
core\output\progress_bar core\output\renderable core\output\templatable

Public Member Functions

 __construct (string $idnumber, int $width=0, bool $autostart=true)
 This overwrites the progress_bar::__construct method.
 
 auto_update (bool $value)
 Set whether or not to auto render updates to the screen.
 
 create ()
 Just set the timestart, do not render the bar immediately.
 
 error (string $errormsg)
 Set that the process running has errored and store that against the bar.
 
 export_for_template (renderer_base $output)
 Export for template.
 
 export_for_template (\renderer_base $output)
 Export for template.
 
 get_content ()
 Get the content to display the progress bar and start polling via AJAX.
 
 get_estimate_message (float $percent)
 This gets the estimate message to be displayed with the progress bar.
 
 get_haserrored ()
 Check if the process has errored.
 
 get_id ()
 Getter for ID.
 
 get_message ()
 Get the progress bar message.
 
 get_percent ()
 Get the percent.
 
 init_js ()
 Initialise Javascript for stored progress bars.
 
 render ()
 Render the progress bar.
 
 restart ()
 Restart the progress bar.
 
 start ()
 Start the recording of the progress and store in the database.
 
 store_pending ()
 Store a progress bar record in a pending state.
 
 update ($cur, $total, $msg)
 Update progress bar according the number of tasks.
 
 update_full ($percent, $msg)
 Update progress bar according percent.
 

Static Public Member Functions

static convert_to_idnumber (string $class, ?int $id=null)
 We need a way to specify a unique idnumber for processes being monitored, so that firstly we don't accidentally overwrite a running process, and secondly so we can automatically load them in some cases, without having to manually code in its name.
 
static get_by_id (int $id)
 Load the stored progress bar from the database, based on it's record ID.
 
static get_by_idnumber (string $idnumber)
 Load the stored progress bar from the database based on its uniqued idnumber.
 
static get_timeout ()
 Get the polling timeout in seconds.
 
static load (\stdClass $record)
 Load the stored progress bar object from its record in the database.
 

Protected Member Functions

 clear_records ()
 End the polling progress and delete the DB record.
 
 estimate ($pt)
 Estimate how much time it is going to take.
 
 render_update ()
 Render an update to the CLI.
 
 set_haserrored (bool $value)
 Set the error flag on the object.
 
 set_last_updated (?int $value=null)
 Set the time we started last updated the progress.
 
 set_message (?string $value=null)
 Set the message.
 
 set_percent ($value=null)
 Set the percent completed.
 
 set_record_id (int $id)
 Set the DB record ID.
 
 set_time_started (?int $value)
 Set the time we started the process.
 
 update_raw ($percent, $msg)
 Update the database record with the percentage and message.
 
 update_record ()
 Update the database record.
 

Protected Attributes

bool $autoupdate = true
 Whether or not to auto render updates to the screen.
 
core clock $clock
 Clock object.
 
bool $haserrored = false
 Whether or not an error has occured.
 
string $idnumber
 unique id
 
int $lastupdate = 0
 time when last printed
 
string null $message = null
 Message to associate with bar.
 
int $percent = 0
 last percentage printed
 
int $recordid
 DB record ID.
 
int $timestart = 0
 when did we start printing this
 
int $width
 total width
 

Static Protected Attributes

static bool $jsloaded = false
 Flag to indicate the Javascript module has been initialised already.
 
static bool $supportsoutputbuffering = true
 Can use output buffering.
 

Constructor & Destructor Documentation

◆ __construct()

core\output\stored_progress_bar::__construct ( string $idnumber,
int $width = 0,
bool $autostart = true )

This overwrites the progress_bar::__construct method.

The stored progress bar does not need to check NO_OUTPUT_BUFFERING since it outputs to the page then polls for updates asynchronously, rather than waiting for synchronous updates in later output.

Parameters
string$idnumber
int$widthThe suggested width.
bool$autostartWhether to start the progress bar right away.

Member Function Documentation

◆ auto_update()

core\output\progress_bar::auto_update ( bool $value)
inherited

Set whether or not to auto render updates to the screen.

Parameters
bool$value
Return values
void

◆ clear_records()

core\output\stored_progress_bar::clear_records ( )
protected

End the polling progress and delete the DB record.

Return values
void

◆ convert_to_idnumber()

static core\output\stored_progress_bar::convert_to_idnumber ( string $class,
?int $id = null )
static

We need a way to specify a unique idnumber for processes being monitored, so that firstly we don't accidentally overwrite a running process, and secondly so we can automatically load them in some cases, without having to manually code in its name.

So this uses the classname of the object being monitored, along with its id.

This method should be used when creating the stored_progress record to set it's idnumber.

Parameters
string$classClass name of the object being monitored, e.g. local_something::task::my_task
int | null$idID of an object from database, e.g. 123
Return values
stringConverted string, e.g. local_something_task_my_task_123

◆ create()

core\output\stored_progress_bar::create ( )

Just set the timestart, do not render the bar immediately.

Return values
void

Reimplemented from core\output\progress_bar.

◆ error()

core\output\stored_progress_bar::error ( string $errormsg)

Set that the process running has errored and store that against the bar.

Parameters
string$errormsg
Return values
void

Reimplemented from core\output\progress_bar.

◆ estimate()

core\output\progress_bar::estimate ( $pt)
protectedinherited

Estimate how much time it is going to take.

Parameters
int$ptFrom 1-100.
Return values
mixedNull (unknown), or int.

◆ export_for_template() [1/2]

core\output\progress_bar::export_for_template ( renderer_base $output)
inherited

Export for template.

Parameters
renderer_base$outputThe renderer.
Return values
array

Implements core\output\templatable.

◆ export_for_template() [2/2]

core\output\stored_progress_bar::export_for_template ( \renderer_base $output)

Export for template.

Parameters
renderer_base$outputThe renderer.
Return values
array

◆ get_by_id()

static core\output\stored_progress_bar::get_by_id ( int $id)
static

Load the stored progress bar from the database, based on it's record ID.

Parameters
int$idDatabase record ID
Return values
stored_progress_bar|null

◆ get_by_idnumber()

static core\output\stored_progress_bar::get_by_idnumber ( string $idnumber)
static

Load the stored progress bar from the database based on its uniqued idnumber.

Parameters
string$idnumberUnique ID of the bar
Return values
stored_progress_bar|null

◆ get_content()

core\output\stored_progress_bar::get_content ( )

Get the content to display the progress bar and start polling via AJAX.

Return values
string

Reimplemented from core\output\progress_bar.

◆ get_estimate_message()

core\output\progress_bar::get_estimate_message ( float $percent)
inherited

This gets the estimate message to be displayed with the progress bar.

Parameters
float$percent
Return values
string

◆ get_haserrored()

core\output\progress_bar::get_haserrored ( )
inherited

Check if the process has errored.

Return values
bool

◆ get_id()

core\output\progress_bar::get_id ( )
inherited

Getter for ID.

Return values
stringid

◆ get_message()

core\output\stored_progress_bar::get_message ( )

Get the progress bar message.

Return values
string|null

◆ get_percent()

core\output\progress_bar::get_percent ( )
inherited

Get the percent.

Return values
float

◆ get_timeout()

static core\output\stored_progress_bar::get_timeout ( )
static

Get the polling timeout in seconds.

Default: 5.

Return values
int

◆ init_js()

core\output\stored_progress_bar::init_js ( )

Initialise Javascript for stored progress bars.

The javascript polls the status of all progress bars on the page, so it only needs to be initialised once.

Return values
void

◆ load()

static core\output\stored_progress_bar::load ( \stdClass $record)
static

Load the stored progress bar object from its record in the database.

Parameters
stdClass$record
Return values
stored_progress_bar

◆ render()

core\output\progress_bar::render ( )
inherited

Render the progress bar.

Return values
void

◆ render_update()

core\output\stored_progress_bar::render_update ( )
protected

Render an update to the CLI.

This will only work in CLI scripts, and not in scheduled/adhoc tasks even though they run via CLI, as they seem to use a different renderer (core_renderer instead of core_renderer_cli).

We also can't check this based on "CLI_SCRIPT" const as that is true for tasks.

So this will just check a flag to see if we want auto rendering of updates.

Return values
void

◆ set_haserrored()

core\output\progress_bar::set_haserrored ( bool $value)
protectedinherited

Set the error flag on the object.

Parameters
bool$value
Return values
void

◆ set_last_updated()

core\output\stored_progress_bar::set_last_updated ( ?int $value = null)
protected

Set the time we started last updated the progress.

Parameters
int | null$value
Return values
void

◆ set_message()

core\output\stored_progress_bar::set_message ( ?string $value = null)
protected

Set the message.

Parameters
string | null$value
Return values
void

◆ set_percent()

core\output\stored_progress_bar::set_percent ( $value = null)
protected

Set the percent completed.

Parameters
float | null$value
Return values
void

◆ set_record_id()

core\output\stored_progress_bar::set_record_id ( int $id)
protected

Set the DB record ID.

Parameters
int$id
Return values
void

◆ set_time_started()

core\output\stored_progress_bar::set_time_started ( ?int $value)
protected

Set the time we started the process.

Parameters
?int$value
Return values
void

◆ start()

core\output\stored_progress_bar::start ( )

Start the recording of the progress and store in the database.

Return values
intID of the DB record

◆ store_pending()

core\output\stored_progress_bar::store_pending ( )

Store a progress bar record in a pending state.

Return values
intID of the DB record

◆ update()

core\output\progress_bar::update ( $cur,
$total,
$msg )
inherited

Update progress bar according the number of tasks.

Parameters
int$curCurrent task number.
int$totalTotal task number.
string$msgThe message needed to be shown.

◆ update_full()

core\output\progress_bar::update_full ( $percent,
$msg )
inherited

Update progress bar according percent.

Parameters
int$percentFrom 1-100.
string$msgThe message needed to be shown.

◆ update_raw()

core\output\stored_progress_bar::update_raw ( $percent,
$msg )
protected

Update the database record with the percentage and message.

Parameters
float$percent
string$msg
Return values
void

Reimplemented from core\output\progress_bar.

◆ update_record()

core\output\stored_progress_bar::update_record ( )
protected

Update the database record.

Exceptions
moodle_exception
Return values
void

The documentation for this class was generated from the following file: