public function testRenderDownloadLinkContentByRelationModelAndFileModel() { Yii::app()->user->userModel = User::getByUsername('super'); $model = new ModelWithAttachmentTestItem(); $fileModel = ZurmoTestHelper::createFileModel(); $link = FileModelDisplayUtil::renderDownloadLinkContentByRelationModelAndFileModel($model, $fileModel); $this->assertNotNull($link); }
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']; }
public static function renderFileDataDetailsWithDownloadLinksContent($model, $filesRelationName, $showHeaderLabel = false) { $content = null; if ($model->{$filesRelationName}->count() > 0) { $content .= '<ul class="attachments">'; if ($showHeaderLabel) { $content .= '<li><strong>' . Zurmo::t('ZurmoModule', 'Attachments') . '</strong></li>'; } foreach ($model->{$filesRelationName} as $fileModel) { $content .= '<li><span class="icon-attachment"></span>' . FileModelDisplayUtil::renderDownloadLinkContentByRelationModelAndFileModel($model, $fileModel) . '</li>'; } $content .= '</ul>'; } return $content; }
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; }
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; }
public function getLatestActivityExtraDisplayStringByModel($model) { return FileModelDisplayUtil::renderFileDataDetailsWithDownloadLinksContent($model, 'files'); }
/** * (non-PHPdoc) * @see MashableActivityRules::getLatestActivityExtraDisplayStringByModel() * @param Conversation $model * @return null|string */ public function getLatestActivityExtraDisplayStringByModel($model) { assert('$model instanceof Conversation'); $content = null; $filesContent = FileModelDisplayUtil::renderFileDataDetailsWithDownloadLinksContent($model, 'files'); if ($filesContent != null) { if ($content != null) { $content .= '<br/>'; } $content .= $filesContent; } return $content; }
protected function renderCommentsContent() { $content = null; $rows = 0; foreach (array_reverse($this->commentsData) as $comment) { //Skip the first if the page size is smaller than what is returned. if (count($this->commentsData) > $this->pageSize && $this->pageSize != null && $rows == 0) { $rows++; continue; } $userUrl = Yii::app()->createUrl('/users/default/details', array('id' => $comment->createdByUser->id)); $stringContent = ZurmoHtml::link($comment->createdByUser->getAvatarImage(36), $userUrl); $userName = ZurmoHtml::link(strval($comment->createdByUser), $userUrl, array('class' => 'user-link')); $element = new TextAreaElement($comment, 'description'); $element->nonEditableTemplate = '<div class="comment-content"><p>' . $userName . ': {content}</p>'; $stringContent .= $element->render(); //attachments if ($comment->files->count() > 0) { $stringContent .= FileModelDisplayUtil::renderFileDataDetailsWithDownloadLinksContent($comment, 'files', true); } if ($comment->createdByUser == Yii::app()->user->userModel || $this->relatedModel->createdByUser == Yii::app()->user->userModel || $this->relatedModel instanceof OwnedSecurableItem && $this->relatedModel->owner == Yii::app()->user->userModel) { $deleteCommentLink = ' · <span class="delete-comment">' . $this->renderDeleteLinkContent($comment) . '</span>'; $editCommentLink = ' · <span class="edit-comment">' . $this->renderEditLinkContent($comment) . '</span>'; } else { $deleteCommentLink = null; $editCommentLink = null; } $editCommentLink = null; //temporary until edit link is added $stringContent .= '<span class="comment-details"><strong>' . DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($comment->createdDateTime, 'long', null) . '</strong></span>' . $editCommentLink . $deleteCommentLink; $stringContent .= '</div>'; $content .= '<div class="comment">' . $stringContent . '</div>'; $rows++; } return $content; }
protected static function renderMaxSizeContent($maxSize, $showMaxSize) { assert('is_int($maxSize) || $maxSize == null'); assert('is_bool($showMaxSize)'); if ($maxSize == null || !$showMaxSize) { return; } $content = ' ' . Yii::t('Default', 'Max upload size: {maxSize}', array('{maxSize}' => FileModelDisplayUtil::convertSizeToHumanReadableAndGet($maxSize))); return $content; }
private static function renderItemFileContent(SocialItem $model) { return ZurmoHtml::tag('span', array(), FileModelDisplayUtil::renderFileDataDetailsWithDownloadLinksContent($model, 'files')); }
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; }