public function mcm_objDelete() { //删除文件对象ById $File = new FileModel(); $id = '5655749ac9a15ae50d392c8e'; $File->objDelete($id); }
public function indexAction() { $fc = FrontController::getInstance(); /* Инициализация модели */ $model = new FileModel(); $model->name = "Гость"; $output = $model->render(USER_DEFAULT_FILE); $fc->setBody($output); }
/** * 文件下载 */ public function downloadAction() { try { $this->file->download($this->_getParam('id')); } catch (Exception $e) { $this->view->feedback(array('title' => '发生错误', 'message' => '指定的文件不存在或者已经被删除', 'linktext' => '点击继续')); } $this->isload = false; }
public function indexAction() { $fc = FrontController::getInstance(); /* Инициализация модели */ $model = new FileModel(); $view = 'moderator.php'; $file = './protected/views/layout/main.php'; $output = $model->render($file, $view); $fc->setBody($output); }
public function indexAction() { $pdo = DB::getInstance()->getConnection(); $fc = FrontController::getInstance(); /* Инициализация модели */ $model = new FileModel(); /* * $model->name = $params['name']; */ $model->name = "Guest"; $output = $model->render(TEMPLATE, USER_DEFAULT_FILE); $fc->setBody($output); }
public function addAction() { $fc = FrontController::getInstance(); $params = $fc->getParams(); $model = new FileModel(); $model->name = $params['name']; $model->role = $params['role']; $str = file_get_contents('data/users.txt'); $arrUsers = unserialize($str); $arrUsers[$model->name] = $model->role; $str_2 = serialize($arrUsers); file_put_contents('data/users.txt', $str_2); $result = $model->render('application/views/' . USER_ADD_FILE); $fc->setBody($result); }
public function renderDefault($url) { $res = dibi::query(' SELECT workId, url as file, title, text,', Model::sqlCategory() . ' as category, authorUrl, CONCAT_WS(" ", name, surname) as authorName, year,', Model::sqlWorkClassName() . 'as workClass,', 'award, type, pages, words, characters, [read], added, edited FROM [works] join [authors] on author = authorId WHERE `url`=%s', $url)->fetchAll(); //$res[0]['award'] = ($res[0]['award'] != 99) ? $res[0]['award'] . ". místo" : "nominaci"; //2010-08-19 22:43:25 $res[0]['added'] = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5', $res[0]['added']); $res[0]['edited'] = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5', $res[0]['edited']); $this->template->data = $res[0]; $this->template->files = FileModel::getFiles($res[0]['workId']); Model::increaseRead($res[0]['workId']); }
protected function renderContent() { $homeUrl = Yii::app()->createUrl('home/default'); $content = '<div class="clearfix">'; $content .= '<a href="#" id="nav-trigger" title="Toggle Navigation">›</a>'; $content .= '<div id="corp-logo">'; if ($logoFileModelId = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'logoFileModelId')) { $logoFileModel = FileModel::getById($logoFileModelId); $logoFileSrc = Yii::app()->getAssetManager()->getPublishedUrl(Yii::getPathOfAlias('application.runtime.uploads') . DIRECTORY_SEPARATOR . $logoFileModel->name); } else { $logoFileSrc = Yii::app()->themeManager->baseUrl . '/default/images/Zurmo_logo.png'; } $logoHeight = ZurmoConfigurationFormAdapter::resolveLogoHeight(); $logoWidth = ZurmoConfigurationFormAdapter::resolveLogoWidth(); if (Yii::app()->userInterface->isMobile()) { $content .= '<a href="' . $homeUrl . '"><img src="' . $logoFileSrc . '" alt="Zurmo Logo" /></a>'; //make sure width and height are NEVER defined } else { $content .= '<a href="' . $homeUrl . '"><img src="' . $logoFileSrc . '" alt="Zurmo Logo" height="' . $logoHeight . '" width="' . $logoWidth . '" /></a>'; } if ($this->applicationName != null) { $content .= ZurmoHtml::tag('span', array(), $this->applicationName); } $content .= '</div>'; if (!empty($this->userMenuItems) && !empty($this->settingsMenuItems)) { $content .= '<div id="user-toolbar" class="clearfix">'; $content .= static::renderHeaderMenus($this->userMenuItems, $this->settingsMenuItems); $content .= '</div>'; } $content .= '</div>'; return $content; }
/** * * @param \Nette\Application\UI\Form $form */ public function serverPropsFormSubmitted(Form $form) { if ($this->allowedToEdit) { $content = $form->getValues()->props; $data = $this->fileModel->checkUnchangeableLines($content, $this->unchangeableLines); $this->fileModel->write($data, $this->filePath); $this->getPresenter()->flashMessage('Nastavení aktualizováno.', 'success'); } else { $this->flashMessage('Nemáte právo editovat nastavení.', 'error'); } if ($this->getPresenter()->isAjax()) { $this->getPresenter()->redrawControl(); } else { $this->getPresenter()->redirect('this'); } }
/** * 打印任务 * POST /task/ * @method POST_index * @param fid 文件id * @param pid 打印店id * @param */ public function POST_indexAction() { $userid = $this->auth(); $response['status'] = 0; if (!Input::post('fid', $fid, 'int')) { $response['info'] = '未选择文件'; } elseif (!Input::post('pid', $pid, 'int')) { $response['info'] = '未选择打印店'; } elseif (!($file = FileModel::where('use_id', $userid)->where('status', '>', 0)->field('url,name,status')->find($fid))) { $response['info'] = '没有该文件或者此文件已经删除'; } else { $task = TaskModel::create('post'); $task['name'] = $file['name']; $task['use_id'] = $userid; $task['pri_id'] = $pid; if (!($task['url'] = File::addTask($file['url']))) { $response['info'] = '文件转换出错'; } elseif (!($tid = TaskModel::insert($task))) { $response['info'] = '任务添加失败'; } else { $response['status'] = 1; $response['info'] = ['msg' => '打印任务添加成功', 'id' => $tid]; } } $this->response = $response; }
public static function createFileModel($fileName = 'testNote.txt') { $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files'); $filePath = $pathToFiles . DIRECTORY_SEPARATOR . $fileName; $contents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . $fileName); $fileContent = new FileContent(); $fileContent->content = $contents; $file = new FileModel(); $file->fileContent = $fileContent; $file->name = $fileName; $file->type = ZurmoFileHelper::getMimeType($pathToFiles . DIRECTORY_SEPARATOR . $fileName); $file->size = filesize($filePath); $saved = $file->save(); assert('$saved'); // Not Coding Standard return $file; }
public function mime() { // http://stackoverflow.com/a/20509354/1478566 // return 'application/octet-stream'; if (self::$mimedb === null) { self::$mimedb = new MimeDatabase(); } return self::$mimedb->resolve($this->file); }
public function handleDelete($id) { Model::delete($id, "authorId", "authors"); $array = dibi::query('SELECT workId FROM works WHERE author=%i', $id)->fetchAssoc(); foreach ($array as $val) { FileModel::deleteFiles($val['workId']); } Model::delete($id, "author", "works"); $this->redirect('this'); }
/** * 删除文件 * */ public function deleteAction() { try { $this->file->delete((int) $this->_getParam('id')); $this->_redirect($this->view->url(array('action' => 'list'))); } catch (Exception $e) { $this->view->feedback(array('message' => '发生错误:' . $e->getMessage())); } $this->isload = false; }
public function addAction() { $fc = FrontController::getInstance(); $params = $fc->getParams(); //Получаем параметры из адресной строки(name/role) $model = new FileModel(); $model->name = $params["name"]; $model->role = $params["role"]; $model->user[$model->name] = $model->role; //Записываем наши значения в "темповый" массив User $model->list = unserialize(file_get_contents(USER_DB)); //Вытягиваем данные из файла пользователей $model->list = array_merge($model->list, $model->user); //Объеденяем массив текущих пользователей с массивом темпового.Перезаписываем file_put_contents(USER_DB, serialize($model->list)); //Перезаписываем файл с данными всех пользователей $result = $model->render(USER_ADD_FILE); $fc->setBody($result); }
public function testToArray() { $model = new FileModel(); $result = $model->toArray(); $attributes = ['Id' => 111, 'Name' => 'Имя']; $model->setAttributes($attributes); $reflectionClass = new ReflectionClass('FileModel'); $properties = $reflectionClass->getProperties(); /** * @var $property ReflectionProperty */ foreach ($properties as $property) { $name = $property->getName(); $value = $model->{$name}; if (array_key_exists($name, $attributes)) { $this->assertEquals($attributes[$name], $value); } else { $this->assertNotContains($name, $result); } } }
protected function populateWithFiles($model, $numberOfFilesToAttach, $pathToFiles) { assert('$model instanceof EmailTemplate || $model instanceof Autoresponder || $model instanceof Campaign'); for ($i = 0; $i < $numberOfFilesToAttach; $i++) { $fileName = $this->files[array_rand($this->files)]; $filePath = $pathToFiles . DIRECTORY_SEPARATOR . $fileName; $contents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . $fileName); $fileContent = new FileContent(); $fileContent->content = $contents; $file = new FileModel(); $file->fileContent = $fileContent; $file->name = $fileName; $file->type = ZurmoFileHelper::getMimeType($pathToFiles . DIRECTORY_SEPARATOR . $fileName); $file->size = filesize($filePath); $saved = $file->save(); if (!$saved) { throw new FailedToSaveModelException(); } $model->files->add($file); } }
public function setUp() { parent::setUp(); $this->user = User::getByUsername('super'); Yii::app()->user->userModel = $this->user; EmailAccount::deleteAll(); EmailMessage::deleteAll(); EmailMessageContent::deleteAll(); EmailMessageSender::deleteAll(); EmailMessageRecipient::deleteAll(); EmailMessageSendError::deleteAll(); FileModel::deleteAll(); }
public function setUp() { parent::setUp(); $this->user = User::getByUsername('super'); Yii::app()->user->userModel = $this->user; EmailAccount::deleteAll(); EmailMessage::deleteAll(); EmailMessageContent::deleteAll(); EmailMessageSender::deleteAll(); EmailMessageRecipient::deleteAll(); EmailMessageSendError::deleteAll(); FileModel::deleteAll(); if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) { $this->markTestSkipped('Please fix the test email settings'); } }
public function actionCreate() { $model = new Image(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $file = UploadedFile::getInstance($model, 'name'); if ($fileModel = FileModel::saveAs($file, '@common/upload')) { } if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->saveUploadedFile() !== false) { $model->save(); return $this->redirect('image/create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } } }
/** * @param string $path * @return array suitable for json */ private function readOpsFromFile($path, $file) { try { $opsFile = $this->fileModel->open($path . $file, FALSE); $json = json_decode(implode('', $opsFile)); $ops = array(); if ($json != NULL) { foreach ($json as $record) { $ops[] = array('uuid' => $record->uuid, 'name' => $record->name, 'level' => $record->level); } return $ops; } else { return array(); } } catch (\Nette\FileNotFoundException $ex) { return array(); } }
public function getAdd($id = null) { if ($id == null) { $new = new AutomateModel(); $new->name = ""; $data['row'] = $new; $data['technology'] = TechnologyModel::all(); $data['plot'] = PlotModel::join('his_technology', 'his_technology.id', '=', 'his_plot.id_tech')->select('his_plot.id', 'his_plot.name', 'his_technology.name as technology')->orderBy('his_plot.id_tech')->get(); $data['file'] = FileModel::where('filename', 'like', '%xls%')->get(); } else { $id = SiteHelpers::encryptID($id, true); $data['technology'] = TechnologyModel::all(); $data['plot'] = PlotModel::all(); $data['file'] = FileModel::where('filename', 'like', '%xls%'); $data['row'] = AutomateModel::where('id', $id)->first(); } return View::make('automate.form', $data); }
/** * 分享文件 * POST /share/ * @method POST_index * @param key 获取token时返回的key */ public function POST_indexAction() { $userid = $this->auth(); $response['status'] = 0; if (!Input::post('fid', $fid, 'int')) { $response['info'] = '未选择文件'; } elseif (!($File = FileModel::field('name,url,status')->where('use_id', '=', $userid)->where('status', '>', 0)->find($fid))) { /*数据库中查询的文件*/ $response['info'] = '文件无效'; } elseif ($File['status'] & self::SHARED_FLAG) { /*是否已经共享*/ $response['info'] = '文件已分享'; } elseif (!($share['url'] = File::share($File->url))) { /*发布到共享空间*/ $response['info'] = '文件转移出错'; } else { /*验证完成,开始插入*/ $share['fil_id'] = $fid; $share['use_id'] = $userid; $share['name'] = Input::post('name', $name, 'title') ? $name : $File->name; if (Input::post('detail', $detail, 'text')) { $share['detail'] = $detail; } if (Input::post('anonymous', $anonymous)) { $share['anonymous'] = boolval($anonymous); } if ($sid = ShareModel::Insert($share)) { //插入成功 //文件状态,更新为已分享 $File->save(['status' => $File['status'] | self::SHARED_FLAG]); //TODO //分享文件预处理 $response['status'] = 1; $response['info'] = ['msg' => '分享成功', 'id' => $sid]; } else { $response['info'] = '分享失败'; } } $this->response = $response; }
/** * Event handler for beforeDelete * @param \yii\base\ModelEvent $event */ public function beforeDelete($event) { $oldId = $this->owner->{$this->savedAttribute}; if (($oldModel = FileModel::findOne($oldId)) !== null) { $event->isValid = $event->isValid && $oldModel->delete(); } }
public function actionDelete($id) { $fileModel = FileModel::getById((int) $id); $fileModel->delete(); //todo: add error handling. }
function postUpload() { $file = Input::file('file'); if ($file) { $destinationPath = public_path() . '/uploads/'; $dir = date('Y-m-d'); if (!file_exists(public_path() . '/uploads/' . $dir)) { mkdir(public_path() . "/uploads/" . $dir, 0777); } $destinationPath = public_path() . '/uploads/' . $dir . '/'; $filename = $file->getClientOriginalName(); $upload_success = Input::file('file')->move($destinationPath, $filename); $file = new FileModel(); $file->filename = $dir . '/' . $filename; $file->uploaded_at = date('Y:m:d h:i:s'); $file->save(); if ($upload_success) { // resizing an uploaded file Image::make($destinationPath . $filename)->resize(100, 100)->save($destinationPath . "100x100_" . $filename); return Response::json('success', 200); } else { return Response::json('error', 400); } } }
/** * @param array $filesIds * @param EmailMessage $emailMessage */ public static function attachFilesToMessage(array $filesIds, $emailMessage) { foreach ($filesIds as $fileId) { $attachment = FileModel::getById((int) $fileId); $emailMessage->files->add($attachment); } }
public function testFileControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->assertEquals(0, count(FileModel::getAll())); $pathToFiles = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files'); $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt'; $contents = file_get_contents($pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt'); //upload a file $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'testNote.txt'; self::resetAndPopulateFilesArrayByFilePathAndName('aTest', $filePath, 'testNote.txt'); $this->resetPostArray(); $this->SetGetArray(array('filesVariableName' => 'aTest')); $content = $this->runControllerWithExitExceptionAndGetContent('zurmo/fileModel/upload'); //Confirm the file has actually been uploaded $files = FileModel::getAll(); $compareJsonString = '[{"name":"testNote.txt","type":"text\\/plain","size":"6.34KB","id":' . $files[0]->id . '}]'; $this->assertEquals($compareJsonString, $content); $fileModels = FileModel::getAll(); $this->assertEquals(1, count($fileModels)); $this->assertEquals($contents, $fileModels[0]->fileContent->content); if (!RedBeanDatabase::isFrozen()) { //add fileModel to a model. $model = new ModelWithAttachmentTestItem(); $model->member = 'test'; $model->files->add($fileModels[0]); $this->assertTrue($model->save()); $modelId = $model->id; $model->forget(); //download a file. $this->setGetArray(array('id' => $fileModels[0]->id, 'modelId' => $modelId, 'modelClassName' => 'ModelWithAttachmentTestItem')); $this->resetPostArray(); $content = $this->runControllerWithExitExceptionAndGetContent('zurmo/fileModel/download'); $compareContent = 'Testing download.'; $this->assertEquals($compareContent, $content); } //todo: test all file errors. //Test deleting a file. $this->assertEquals(1, count(FileModel::getAll())); $this->assertEquals(1, count(FileContent::getAll())); $this->setGetArray(array('id' => $fileModels[0]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('zurmo/fileModel/delete', true); //Now confirm that there are no file models or content in the system. $this->assertEquals(0, count(FileModel::getAll())); $this->assertEquals(0, count(FileContent::getAll())); //Test GlobalSearchAutoComplete $this->assertTrue(ContactsModule::loadStartingData()); $this->setGetArray(array('term' => 'something')); $this->resetPostArray(); $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/default/globalSearchAutoComplete'); $compareContent = '[{"href":"","label":"No results found","iconClass":""}'; // Not Coding Standard $this->assertTrue(strpos($content, $compareContent) !== false); }
/** * @depends testAddingComments */ public function testDeleteSocialItem() { $socialItems = SocialItem::getAll(); $this->assertEquals(1, count($socialItems)); $comments = Comment::getAll(); $this->assertEquals(1, count($comments)); $fileModels = FileModel::getAll(); $this->assertEquals(1, count($fileModels)); foreach ($socialItems as $socialItem) { $socialItemId = $socialItem->id; $socialItem->forget(); $socialItem = SocialItem::getById($socialItemId); $deleted = $socialItem->delete(); $this->assertTrue($deleted); } $socialItems = SocialItem::getAll(); $this->assertEquals(0, count($socialItems)); //check that all comments are removed, since they are owned. $comments = Comment::getAll(); $this->assertEquals(0, count($comments)); $fileModels = FileModel::getAll(); $this->assertEquals(0, count($fileModels)); }
public static function deleteCurrentCustomLogo() { if ($logoFileModelId = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'logoFileModelId')) { //Get path of currently uploaded logo, required to delete/unlink legacy logo from runtime/uploads $logoFileModel = FileModel::getById($logoFileModelId); $currentLogoFileName = $logoFileModel->name; $currentLogoFilePath = Yii::getPathOfAlias('application.runtime.uploads') . DIRECTORY_SEPARATOR . $currentLogoFileName; if (file_exists($currentLogoFilePath)) { unlink($currentLogoFilePath); } } }