ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler Class Reference

Class ilCtrlAwareUploadHandler. More...

+ Inheritance diagram for ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler:
+ Collaboration diagram for ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler:

Public Member Functions

 __construct ()
 ilUIDemoFileUploadHandlerGUI constructor. More...
 
 getFileIdentifierParameterName ()
 
 getUploadURL ()
 
 getExistingFileInfoURL ()
 
 getFileRemovalURL ()
 
 executeCommand ()
 Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented. More...
 
 getInfoResult (string $identifier)
 
 getInfoForExistingFiles (array $file_ids)
 
 supportsChunkedUploads ()
 

Protected Member Functions

 readChunkedInformation ()
 
 getUploadResult ()
 
 getRemoveResult (string $identifier)
 

Protected Attributes

const CMD_UPLOAD = 'upload'
 
const CMD_REMOVE = 'remove'
 
const CMD_INFO = 'info'
 
HttpServices $http
 
ilCtrl $ctrl
 
FileUpload $upload
 
bool $is_chunked = false
 
int $chunk_index = 0
 
int $amount_of_chunks = 0
 
string $chunk_id = null
 
int $chunk_total_size = 0
 

Additional Inherited Members

- Data Fields inherited from ILIAS\UI\Component\Input\Field\UploadHandler
const DEFAULT_FILE_ID_PARAMETER = 'file_id'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::__construct ( )

ilUIDemoFileUploadHandlerGUI constructor.

Definition at line 50 of file AbstractCtrlAwareUploadHandler.php.

References $DIC, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), and ILIAS\Repository\upload().

51  {
52  global $DIC;
53  $this->ctrl = $DIC->ctrl();
54  $this->upload = $DIC->upload();
55  $this->http = $DIC->http();
56  }
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::executeCommand ( )

Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.

The Implementation MUST make sure, the Upload and the Removal Command are handled correctly

Implements ILIAS\FileUpload\Handler\ilCtrlAwareUploadHandler.

Definition at line 105 of file AbstractCtrlAwareUploadHandler.php.

References $response, ILIAS\Repository\ctrl(), ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\getFileIdentifierParameterName(), ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\getInfoForExistingFiles(), ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\getInfoResult(), ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\getRemoveResult(), ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\getUploadResult(), ILIAS\FileDelivery\http(), ILIAS\Filesystem\Stream\Streams\ofString(), ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\readChunkedInformation(), and ILIAS\FileUpload\Handler\HandlerResult\STATUS_FAILED.

105  : void
106  {
107  switch ($this->ctrl->getCmd()) {
108  case self::CMD_UPLOAD:
109  // Here you must save the file and tell the input item the
110  // file-id which will be a FileStorage-ID in a later version
111  // of ILIAS and for now you must implement an own ID which allows
112  // identifying the file after the request
113  try {
114  $this->readChunkedInformation();
115  $content = json_encode($this->getUploadResult());
116  } catch (\Throwable $t) {
117  $content = json_encode(
118  new BasicHandlerResult(
121  '',
122  $t->getMessage()
123  )
124  );
125  }
126  break;
127  case self::CMD_REMOVE:
128  // here you delete the previously uploaded file again, you know
129  // which file to delete since you defined what 'my_file_id' is.
130  $file_identifier = $this->http->request()->getQueryParams()[$this->getFileIdentifierParameterName()];
131  $content = json_encode($this->getRemoveResult($file_identifier));
132  break;
133  case self::CMD_INFO:
134  // here you give info about an already existing file
135  // return a JsonEncoded \ILIAS\FileUpload\Handler\FileInfoResult
136  $file_identifier = $this->http->request()->getQueryParams()[$this->getFileIdentifierParameterName()];
137  $content = json_encode($this->getInfoResult($file_identifier));
138  break;
139  default:
140  $content = '';
141  break;
142  }
143  $response = $this->http->response()->withBody(Streams::ofString($content));
144  $this->http->saveResponse($response);
145  $this->http->sendResponse();
146  $this->http->close();
147  }
static http()
Fetches the global http state from ILIAS.
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:43
$response
+ Here is the call graph for this function:

◆ getExistingFileInfoURL()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getExistingFileInfoURL ( )

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 80 of file AbstractCtrlAwareUploadHandler.php.

References ILIAS\Repository\ctrl().

80  : string
81  {
82  return $this->ctrl->getLinkTargetByClass([static::class], self::CMD_INFO);
83  }
+ Here is the call graph for this function:

