1: <?php
2:
3: namespace PHPixie\ORM\Steps\Step\Update;
4:
5: class Map extends \PHPixie\ORM\Steps\Step\Update
6: {
7: protected $map;
8: protected $resultStep;
9:
10: public function __construct($updateQuery, $map, $resultStep)
11: {
12: parent::__construct($updateQuery);
13: $this->map = $map;
14: $this->resultStep = $resultStep;
15: }
16:
17: public function execute()
18: {
19: $fieldRows = $this->resultStep->getFields(array_values($this->map));
20: if(count($fieldRows) !== 1)
21: throw new \PHPixie\ORM\Exception\Plan("Result used as update source must contain a single item.");
22: $fields = current($fieldRows);
23: $set = array();
24: foreach($this->map as $target => $source) {
25: $set[$target] = $fields[$source];
26: }
27: $this->updateQuery->set($set);
28: }
29:
30: }
31: