private function userDocTypes() { // get all projects a user has access to $projects = ProjectHandler::getUserProjects(Auth::user()); $projects = array_column($projects, 'name'); $types = []; $allunits = 0; $searchComponent = new MediaSearchComponent(); // for each project get the document types in it foreach ($projects as $key => $project) { $docTypes = Unit::distinct('documentType')->where('project', $project)->get()->toArray(); // skip if there is no data if (!empty($docTypes[0])) { // for each document type get the number of units $types[$project] = []; foreach ($docTypes as $key => $type) { $count = Unit::where('project', $project)->where('documentType', $type[0])->count(); $allunits += $count; $types[$project][$type[0]] = $count; } } } return [$types, $allunits]; }
/** * Display user settings */ public function getSettings(UserAgent $user) { $groups = ProjectHandler::getUserProjects($user); return View::make('users.settings')->with('user', $user)->with('groups', $groups); }
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]); }