-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* @date 29/01/2018 | ||
* @author Wojciech Peisert <wpeisert@divante.pl> | ||
* @copyright Copyright (c) 2018 DIVANTE (http://divante.pl) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PimcoreDevkitBundle\Service; | ||
|
||
use Pimcore\Model\Asset\Folder; | ||
use Pimcore\Model\Asset; | ||
|
||
/** | ||
* Class AssetService | ||
* | ||
* @package PimcoreDevkitBundle\Service | ||
*/ | ||
class AssetService | ||
{ | ||
/** | ||
* Returns asset folder. If not existent, creates it. | ||
* | ||
* @param int $parentId | ||
* @param string $key | ||
* @return Folder | ||
* @internal param string $name | ||
*/ | ||
public function getOrCreateAssetFolder($parentId, $key) | ||
{ | ||
/** @var Asset $parent */ | ||
$parent = Asset::getById($parentId); | ||
$key = Asset\Service::getValidKey($key, 'folder'); | ||
$path = $parent->getRealFullPath() . '/' . $key; | ||
|
||
$folder = Folder::getByPath($path); | ||
if (!$folder instanceof Folder) { | ||
$folder = Folder::create( | ||
$parentId, | ||
[ | ||
'parentId' => $parentId, | ||
'creationDate' => time(), | ||
'userOwner' => 0, | ||
'userModification' => 0, | ||
'path' => $key, | ||
'published' => true, | ||
'type' => 'folder', | ||
'locked' => true, | ||
'filename' => $key, | ||
] | ||
); | ||
} | ||
|
||
return $folder; | ||
} | ||
} |