Folder.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin McCorkell <robin@mccorkell.me.uk>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCA\Files_Sharing\ShareBackend;
  30. class Folder extends File implements \OCP\Share_Backend_Collection {
  31. public function getChildren($itemSource) {
  32. $children = [];
  33. $parents = [$itemSource];
  34. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  35. $qb->select('id')
  36. ->from('mimetypes')
  37. ->where(
  38. $qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory'))
  39. );
  40. $result = $qb->execute();
  41. $row = $result->fetch();
  42. $result->closeCursor();
  43. if ($row = $result->fetchRow()) {
  44. $mimetype = (int) $row['id'];
  45. } else {
  46. $mimetype = -1;
  47. }
  48. while (!empty($parents)) {
  49. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  50. $parents = array_map(function ($parent) use ($qb) {
  51. return $qb->createNamedParameter($parent);
  52. }, $parents);
  53. $qb->select('`fileid', 'name', '`mimetype')
  54. ->from('filecache')
  55. ->where(
  56. $qb->expr()->in('parent', $parents)
  57. );
  58. $result = $qb->execute();
  59. $parents = [];
  60. while ($file = $result->fetch()) {
  61. $children[] = ['source' => $file['fileid'], 'file_path' => $file['name']];
  62. // If a child folder is found look inside it
  63. if ((int) $file['mimetype'] === $mimetype) {
  64. $parents[] = $file['fileid'];
  65. }
  66. }
  67. $result->closeCursor();
  68. }
  69. return $children;
  70. }
  71. }