EGOCMS  18.0
EGOTEC Content-Managament-System
Ego_Progress.php
gehe zur Dokumentation dieser Datei
1 <?php
7 class Ego_Progress {
13  private $log;
14 
20  private $value;
21 
27  private $alreadyExists = false;
28 
36  public function __construct($name, $reset = true, $create = true) {
37  $path = $GLOBALS['egotec_conf']['log_dir'].'/progress/';
38  if (!Ego_System::file_exists($path)) {
39  Ego_System::mkdir($path);
40  }
41  $this->log = $path.md5($name);
42 
43  // Fortschritt zurücksetzen
44  if ($reset) {
45  $this->clear();
46  }
47 
48  // Daten des Fortschritts ermitteln
49  if (!Ego_System::file_exists($this->log)) {
50  if ($create) {
51  // Logdatei anlegen, wenn diese nicht existiert
52  $this->value = array(
53  'name' => $name,
54  'start' => 0,
55  'end' => 0,
56  'limit' => 0,
57  'current' => 0,
58  'message' => '',
59  'data' => array()
60  );
61  $this->update();
62  }
63  } else {
64  $this->alreadyExists = true;
65  $this->value = json_decode(Ego_System::file_get_contents($this->log), true);
66  }
67  }
68 
74  public function hasFinished() {
75  return $this->value['current'] >= $this->value['limit'] && !empty($this->value['end']);
76  }
77 
83  public function getValue() {
84  return $this->value;
85  }
86 
93  public function getValueByKey($key) {
94  return $this->value[$key];
95  }
96 
102  private function update() {
103  Ego_System::file_put_contents($this->log, json_encode($this->value));
104  }
105 
112  public function setLimit($limit) {
113  $this->value['limit'] = $limit;
114  $this->update();
115  }
116 
123  public function setMessage($message = '') {
124  $this->value['message'] = $message;
125  $this->update();
126  }
127 
134  public function setData($data = array()) {
135  $this->value['data'] = $data;
136  $this->update();
137  }
138 
145  public function setContinue($data) {
146  $this->value['continue'] = $data;
147  $this->value['continue']['_ref'] = md5(microtime());
148  $this->update();
149  }
150 
156  public function getContinue() {
157  if (!empty($this->value['continue'])) {
158  $continue = $this->value['continue'];
159  unset($this->value['continue']);
160  $this->update();
161  return $continue;
162  }
163  return null;
164  }
165 
174  public function increase($message = '', $data = array(), $amount = 1) {
175  $this->value['current'] += $amount;
176  if (!empty($message)) {
177  $this->value['message'] = $message;
178  }
179  if (!empty($data)) {
180  $this->value['data'] = $data;
181  }
182  $this->update();
183  }
184 
192  public function start($message = '', $data = array()) {
193  $this->value['start'] = time();
194  if (!empty($message)) {
195  $this->value['message'] = $message;
196  }
197  if (!empty($data)) {
198  $this->value['data'] = $data;
199  }
200  $this->update();
201  }
202 
210  public function end($message = '', $data = array()) {
211  $this->value['end'] = time();
212  $this->value['current'] = $this->value['limit'];
213  if (!empty($message)) {
214  $this->value['message'] = $message;
215  }
216  if (!empty($data)) {
217  $this->value['data'] = $data;
218  }
219  $this->update();
220  }
221 
227  public function clear() {
228  @unlink($this->log);
229  }
230 
236  public function exists() {
237  return $this->alreadyExists;
238  }
239 }
240 ?>
setData($data=array())
static file_put_contents($filename, $data, $flags=0, $context=null)
end($message='', $data=array())
__construct($name, $reset=true, $create=true)
static file_exists($file)
start($message='', $data=array())
increase($message='', $data=array(), $amount=1)
static mkdir($dir, $mode=0755, $recursive=true)
Definition: Ego_System.php:497
setLimit($limit)
getValueByKey($key)
static file_get_contents($filename, $utf8=true, $context=null)
setContinue($data)
setMessage($message='')