* @package tao */ class tao_helpers_form_elements_xhtml_GenerisAsyncFile extends tao_helpers_form_elements_GenerisAsyncFile { use XhtmlRenderingTrait; /** * Short description of method feed * * @access public * @author Jerome Bogaerts, * @return mixed */ public function feed() { if (isset($_POST[$this->name])) { $structure = json_decode($_POST[$this->name], true); if ($structure !== false) { $description = new tao_helpers_form_data_UploadFileDescription( array_key_exists( 'name', $structure ) ? $structure['name'] : null, array_key_exists('size', $structure) ? $structure['size'] : null, array_key_exists('type', $structure) ? $structure['type'] : null, array_key_exists('uploaded_file', $structure) ? $structure['uploaded_file'] : null, array_key_exists('action', $structure) ? $structure['action'] : null ); $this->setValue($description); } else { // else, no file was selected by the end user. // set the value as empty in order $this->setValue($_POST[$this->name]); } } } /** * Short description of method render * * @access public * @author Jerome Bogaerts, * @return string */ public function render() { $widgetContainerId = $this->buildWidgetContainerId(); $returnValue = $this->renderLabel(); $returnValue .= "
"; if ($this->value instanceof tao_helpers_form_data_UploadFileDescription && $this->value->getAction() == tao_helpers_form_data_UploadFileDescription::FORM_ACTION_DELETE) { // File deleted, nothing to render } elseif ($this->value instanceof tao_helpers_form_data_FileDescription && ($file = $this->value->getFile()) != null) { // A file is stored or has just been uploaded. $shownFileName = $this->value->getName(); $shownFileSize = $this->value->getSize(); $shownFileSize = number_format($shownFileSize / 1000, 2); // to kb. $shownFileTxt = sprintf(__('%s (%s kb)'), $shownFileName, $shownFileSize); $deleteButtonTitle = __("Delete"); $deleteButtonId = $this->buildDeleteButtonId(); $downloadButtonTitle = __("Download"); $downloadButtonId = $this->buildDownloadButtonId(); $iFrameId = $this->buildIframeId(); $returnValue .= "${shownFileTxt}"; $returnValue .= "