forked from thelia/thelia
/
FolderQuery.php
67 lines (58 loc) · 1.88 KB
/
FolderQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Thelia\Model;
use Thelia\Model\Base\FolderQuery as BaseFolderQuery;
/**
* Skeleton subclass for performing query and update operations on the 'folder' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class FolderQuery extends BaseFolderQuery
{
/**
*
* count how many direct contents a folder has
*
* @param int $parent folder id
* @return int
*/
public static function countChild($parent)
{
return self::create()->filterByParent($parent)->count();
}
/**
* find all contents for a given folder.
*
* @param $folderId the folder id or an array of id
* @param int $depth max depth you want to search
* @param int $currentPosition don't change this param, it is used for recursion
* @return \Thelia\Model\Folder[]
*/
public static function findAllChild($folderId, $depth = 0, $currentPosition = 0)
{
$result = array();
if (is_array($folderId)) {
foreach ($folderId as $folderSingleId) {
$result = array_merge($result, (array) self::findAllChild($folderSingleId, $depth, $currentPosition));
}
} else {
$currentPosition++;
if ($depth == $currentPosition && $depth != 0) {
return;
}
$categories = self::create()
->filterByParent($folderId)
->find();
foreach ($categories as $folder) {
array_push($result, $folder);
$result = array_merge($result, (array) self::findAllChild($folder->getId(), $depth, $currentPosition));
}
}
return $result;
}
}
// FolderQuery