◆ getFileIdentifierParameterName()

◆ getFileRemovalURL()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getFileRemovalURL ( )

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 89 of file AbstractCtrlAwareUploadHandler.php.

References ILIAS\Repository\ctrl().

89  : string
90  {
91  return $this->ctrl->getLinkTargetByClass([static::class], self::CMD_REMOVE);
92  }
+ Here is the call graph for this function:

◆ getInfoForExistingFiles()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getInfoForExistingFiles ( array  $file_ids)
abstract
Parameters
array$file_ids
Returns
BasicFileInfoResult[]

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Referenced by ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\executeCommand().

+ Here is the caller graph for this function:

◆ getInfoResult()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getInfoResult ( string  $identifier)
abstract
Returns
null|FileInfoResult for the file with the given identifier or null if the file does not exist.

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Referenced by ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\executeCommand().

+ Here is the caller graph for this function:

◆ getRemoveResult()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getRemoveResult ( string  $identifier)
abstractprotected

Referenced by ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\executeCommand().

+ Here is the caller graph for this function:

◆ getUploadResult()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getUploadResult ( )
abstractprotected

◆ getUploadURL()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::getUploadURL ( )

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 71 of file AbstractCtrlAwareUploadHandler.php.

References ILIAS\Repository\ctrl().

71  : string
72  {
73  return $this->ctrl->getLinkTargetByClass([static::class], self::CMD_UPLOAD);
74  }
+ Here is the call graph for this function:

◆ readChunkedInformation()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::readChunkedInformation ( )
protected

Definition at line 94 of file AbstractCtrlAwareUploadHandler.php.

References ILIAS\FileDelivery\http(), and ILIAS\Repository\int().

Referenced by ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler\executeCommand().

94  : void
95  {
96  $body = $this->http->request()->getParsedBody();
97  $this->chunk_id = $body['dzuuid'] ?? null;
98  $this->amount_of_chunks = (int) ($body['dztotalchunkcount'] ?? 0);
99  $this->chunk_index = (int) ($body['dzchunkindex'] ?? 0);
100  $this->chunk_total_size = (int) ($body['dztotalfilesize'] ?? 0);
101  $this->is_chunked = ($this->chunk_id !== null && $this->amount_of_chunks > 0);
102  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ supportsChunkedUploads()

ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::supportsChunkedUploads ( )
Returns
bool if this uploadhandler chan handle Chunked Uploads. These come in multiple requests and must be combined to a single file. If your UploadHandler can handle Chunked Uploads, you can use a UI with .

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 161 of file AbstractCtrlAwareUploadHandler.php.

161  : bool
162  {
163  return false;
164  }

Field Documentation

◆ $amount_of_chunks

int ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$amount_of_chunks = 0
protected

Definition at line 42 of file AbstractCtrlAwareUploadHandler.php.

◆ $chunk_id

string ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$chunk_id = null
protected

Definition at line 43 of file AbstractCtrlAwareUploadHandler.php.

◆ $chunk_index

int ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$chunk_index = 0
protected

Definition at line 41 of file AbstractCtrlAwareUploadHandler.php.

◆ $chunk_total_size

int ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$chunk_total_size = 0
protected

Definition at line 44 of file AbstractCtrlAwareUploadHandler.php.

◆ $ctrl

ilCtrl ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$ctrl
protected

◆ $http

HttpServices ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$http
protected

Definition at line 36 of file AbstractCtrlAwareUploadHandler.php.

◆ $is_chunked

bool ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$is_chunked = false
protected

Definition at line 40 of file AbstractCtrlAwareUploadHandler.php.

◆ $upload

FileUpload ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::$upload
protected

Definition at line 38 of file AbstractCtrlAwareUploadHandler.php.

◆ CMD_INFO

const ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::CMD_INFO = 'info'
protected

Definition at line 34 of file AbstractCtrlAwareUploadHandler.php.

◆ CMD_REMOVE

const ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::CMD_REMOVE = 'remove'
protected

Definition at line 33 of file AbstractCtrlAwareUploadHandler.php.

◆ CMD_UPLOAD

const ILIAS\FileUpload\Handler\AbstractCtrlAwareUploadHandler::CMD_UPLOAD = 'upload'
protected

Definition at line 32 of file AbstractCtrlAwareUploadHandler.php.


The documentation for this class was generated from the following file: