| Conditions | 7 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public static function saveTreeFromIds($nodeTree) |
||
| 12 | { |
||
| 13 | $nodeModels = self::all(); |
||
| 14 | $nodeArrays = self::flattenTree($nodeTree); |
||
| 15 | |||
| 16 | foreach ($nodeArrays as $nodeArray) { |
||
| 17 | $nodeModel = $nodeModels->where('id', $nodeArray['id'])->first(); |
||
| 18 | |||
| 19 | if ($nodeArray['parent_id'] === null) { |
||
| 20 | if (!$nodeModel->isRoot() || $nodeModel->position !== $nodeArray['position']) { |
||
| 21 | $nodeModel->position = $nodeArray['position']; |
||
| 22 | $nodeModel->saveAsRoot(); |
||
| 23 | } |
||
| 24 | } else { |
||
| 25 | if ($nodeModel->position !== $nodeArray['position'] || $nodeModel->parent_id !== $nodeArray['parent_id']) { |
||
| 26 | $nodeModel->position = $nodeArray['position']; |
||
| 27 | $nodeModel->parent_id = $nodeArray['parent_id']; |
||
| 28 | $nodeModel->save(); |
||
| 29 | } |
||
| 55 |