FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Item.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Rsi\Fred\Workflow;
4 
5 class Item extends \Rsi\Thing{
6 
7  protected $_workflow = null;
8  protected $_id = null;
9 
10  protected $_data = null;
11 
12  public function __construct($workflow,$id){
13  $this->_workflow = $workflow;
14  $this->_id = $id;
15  }
16  /**
17  * Execute the action for the current step.
18  * @return bool True when status changed, false when not.
19  */
20  public function execute(){
21  if(method_exists($this,$method = 'action' . lcfirst($this->status))){
22  $result = call_user_func([$this,$method]);
23  foreach($this->statuses as $id => $status) if($status['result'] == $result){
24  $this->status = $id;
25  return $result;
26  }
27  throw new \Exception("No change for result '$result'");
28  }
29  return false;
30  }
31 
32  public function lock(){
33  return $this->_workflow->lockItem($this->_id);
34  }
35 
36  public function unlock(){
37  return $this->_workflow->unlockItem($this->_id);
38  }
39 
40  protected function getData(){
41  if($this->_data === null) $this->_data = $this->_workflow->getItemData($this->_id);
42  return $this->_data;
43  }
44 
45  protected function setData($value){
46  $this->_data = array_merge($this->data,$value);
47  $this->_workflow->setItemData($this->_id,$value);
48  }
49 
50  protected function getStatus(){
51  return $this->_workflow->getItemStatus($this->_id);
52  }
53 
54  protected function setStatus($value){
55  if(!$this->_workflow->setItemStatus($this->_id,$value)) throw new \Exception("Could not change status to '$value'");
56  }
57 
58  protected function getStatuses(){
59  return $this->_workflow->getItemStatuses($this->_id);
60  }
61 
62  protected function _get($key){
63  return $this->data[$key] ?? null;
64  }
65 
66  protected function _set($key,$value){
67  $this->data = [$key => $value];
68  }
69 
70 }
setStatus($value)
Definition: Item.php:54
Basic object.
Definition: Thing.php:13
execute()
Execute the action for the current step.
Definition: Item.php:20
__construct($workflow, $id)
Definition: Item.php:12
_set($key, $value)
Definition: Item.php:66