public function testConvertSizeToHumanReadableAndGet()
 {
     $readableSize = FileModelDisplayUtil::convertSizeToHumanReadableAndGet(5000);
     $this->assertEquals('4.88KB', $readableSize);
     $readableSize = FileModelDisplayUtil::convertSizeToHumanReadableAndGet(500000);
     $this->assertEquals('488.28KB', $readableSize);
     $readableSize = FileModelDisplayUtil::convertSizeToHumanReadableAndGet(5000000);
     $this->assertEquals('4.77MB', $readableSize);
     $readableSize = FileModelDisplayUtil::convertSizeToHumanReadableAndGet(500000000);
     $this->assertEquals('476.84MB', $readableSize);
     $readableSize = FileModelDisplayUtil::convertSizeToHumanReadableAndGet(5000000000);
     $this->assertEquals('4.66GB', $readableSize);
 }
Esempio n. 2
0
 protected function renderControlEditable()
 {
     assert('$this->model instanceof Item || $this->model->getModel() instanceof Item');
     $existingFilesInformation = array();
     foreach ($this->model->files as $existingFile) {
         $existingFilesInformation[] = array('name' => $existingFile->name, 'size' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet((int) $existingFile->size), 'id' => $existingFile->id);
     }
     $inputNameAndId = $this->getEditableInputId('files');
     $cClipWidget = new CClipWidget();
     $cClipWidget->beginClip("filesElement");
     $cClipWidget->widget('application.core.widgets.FileUpload', array('uploadUrl' => Yii::app()->createUrl("zurmo/fileModel/upload", array('filesVariableName' => $inputNameAndId)), 'deleteUrl' => Yii::app()->createUrl("zurmo/fileModel/delete"), 'inputName' => $inputNameAndId, 'inputId' => $inputNameAndId, 'hiddenInputName' => 'filesIds', 'formName' => $this->form->id, 'allowMultipleUpload' => true, 'existingFiles' => $existingFilesInformation, 'maxSize' => (int) InstallUtil::getMaxAllowedFileSize(), 'showMaxSize' => $this->getShowMaxSize(), 'id' => $this->getId()));
     $cClipWidget->endClip();
     return $cClipWidget->getController()->clips['filesElement'];
 }
Esempio n. 3
0
 public function actionCloneExistingFiles($commaSeparatedExistingModelIds)
 {
     assert('is_string($commaSeparatedExistingModelIds)');
     $existingFileModelIds = explode(',', $commaSeparatedExistingModelIds);
     // Not Coding Standard
     $newFileModelsData = array();
     //needs id, name, size at least, preferably type too.
     foreach ($existingFileModelIds as $existingFileModelId) {
         $newFileModel = FileModelUtil::makeByExistingFileModelId($existingFileModelId);
         if ($newFileModel === false) {
             throw new FailedFileUploadException();
         }
         $newFileModelsData[] = array('name' => $newFileModel->name, 'type' => $newFileModel->type, 'size' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($newFileModel->size), 'id' => $newFileModel->id);
     }
     $newFileModelsJson = CJSON::encode($newFileModelsData);
     echo $newFileModelsJson;
 }
Esempio n. 4
0
 protected static function renderMaxSizeContent($maxSize, $showMaxSize)
 {
     assert('is_int($maxSize) || $maxSize == null');
     assert('is_bool($showMaxSize)');
     if ($maxSize == null || !$showMaxSize) {
         return;
     }
     $content = '<span class="max-upload-size">' . Zurmo::t('Core', 'Max upload size: {maxSize}', array('{maxSize}' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($maxSize))) . '</span>';
     return $content;
 }
Esempio n. 5
0
 protected static function renderMaxSizeContent($maxSize, $showMaxSize)
 {
     assert('is_int($maxSize) || $maxSize == null');
     assert('is_bool($showMaxSize)');
     if ($maxSize == null || !$showMaxSize) {
         return;
     }
     $content = '&#160;' . Yii::t('Default', 'Max upload size: {maxSize}', array('{maxSize}' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($maxSize)));
     return $content;
 }
 public static function saveImageFromTemporaryFile($tempFilePath, $name)
 {
     $fileContent = new FileContent();
     $fileContent->content = file_get_contents($tempFilePath);
     $imageProperties = getimagesize($tempFilePath);
     $imageFileModel = new ImageFileModel();
     static::resolveImageName($name, $imageProperties['mime']);
     $imageFileModel->name = $name;
     $imageFileModel->size = filesize($tempFilePath);
     $imageFileModel->type = $imageProperties['mime'];
     $imageFileModel->width = $imageProperties[0];
     $imageFileModel->height = $imageProperties[1];
     $imageFileModel->fileContent = $fileContent;
     if ($imageFileModel->save()) {
         $imageFileModel->createImageCache();
         $fileUploadData = array('id' => $imageFileModel->id, 'name' => $imageFileModel->name, 'summary' => ImageFileModelUtil::getImageSummary($imageFileModel), 'size' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($imageFileModel->size), 'thumbnail_url' => Yii::app()->createAbsoluteUrl('zurmo/imageModel/getThumb', array('fileName' => $imageFileModel->getImageCacheFileName())), 'filelink' => Yii::app()->createAbsoluteUrl('zurmo/imageModel/getImage', array('fileName' => $imageFileModel->getImageCacheFileName())), 'insert_link' => static::resolveInsertLink($imageFileModel));
     } else {
         $message = Zurmo::t('ZurmoModule', 'Error uploading the image');
         $fileUploadData = array('error' => $message);
     }
     return $fileUploadData;
 }