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
6e1f87cb
Unverified
Commit
6e1f87cb
authored
Sep 30, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding file repository method to get all files w/o folders
parent
dc98714c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
EloquentFileRepository.php
...es/Media/Repositories/Eloquent/EloquentFileRepository.php
+12
-0
FileRepository.php
Modules/Media/Repositories/FileRepository.php
+4
-0
EloquentFileRepositoryTest.php
Modules/Media/Tests/EloquentFileRepositoryTest.php
+11
-0
No files found.
Modules/Media/Repositories/Eloquent/EloquentFileRepository.php
View file @
6e1f87cb
...
...
@@ -172,4 +172,16 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
{
return
$this
->
model
->
where
(
'folder_id'
,
$folderId
)
->
get
();
}
public
function
findForVirtualPath
(
string
$path
)
{
$prefix
=
config
(
'asgard.media.config.files-path'
);
return
$this
->
model
->
where
(
'path'
,
$prefix
.
$path
)
->
first
();
}
public
function
allForGrid
()
:
Collection
{
return
$this
->
model
->
where
(
'is_folder'
,
0
)
->
get
();
}
}
Modules/Media/Repositories/FileRepository.php
View file @
6e1f87cb
...
...
@@ -44,4 +44,8 @@ interface FileRepository extends BaseRepository
* @return Collection
*/
public
function
allChildrenOf
(
int
$folderId
)
:
Collection
;
public
function
findForVirtualPath
(
string
$path
);
public
function
allForGrid
()
:
Collection
;
}
Modules/Media/Tests/EloquentFileRepositoryTest.php
View file @
6e1f87cb
...
...
@@ -246,6 +246,17 @@ class EloquentFileRepositoryTest extends MediaTestCase
$this
->
assertEquals
(
$nestedFolder
->
id
,
$file
->
folder_id
);
}
/** @test */
public
function
it_can_fetch_all_files_only
()
{
$folderRepository
=
app
(
FolderRepository
::
class
);
$folderRepository
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$this
->
createFile
();
$this
->
createFile
();
$this
->
assertCount
(
2
,
$this
->
file
->
allForGrid
());
}
private
function
createFile
(
$fileName
=
'random/name.jpg'
)
{
return
File
::
create
([
...
...
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