/** * Load data for the Media Upload View and return the view ready to be sent * back to the user. */ private function loadMediaUploadView() { // Load properties from file uploader software component. // TODO: replace for $data = new FileUploader ? $data = SoftwareComponent::find("fileuploader"); $dbDomains = $data->domains; $domains = []; $names = []; $fileTypes = []; $doctypes = []; foreach ($dbDomains as $domainKey => $domain) { // $domainKey = $domain['key']; array_push($domains, $domainKey); $names[$domainKey] = $domain['name']; $fileTypeList = ''; foreach ($domain['file_formats'] as $fileType) { $fileTypeList = $fileTypeList . ' ' . $fileType; } $fileTypes[$domainKey] = $fileTypeList; $doctypes[$domainKey] = $domain['document_types']; } $userprojects = ProjectHandler::getUserProjects(Auth::user()); $userprojects = array_column($userprojects, 'name'); return View::make('media.pages.upload')->with('domains', $domains)->with('names', $names)->with('fileTypes', $fileTypes)->with('doctypes', $doctypes)->with('projects', $userprojects); }
public function getIndex() { $c = Input::get('collection', 'Entity'); $collection = $this->repository->returnCollectionObjectFor($c); // Filter data for projects for which the authenticated user has permissions. if (Input::has('authkey')) { $user = \MongoDB\UserAgent::where('api_key', Input::get('authkey'))->first(); if (is_null($user)) { return ['error' => 'Invalid auth key: ' . Input::get('authkey')]; } } elseif (Auth::check()) { $user = Auth::user(); } else { return ['error' => 'Authentication required. Please supply authkey.']; } $projects = ProjectHandler::getUserProjects($user, Permissions::PROJECT_READ); $projectNames = array_column($projects, 'name'); $collection = $collection->whereIn('project', $projectNames); if (Input::has('match')) { $collection = $this->processFields($collection); } $start = (int) Input::get('start', 0); $limit = (int) Input::get('limit', 100); $only = Input::get('only', array()); if ($orderBy = Input::get('orderBy')) { foreach ($orderBy as $sortingColumnName => $sortingDirection) { $collection = $collection->orderBy($sortingColumnName, $sortingDirection); } } $collection = $collection->paginate($limit, $only); $pagination = $collection->links()->render(); $count = $collection->toArray(); unset($count['data']); $documents = $collection->toArray()['data']; if (array_key_exists('tocsv', Input::all())) { set_time_limit(1200); $writer = new Writer(new \SplTempFileObject()); $writer->setNullHandlingMode(Writer::NULL_AS_EMPTY); $headerDotted = array(); foreach ($documents as $line_index => $row) { unset($row['metrics'], $row['platformJobId'], $row['results'], $row['cache']); if (isset($row['parents'])) { $row['wasDerivedFrom'] = implode(",", $row['parents']); unset($row['parents']); } foreach (array_dot($row) as $k => $v) { array_push($headerDotted, $k); } } $headerDotted = array_unique($headerDotted); natcasesort($headerDotted); $csvHeader = array_change_key_case(str_replace('.', '_', array_values($headerDotted)), CASE_LOWER); $writer->insertOne($csvHeader); foreach ($documents as $line_index => $row) { if (isset($row['parents'])) { $row['wasDerivedFrom'] = implode(",", $row['parents']); unset($row['parents']); } $row = array_dot($row); foreach ($headerDotted as $column) { if (isset($row[$column])) { $csvRow[str_replace('.', '_', $column)] = $row[$column]; } else { $csvRow[str_replace('.', '_', $column)] = ""; } } $writer->insertOne($csvRow); } $writer->output(time() . '.csv'); die; } return Response::json(["count" => $count, "pagination" => $pagination, "searchQuery" => Input::except('page'), "documents" => $documents]); }
/** * Display user settings */ public function getSettings(UserAgent $user) { $groups = ProjectHandler::getUserProjects($user); return View::make('users.settings')->with('user', $user)->with('groups', $groups); }