public function createFile() { $dbFile = new DBFile(); $dbFile->name = Input::get('filename'); $dbFile->path = ""; $dbFile->uploader = Auth::user()->id; $dbFile->size = "Unknown"; $dbFile->content = ""; $dbFile->filetype = Input::get('filetype'); $uploaded = $dbFile->save(); $allowEditing = Input::get('allowediting'); $post = new Post(); $grp = Group::where('uid', '=', Input::get('uid'))->first(); $filelist = unserialize($grp->files); array_push($filelist, $dbFile->id); $grp->files = serialize($filelist); $grp->save(); $post->parent = $grp->id; $post->title = Auth::user()->firstname . ' ' . Auth::user()->lastname . ' has created a new file.'; if ($allowEditing) { $post->content = 'A new file named \'' . $dbFile->name . '\' has been created. Click <a href="' . URL::to('g/' . $grp->uid . '/edit/' . $dbFile->id) . '">here</a> to edit it.'; } else { $post->content = 'A new file named \'' . $dbFile->name . '\' has been created. Click <a href="' . URL::to('g/' . $grp->uid . '/view/' . $dbFile->id) . '">here</a> to view it.'; } $post->creator = Auth::user()->id; $post->save(); if ($uploaded) { return Redirect::to('g/' . Input::get('uid') . '/edit/' . $dbFile->id); } else { return Response::jscon('error', 400); } }
public function insertFile($fields) { $f = new DBFile(); if (!isset($fields['task_id'])) { $fields['task_id'] = $this->_dbtask->lastInsert(); } $f->create($fields); }
public function store($data) { $validator = \Validator::make($data, ['file' => 'required']); if ($validator->fails()) { $exception = new \Watson\Validating\ValidationException('Model failed validation'); $exception->setErrors($validator->messages()); throw $exception; } $file = new \DBFile(); $path = $data['path'] ? $data['path'] . '/' : ''; $file->name = $path . $data['file']->getClientOriginalName(); $file->size = $data['file']->getSize(); $file->mime = $data['file']->getMimeType(); $file->system_name = uniqid() . '-' . $data['file']->getClientOriginalName(); $file->save(); $this->saveFile($data['file'], $file->system_name); return $file; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $file = DBFile::find($id); $file->content = Input::get('content'); if ($file->save()) { return Response::json(array('success' => 'yes')); } else { return Response::json(array('success' => 'no')); } }
/** * Set this store as the new asset backend * * @param string $basedir Basedir to store assets, which will be placed beneath 'assets' folder */ public static function activate($basedir) { // Assign this as the new store $publicAdapter = new PublicAssetAdapter(ASSETS_PATH . '/' . $basedir); $publicFilesystem = new Filesystem($publicAdapter, ['visibility' => AdapterInterface::VISIBILITY_PUBLIC]); $protectedAdapter = new ProtectedAssetAdapter(ASSETS_PATH . '/' . $basedir . '/.protected'); $protectedFilesystem = new Filesystem($protectedAdapter, ['visibility' => AdapterInterface::VISIBILITY_PRIVATE]); $backend = new AssetStoreTest_SpyStore(); $backend->setPublicFilesystem($publicFilesystem); $backend->setProtectedFilesystem($protectedFilesystem); Injector::inst()->registerService($backend, 'AssetStore'); // Assign flysystem backend to generated asset handler at the same time $generated = new FlysystemGeneratedAssetHandler(); $generated->setFilesystem($publicFilesystem); Injector::inst()->registerService($generated, 'GeneratedAssetHandler'); Requirements::backend()->setAssetHandler($generated); // Disable legacy and set defaults Config::inst()->remove(get_class(new FlysystemAssetStore()), 'legacy_filenames'); Config::inst()->update('Director', 'alternate_base_url', '/'); DBFile::config()->force_resample = false; File::config()->force_resample = false; self::reset(); self::$basedir = $basedir; // Ensure basedir exists \Filesystem::makeFolder(self::base_path()); }
public function taskFindTaskFiles($taskId) { $f = new DBFile(); return $f->findFile($taskId); }
/** * Set this store as the new asset backend * * @param string $basedir Basedir to store assets, which will be placed beneath 'assets' folder */ public static function activate($basedir) { // Assign this as the new store $adapter = new AssetAdapter(ASSETS_PATH . '/' . $basedir); $filesystem = new Filesystem($adapter); $filesystem->addPlugin(new FlysystemUrlPlugin()); $backend = new AssetStoreTest_SpyStore(); $backend->setFilesystem($filesystem); Injector::inst()->registerService($backend, 'AssetStore'); // Disable legacy and set defaults Config::inst()->remove(get_class(new FlysystemAssetStore()), 'legacy_filenames'); Config::inst()->update('Director', 'alternate_base_url', '/'); DBFile::config()->force_resample = false; File::config()->force_resample = false; self::reset(); self::$basedir = $basedir; // Ensure basedir exists SS_Filesystem::makeFolder(self::base_path()); }
/** * Safely encodes the File object with all standard fields required * by the front end * * @param string $filename * @param string $hash * @param string $variant * @return array Encoded list of file attributes */ protected function encodeAssetAttributes($filename, $hash, $variant) { // Force regeneration of file thumbnail for this tuple (without saving into db) $object = DBFile::create(); $object->setValue(array('Filename' => $filename, 'Hash' => $hash, 'Variant' => $variant)); return array('filename' => $filename, 'hash' => $hash, 'variant' => $variant, 'name' => $object->getBasename(), 'url' => $object->getURL(), 'thumbnail_url' => $object->ThumbnailURL($this->getPreviewMaxWidth(), $this->getPreviewMaxHeight()), 'size' => $object->getAbsoluteSize(), 'type' => File::get_file_type($object->getFilename()), 'buttons' => (string) $this->renderWith($this->getTemplateFileButtons()), 'fieldname' => $this->getName()); }
return View::make('workgroups.groups.index', array('group' => $wg)); }); Route::get('{groupid}/edit/{fileid}', function ($groupid, $fileid) { $finfo = DBFile::find($fileid); return View::make('workgroups.groups.edit')->with('fdata', $finfo); }); Route::get('{groupid}/settings', function ($groupid) { $wg = Group::where('uid', '=', $groupid)->firstOrFail(); if (!Auth::check() || Auth::user()->id != $wg->ownerid) { return Redirect::to('error/not-owner'); } else { return View::make('workgroups.groups.settings')->with('groupinfo', $wg); } }); Route::get('{groupid}/view/{fileid}', function ($groupid, $fileid) { $file = DBFile::find($fileid); $wg = Group::where('uid', '=', $groupid)->firstOrFail(); return View::make('workgroups.groups.viewfile', array('fdata' => $file, 'group' => $wg)); }); Route::get('{groupid}/removeuser/{userid}', function ($groupid, $userid) { $group = Group::where('uid', '=', $groupid)->firstOrFail(); $members = unserialize($group->members); for ($i = 0; $i < count($members); $i++) { if ($members[$i] == $userid) { unset($members[$i]); } } $members = array_values($members); $group->members = serialize($members); $group->save(); return Redirect::to('g/' . $groupid);