create() 공개 정적인 메소드

Helper to quickly create a new asset
public static create ( integer $parentId, array $data = [], $save = true ) : Asset
$parentId integer
$data array
리턴 Asset
 public function importUrlAction()
 {
     $success = true;
     $data = Tool::getHttpData($this->getParam("url"));
     $filename = basename($this->getParam("url"));
     $parentId = $this->getParam("id");
     $parentAsset = Asset::getById(intval($parentId));
     $filename = File::getValidFilename($filename);
     $filename = $this->getSafeFilename($parentAsset->getFullPath(), $filename);
     if (empty($filename)) {
         throw new \Exception("The filename of the asset is empty");
     }
     // check for duplicate filename
     $filename = $this->getSafeFilename($parentAsset->getFullPath(), $filename);
     if ($parentAsset->isAllowed("create")) {
         $asset = Asset::create($parentId, array("filename" => $filename, "data" => $data, "userOwner" => $this->user->getId(), "userModification" => $this->user->getId()));
         $success = true;
     } else {
         \Logger::debug("prevented creating asset because of missing permissions");
     }
     $this->_helper->json(array("success" => $success));
 }
예제 #2
0
파일: Folder.php 프로젝트: pimcore/pimcore
 /**
  * @param string $name
  * @throws DAV\Exception\Forbidden
  */
 public function createDirectory($name)
 {
     $user = AdminTool::getCurrentUser();
     if ($this->asset->isAllowed("create")) {
         $asset = Asset::create($this->asset->getId(), ["filename" => Element\Service::getValidKey($name, "asset"), "type" => "folder", "userModification" => $user->getId(), "userOwner" => $user->getId()]);
     } else {
         throw new DAV\Exception\Forbidden();
     }
 }
예제 #3
0
 /**
  * @param string $name
  * @throws DAV\Exception\Forbidden
  */
 function createDirectory($name)
 {
     $user = AdminTool::getCurrentUser();
     if ($this->asset->isAllowed("create")) {
         $asset = Asset::create($this->asset->getId(), array("filename" => File::getValidFilename($name), "type" => "folder", "userModification" => $user->getId(), "userOwner" => $user->getId()));
     } else {
         throw new DAV\Exception\Forbidden();
     }
 }
예제 #4
0
 /**
  * @param string base64
  * @return Asset
  */
 public function convertToAsset($imgstr)
 {
     $uploadDir = PIMCORE_TMP_DIRECTORY . '/asset-temporary/';
     $content = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $imgstr));
     $name = uniqid() . '.png';
     $file = $uploadDir . $name;
     $success = file_put_contents($file, $content);
     if ($success) {
         $parentAsset = Asset_Folder::getById(71);
         $asset = Asset::create($parentAsset->getId(), array("filename" => $name, "data" => file_get_contents($file)));
         return $asset;
     } else {
         return false;
     }
 }