| Conditions | 6 |
| Paths | 12 |
| Total Lines | 23 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | public function updateListLabels(ArrayCollection $new_labels) |
||
| 26 | { |
||
| 27 | $old_label = new ArrayCollection($this->findAll()); |
||
| 28 | // remove labels |
||
| 29 | foreach ($old_label as $label) { |
||
| 30 | if (!$new_labels->contains($label)) { |
||
| 31 | foreach ($label->getItems() as $item) { |
||
| 32 | /* @var $item ItemEntity */ |
||
| 33 | $item->removeLabel($label); |
||
| 34 | } |
||
| 35 | $this->getEntityManager()->remove($label); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | // add new labals |
||
| 40 | foreach ($new_labels as $label) { |
||
| 41 | if (!$old_label->contains($label)) { |
||
| 42 | $this->getEntityManager()->persist($label); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | $this->getEntityManager()->flush(); |
||
| 47 | } |
||
| 48 | } |
||
| 49 |