/** * 本体実行前にクラスを初期化する */ static function init() { $ins = self::getinstance(); Page::attach($ins); Attach::attach($ins); AttachedFile::attach($ins); }
protected function loadModel($id) { $attachedFile = AttachedFile::model()->findByPk($id); if (!$attachedFile) { throw new CHttpException(404); } return $attachedFile; }
public static function uploadFile(AttachedFile $attachedFile, $attributes, $modelType, $modelId, $fileInstance) { $attachedFile->attributes = $attributes; $attachedFile->modelType = $modelType; $attachedFile->modelId = $modelId; if ($attachedFile->attachType == AttachedFile::ATTACH_TYPE_FILE) { $attachedFile->file = $fileInstance; $basePath = Yii::getPathOfAlias('webroot') . '/public/attached'; if (!file_exists($basePath)) { mkdir($basePath, 0777, true); } $path = $basePath . '/' . md5(time() . $attachedFile->file->getName()); $attachedFile->filePath = $path; $attachedFile->fileName = $attachedFile->file->getName(); $attachedFile->fileSize = $attachedFile->file->getSize(); if ($attachedFile->validate()) { $attachedFile->file->saveAs($path); } } $attachedFile->save(); return $attachedFile; }
public function processSurveys(array $surveys) { foreach ($surveys as $survey) { if ($survey->surveyInfo == null) { $info = new SurveyInfo(); $info->surveyId = $survey->sid; $info->surveyType = $survey->location; $survey->surveyInfo = $info; } if ($survey->surveyInfo->isActive == null) { $survey->surveyInfo->isActive = $survey->isActive(); $survey->surveyInfo->save(); } else { if ($survey->surveyInfo->isActive && $survey->surveyInfo->isActive != $survey->isActive()) { $attachedFiles = AttachedFile::model()->findAllByAttributes(array('fileType' => AttachedFile::FILE_TYPE_FULL_ANALYTICS, 'modelId' => $survey->sid, 'modelType' => get_class($survey))); $linksToFiles = array(); $filesToAttachment = array(); foreach ($attachedFiles as $file) { if ($file->attachType == AttachedFile::ATTACH_TYPE_LINK) { $linksToFiles[$file->filePath] = $file->name; } elseif ($file->attachType == AttachedFile::ATTACH_TYPE_FILE) { $filesToAttachment[$file->filePath] = $file->fileName; } } $exportHelper = new ExcelExportSurveyHelper($survey); $res = $exportHelper->export(); if ($res != null) { $excelFilepath = "/tmp/" . md5(time() . "_" . $survey->sid . "_" . $survey->location) . '.xls'; file_put_contents($excelFilepath, $res['content']); $filesToAttachment[$excelFilepath] = 'Массив данных в Excel.xls'; } $mail = new YiiMailer(); $mail->setFrom(Yii::app()->params['adminEmail'], 'Администраток ЛК'); $mail->setTo(Yii::app()->params['adminEmail']); $mail->setSubject('Опрос перешёл в список завершённых.'); $mail->setView('surveyChangeActivity'); $mail->setData(array('survey' => $survey, 'linksToFiles' => $linksToFiles)); $mail->setAttachment($filesToAttachment); echo "[" . date("Y-m-d H:i:s") . "] try to send mail\n"; if (!$mail->send()) { echo "[" . date("Y-m-d H:i:s") . "] fail \n"; print_r($mail->getError()); echo PHP_EOL; } $survey->surveyInfo->isActive = $survey->isActive(); $survey->surveyInfo->save(); } } } }
function do_url() { if (empty(Vars::$get['page']) || empty(Vars::$get['file'])) { exit; } if (!mb_ereg('\\.(.+?)$', Vars::$get['file'], $m) || empty(self::$type[$m[1]])) { exit; } $file = AttachedFile::getinstance(Vars::$get['file'], Page::getinstance(Vars::$get['page'])); header('Content-Type: ' . self::$type[$m[1]]); header('Content-Length: ' . $file->getsize()); echo $file->getdata(); exit; }
/** * Constructor */ protected function __construct($filename, $page) { if (empty(self::$notifier)) { self::$notifier = new NotifierImpl(); } $this->filename = $filename; $this->page = $page; }
</thead> <tbody> <?php foreach ($model->attachedFiles as $attachedFile) { ?> <tr> <td><?php echo $attachedFile->name; ?> </td> <td><?php echo AttachedFile::model()->getAttributeLabel($attachedFile->attachType); ?> </td> <td><?php echo AttachedFile::model()->getAttributeLabel($attachedFile->fileType); ?> </td> <td> <?php echo CHtml::link($attachedFile, $attachedFile->getURL(), array('target' => '_blank')); ?> </td> <td> <?php $deleteFileUrl = Yii::app()->createUrl('/attachedFile/delete', array('id' => $attachedFile->id)); ?> <a class="delete-link" data-title="Удалить" title="" data-toggle="tooltip" href="<?php echo $deleteFileUrl; ?> " data-original-title="Удалить">
protected function show() { if (!isset(Vars::$get['page']) || !isset(Vars::$get['file'])) { throw new CommandException('パラメータが足りません。', $this); } $page = Page::getinstance(Vars::$get['page']); if ($page->isnull() || Vars::$get['file'] == '') { throw new CommandException('パラメータが正しくありません。', $this); } $smarty = $this->getSmarty(); $smarty->assign('filename', Vars::$get['file']); $smarty->assign('pagename', $page->getpagename()); $file = AttachedFile::getinstance(Vars::$get['file'], $page); $smarty->assign('size', $file->getsize()); $smarty->assign('count', $file->getcount()); $smarty->assign('timestamp', $file->gettimestamp()); $smarty->assign('md5', md5($file->getdata())); $ret['title'] = $page->getpagename() . ' の添付ファイル ' . Vars::$get['file']; $ret['pagename'] = Vars::$get['page']; $ret['body'] = $smarty->fetch('show.tpl.htm'); return $ret; }
/** * Attach project file to this object * * @param ProjectFile $file * @return AttachedFiles */ function attachFile(ProjectFile $file) { $manager_class = get_class($this->manager()); $object_id = $this->getObjectId(); $attached_file = AttachedFiles::findById(array('rel_object_manager' => $manager_class, 'rel_object_id' => $object_id, 'file_id' => $file->getId())); // findById if ($attached_file instanceof AttachedFile) { return $attached_file; // Already attached } // if $attached_file = new AttachedFile(); $attached_file->setRelObjectManager($manager_class); $attached_file->setRelObjectId($object_id); $attached_file->setFileId($file->getId()); $attached_file->save(); if (!$file->getIsVisible()) { $file->setIsVisible(true); $file->setExpirationTime(EMPTY_DATETIME); $file->save(); } // if return $attached_file; }