/**
  * Generate a file url
  *
  * @param string $fileName
  * @param array $options
  *      string path
  *      array filters
  * @return string
  */
 public function __invoke($fileName, array $options)
 {
     $currentPath = $options['path'] . '/' . $fileName;
     // generate a directory navigation link
     if (is_dir(FileManagerBaseModel::getUserBaseFilesDir() . '/' . $options['path'] . '/' . $fileName)) {
         // get the directory url
         $directoryUrl = $this->getView()->url('application/page', ['controller' => $this->getView()->applicationRoute()->getParam('controller'), 'action' => $this->getView()->applicationRoute()->getParam('action')], ['force_canonical' => true, 'query' => ['path' => $currentPath] + $options['filters']]);
         return $this->getView()->partial('file-manager/patrial/directory-url', ['name' => $fileName, 'url' => $directoryUrl]);
     }
     // generate a file link
     return $this->getView()->partial('file-manager/patrial/file-url', ['file_extension' => FileSystemUtility::getFileExtension($fileName), 'name' => $fileName, 'url' => $this->view->serverUrl() . $this->view->basePath() . '/' . FileManagerBaseModel::getUserBaseFilesUrl() . '/' . $currentPath]);
 }
Example #2
0
 /**
  * Test delete user home directory
  */
 public function testDeleteUserHomeDirectory()
 {
     // test user data
     $data = ['nick_name' => Rand::getString(32), 'email' => Rand::getString(32), 'api_key' => Rand::getString(32), 'role' => AclModelBase::DEFAULT_ROLE_MEMBER, 'language' => null];
     // create a test user
     $query = $this->userModel->insert()->into('user_list')->values($data);
     $statement = $this->userModel->prepareStatementForSqlObject($query);
     $statement->execute();
     $testUserId = $this->userModel->getAdapter()->getDriver()->getLastGeneratedValue();
     // create a test user's home directory
     $homeUserDirectory = FileManagerBaseModel::getUserBaseFilesDir($testUserId) . '/' . FileManagerBaseModel::getHomeDirectoryName();
     FileSystemUtility::createDir($homeUserDirectory);
     // fire the delete user event
     UserEvent::fireUserDeleteEvent($testUserId, $data);
     // delete the created user
     $query = $this->userModel->delete()->from('user_list')->where(['user_id' => $testUserId]);
     $statement = $this->userModel->prepareStatementForSqlObject($query);
     $statement->execute();
     // home directory must be deleted
     $this->assertFalse(file_exists($homeUserDirectory));
 }