/**
  * @param MediaFolderInterface $folder
  *
  * @return int
  */
 protected function countMediaTree(MediaFolderInterface $folder)
 {
     $count = count($folder->getMedias());
     $subFolders = $folder->getSubFolders();
     foreach ($subFolders as $subFolder) {
         $count += $this->countMediaTree($subFolder, $count);
     }
     return $count;
 }
 /**
  * Vote for $action on $folder not owned by $user
  * A user can act on someone else's folder if he has the matching super role and the folder is in his perimeter
  *
  * @param string               $action
  * @param MediaFolderInterface $folder
  * @param UserInterface        $user
  *
  * @return bool
  */
 protected function voteForSomeoneElseSubject($action, $folder, UserInterface $user)
 {
     $requiredRole = ContributionRoleInterface::MEDIA_FOLDER_CONTRIBUTOR;
     switch ($action) {
         case ContributionActionInterface::EDIT:
             $requiredRole = ContributionRoleInterface::MEDIA_FOLDER_SUPER_EDITOR;
             break;
         case ContributionActionInterface::DELETE:
             $requiredRole = ContributionRoleInterface::MEDIA_FOLDER_SUPER_SUPRESSOR;
             break;
     }
     return $user->hasRole($requiredRole) && $this->isSubjectInPerimeter($folder->getPath(), $user, MediaFolderInterface::ENTITY_TYPE);
 }