Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
3e44eaaf
Unverified
Commit
3e44eaaf
authored
Oct 08, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding method to get all folders under nested collection
parent
c9a8a838
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
0 deletions
+23
-0
EloquentFolderRepository.php
.../Media/Repositories/Eloquent/EloquentFolderRepository.php
+6
-0
FolderRepository.php
Modules/Media/Repositories/FolderRepository.php
+3
-0
EloquentFolderRepositoryTest.php
Modules/Media/Tests/EloquentFolderRepositoryTest.php
+14
-0
No files found.
Modules/Media/Repositories/Eloquent/EloquentFolderRepository.php
View file @
3e44eaaf
...
...
@@ -11,6 +11,7 @@ use Modules\Media\Events\FolderIsUpdating;
use
Modules\Media\Events\FolderWasCreated
;
use
Modules\Media\Events\FolderWasUpdated
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Support\Collection\NestedFoldersCollection
;
class
EloquentFolderRepository
extends
EloquentBaseRepository
implements
FolderRepository
{
...
...
@@ -83,6 +84,11 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
return
$this
->
model
->
where
(
'path'
,
'like'
,
"
{
$path
}
%"
)
->
get
();
}
public
function
allNested
()
:
NestedFoldersCollection
{
return
new
NestedFoldersCollection
(
$this
->
all
());
}
/**
* @param array $data
* @return string
...
...
Modules/Media/Repositories/FolderRepository.php
View file @
3e44eaaf
...
...
@@ -5,6 +5,7 @@ namespace Modules\Media\Repositories;
use
Illuminate\Database\Eloquent\Collection
;
use
Modules\Core\Repositories\BaseRepository
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Support\Collection\NestedFoldersCollection
;
interface
FolderRepository
extends
BaseRepository
{
...
...
@@ -20,4 +21,6 @@ interface FolderRepository extends BaseRepository
* @return Collection
*/
public
function
allChildrenOf
(
File
$folder
);
public
function
allNested
()
:
NestedFoldersCollection
;
}
Modules/Media/Tests/EloquentFolderRepositoryTest.php
View file @
3e44eaaf
...
...
@@ -11,6 +11,7 @@ use Modules\Media\Events\FolderWasCreated;
use
Modules\Media\Events\FolderWasUpdated
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Services\FileService
;
use
Modules\Media\Support\Collection\NestedFoldersCollection
;
final
class
EloquentFolderRepositoryTest
extends
MediaTestCase
{
...
...
@@ -239,6 +240,19 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
$this
->
assertCount
(
2
,
$this
->
folder
->
all
());
}
/** @test */
public
function
it_can_find_all_folders_with_nested
()
{
$parentFolder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
]);
$this
->
folder
->
create
([
'name'
=>
'Child folder'
,
'parent_id'
=>
$parentFolder
->
id
]);
$this
->
createFile
();
$this
->
createFile
(
'second-file.jpg'
);
$folders
=
$this
->
folder
->
allNested
();
$this
->
assertInstanceOf
(
NestedFoldersCollection
::
class
,
$folders
);
$this
->
assertCount
(
2
,
$folders
);
}
/** @test */
public
function
it_can_delete_a_folder_from_database
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment