Example #1
0
 /**
  * Return tree node full path based on current path
  *
  * @return string
  */
 public function getTreeCurrentPath()
 {
     $treePath = '/root';
     $path = $this->_storageHelper->getSession()->getCurrentPath();
     if ($path) {
         $path = str_replace($this->_storageHelper->getStorageRoot(), '', $path);
         $relative = '';
         foreach (explode('/', $path) as $dirName) {
             if ($dirName) {
                 $relative .= '/' . $dirName;
                 $treePath .= '/' . $this->urlEncoder->encode($relative);
             }
         }
     }
     return $treePath;
 }
Example #2
0
 /**
  * Upload file
  *
  * @param string $targetPath
  * @return bool
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function uploadFile($targetPath)
 {
     /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
     $uploader = $this->_objectManager->create('Magento\\MediaStorage\\Model\\File\\Uploader', ['fileId' => 'file']);
     $uploader->setAllowedExtensions($this->_helper->getAllowedExtensionsByType());
     $uploader->setAllowRenameFiles(true);
     $uploader->setFilesDispersion(false);
     $result = $uploader->save($targetPath);
     if (!$result) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t upload the file right now.'));
     }
     $this->_createThumbnail($targetPath . '/' . $uploader->getUploadedFileName());
     $result['cookie'] = ['name' => $this->_helper->getSession()->getName(), 'value' => $this->_helper->getSession()->getSessionId(), 'lifetime' => $this->_helper->getSession()->getCookieLifetime(), 'path' => $this->_helper->getSession()->getCookiePath(), 'domain' => $this->_helper->getSession()->getCookieDomain()];
     return $result;
 }
Example #3
0
 public function testGetSession()
 {
     $this->assertInstanceOf('Magento\\Backend\\Model\\Session', $this->helper->getSession());
 }