code: private function hierarchyToFlatArray($items) {
          $flatArray = [];
          foreach($items as $item) {
              $flatArray[] = $item->getId();
              // TODO generalize
              if($items->getChildren()->count() > 0) {
                  $flatArray = array_merge($flatArray, $this->hierarchyToFlatArray($items->getChildren()));
              }
          }
          return $flatArray;
      }
docs: Transform hierarchical list to flat array for easing comparison
  @param $items
  @return array