ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBackgroundTaskJson.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
18  public static function getFailedJson($a_message)
19  {
20  global $lng;
21 
22  $json = new stdClass();
23 
24  $json->status = "fail";
25  $json->title = self::jsonSafeString($lng->txt("bgtask_failure"));
26  $json->message = self::jsonSafeString($a_message);
27  $json->button = self::jsonSafeString($lng->txt("ok"));
28 
29  return $json;
30  }
31 
38  public static function getBlockedJson($a_task_id)
39  {
40  global $lng;
41 
42  $json = new stdClass();
43 
44  $json->status = "block";
45  $json->task_id = $a_task_id;
46  $json->title = self::jsonSafeString($lng->txt("bgtask_blocked"));
47  $json->message = self::jsonSafeString($lng->txt("bgtask_blocked_info"));
48  $json->button_old = self::jsonSafeString($lng->txt("bgtask_blocked_cancel_old"));
49  $json->button_new = self::jsonSafeString($lng->txt("bgtask_blocked_cancel_new"));
50 
51  return $json;
52  }
53 
62  public static function getProcessingJson($a_task_id, $a_message, $a_steps)
63  {
64  global $lng;
65 
66  $json = new stdClass();
67 
68  $json->status = "bg";
69  $json->task_id = $a_task_id;
70  $json->title = self::jsonSafeString($lng->txt("bgtask_processing"));
71  $json->message = self::jsonSafeString($a_message);
72  $json->button = self::jsonSafeString($lng->txt("cancel"));
73  $json->steps = (int)$a_steps;
74 
75  return $json;
76  }
77 
86  public static function getProgressJson(ilBackgroundTask $a_task, $a_finished_cmd = null, $a_finished_result = null)
87  {
88  $json = new stdClass();
89 
90  $json->status = $a_task->getStatus();
91  $json->steps = $a_task->getSteps();
92  $json->current = $a_task->getCurrentStep();
93 
94  // if task has been finished, get result action
95  if($a_finished_cmd)
96  {
97  $json->result_cmd = $a_finished_cmd;
98  $json->result = $a_finished_result;
99  }
100 
101  return $json;
102  }
103 
112  public static function getFinishedJson($a_task_id, $a_cmd, $a_result)
113  {
114  $json = new stdClass();
115 
116  $json->status = "finished";
117  $json->task_id = $a_task_id;
118  $json->result_cmd = $a_cmd;
119  $json->result = $a_result;
120 
121  return $json;
122  }
123 
130  protected static function jsonSafeString($a_text)
131  {
132  if(!is_string($a_text))
133  {
134  return $a_text;
135  }
136 
137  $a_text = htmlentities($a_text, ENT_COMPAT | ENT_HTML401, "UTF-8");
138  $a_text = str_replace("'", "&#039;", $a_text);
139 
140  return $a_text;
141  }
142 }
static getFinishedJson($a_task_id, $a_cmd, $a_result)
Get json for finished task.
getSteps()
Gets the steps.
static getProcessingJson($a_task_id, $a_message, $a_steps)
Get json for processing task.
static jsonSafeString($a_text)
Makes the specified string safe for JSON.
static getFailedJson($a_message)
Get json for failed task.
getCurrentStep()
Gets the current step.
Background task JSON helper.
static getProgressJson(ilBackgroundTask $a_task, $a_finished_cmd=null, $a_finished_result=null)
Get json for task progress.
static getBlockedJson($a_task_id)
Get json for blocked task.
global $lng
Definition: privfeed.php:17
getStatus()
Gets the status.