/** * @param $activity * @return array */ public function getXmlData(Activity $activity) { $activityData = []; $documentLinks = $activity->documentLinks()->get(); foreach ($documentLinks as $documentLink) { $documentLink = $documentLink->document_link; $activityData[] = ['@attributes' => ['url' => $documentLink['url'], 'format' => $documentLink['format']], 'title' => ['narrative' => $this->buildNarrative($documentLink['title'][0]['narrative'])], 'category' => ['@attributes' => ['code' => isset($documentLink['category'][0]['code']) ? $documentLink['category'][0]['code'] : '']], 'language' => ['@attributes' => ['code' => isset($documentLink['language'][0]['language']) ? $documentLink['language'][0]['language'] : '']]]; } return $activityData; }
/** * @param $activity * @return array */ public function getXmlData(Activity $activity) { $activityData = []; $documentLinks = $activity->documentLinks()->get(); foreach ($documentLinks as $documentLink) { $documentLink = $documentLink->document_link; $activityData[] = ['@attributes' => ['url' => $documentLink['url'], 'format' => $documentLink['format']], 'title' => ['narrative' => $this->buildNarrative(getVal($documentLink, ['title', 0, 'narrative'], []))], 'category' => ['@attributes' => ['code' => getVal($documentLink, ['category', 0, 'code'])]], 'language' => ['@attributes' => ['code' => getVal($documentLink, ['language', 0, 'language'])]], 'document-date' => ['@attributes' => ['iso-date' => getVal($documentLink, ['document_date', 0, 'date'])]]]; } return $activityData; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('auth/login'); } } elseif (session('role_id') == 3) { $route = $request->route(); $routeName = $route->getName(); if ($routeName == 'activity.show') { $activityId = $route->getParameter('activity'); $orgId = Activity::select('organization_id')->find($activityId)->organization_id; } elseif ($routeName == 'organization.show') { $orgId = $route->getParameter('organization'); } else { $orgId = session('org_id'); } if ($orgId && $this->auth->user()->isSuperAdmin()) { $userId = User::select('id')->where('org_id', $orgId)->where('role_id', 1)->first()->id; app(OrganizationController::class)->masqueradeOrganization($orgId, $userId); } elseif (!$orgId && !isSuperAdminRoute()) { return redirect(config('app.super_admin_dashboard')); } } elseif (isSuperAdminRoute()) { $response = ['type' => 'warning', 'code' => ['message', ['message' => "You don't have correct privilege"]]]; return redirect(config('app.admin_dashboard'))->withResponse($response); } return $next($request); }
/** * Get the file being published for the Activity with a specific activityId. * @param $activityId * @return ActivityPublished|null */ public function fileBeingPublished($activityId) { $activity = $this->activity->findOrFail($activityId); $settings = $activity->organization->settings; $publisherId = getVal($settings->registry_info, [0, 'publisher_id']); return $this->getFile($publisherId, $settings->publishing_type, $activityId, $activity->organization_id); }
/** * get the identifiers of all activity * @param $orgId * @return array */ public function getIdentifiers($orgId) { $activities = $this->activity->where('organization_id', $orgId)->get(); $identifiers = []; foreach ($activities as $activityRow) { $identifiers[$activityRow->identifier['activity_identifier']] = $activityRow->id; } return $identifiers; }
/** * @return mixed */ public function buildActivityXml() { $activities = Activity::all(); $xmlData = []; foreach ($activities as $activity) { $xmlData[] = $this->fetchActivityData($activity); } return $xmlData; }
/** * @param $id * @param OrganizationManager $organizationManager * @return \Illuminate\View\View */ public function index($id, OrganizationManager $organizationManager) { $activity = Activity::find($id); if (Gate::denies('ownership', $activity)) { return redirect()->back()->withResponse($this->getNoPrivilegesMessage()); } if ($activity) { $reportingOrganization = $organizationManager->getOrganization(Session::get('org_id'))->reporting_org; return view('Activity.ReportingOrganization.edit', compact('reportingOrganization', 'id')); } return redirect()->route('activity.index')->withResponse(['messages' => ['Activity with id' . $id . ' not found.'], 'type' => 'danger']); }
/** * return activity data with results and transactions * @param int $id */ private function getActivityData($id) { $activityData = Activity::find($id); if ($activityData) { $activityData = $activityData->toArray(); $reportingOrg = Organization::find($activityData['organization_id'])->reporting_org; $results = ActivityResult::where('activity_id', $id)->get()->toArray(); $transactions = Transaction::where('activity_id', $id)->get()->toArray(); $documentLinks = ActivityDocumentLink::where('activity_id', $id)->get()->toArray(); $activityData['results'] = $results; $activityData['transactions'] = $transactions; $activityData['document_link'] = $documentLinks; $activityData['reporting_organization'] = $reportingOrg; } return $activityData; }
/** * update Activity Default * @param array $activityDefaults * @param Activity $activity * @return bool */ public function update(array $activityDefaults, Activity $activity) { $activity->default_field_values = $activityDefaults; return $activity->save(); }
/** * get identifier except activityId of an organization * @param $activityId * @return mixed */ public function getActivityIdentifiersForOrganizationExcept($activityId) { return $this->activity->where(function ($query) use($activityId) { $query->where('id', '<>', $activityId)->where('organization_id', '=', session('org_id')); })->get(['identifier']); }
/** * @param $activityId * @return model */ public function getOtherIdentifierData($activityId) { return Activity::findorFail($activityId)->other_identifier; }
/** * @param $activityId * @return array */ public function getDefaultFlowTypeData($activityId) { return $this->activity->findOrFail($activityId)->default_flow_type; }
/** * creates new transaction * @param $transactionDetails * @param $activity */ public function create(array $transactionDetails, Activity $activity) { $transactionDetails = $this->checkSectorVocabulary($transactionDetails); $transaction = $this->transaction->newInstance(['transaction' => $transactionDetails['transaction'][0]]); $activity->transactions()->save($transaction); }
/** * duplicate activity * @param Activity $activityData * @return bool */ public function duplicateActivityAction(Activity $activityData) { try { $this->database->beginTransaction(); $activityData->save(); $this->database->commit(); $this->logger->info('Activity has been Duplicated.', ['for ' => $activityData->id]); $this->logger->activity("activity.activity_duplicated", ['activity_id' => $activityData->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]); return true; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['ActivityIdentifier' => $activityData]); } return false; }
/** * @param $activityId * @return model */ public function getLegacyData($activityId) { return $this->activity->findOrFail($activityId)->legacy_data; }
/** * @param $activityId * @return array */ public function getCountryBudgetItemData($activityId) { return $this->activity->findOrFail($activityId)->country_budget_items; }
/** * @param $activityId * @return array */ public function getDefaultAidTypeData($activityId) { return $this->activity->findOrFail($activityId)->default_aid_type; }
/** * @param Activity $activity * @param $element * @return bool */ public function deleteElement(Activity $activity, $element) { $activity->{$element} = null; return $activity->save(); }
/** * @param $activityId * @return model */ public function getLocation($activityId) { return $this->activity->findOrFail($activityId)->location; }
/** * @param $activityId * @return model */ public function getRecipientCountryData($activityId) { return $this->activity->findOrFail($activityId)->recipient_country; }
/** * @param $activityId * @return model */ public function getDescriptionData($activityId) { return $this->activity->findorFail($activityId)->description; }
/** * @param $activityId * @return array */ public function getCollaborationTypeData($activityId) { return $this->activity->findOrFail($activityId)->collaboration_type; }
/** * @param $activityId * @return model */ public function getBudgetData($activityId) { return $this->activity->findorFail($activityId)->budget; }
/** * @param $activityId * @return model */ public function getActivityDateData($activityId) { return $this->activity->findorFail($activityId)->activity_date; }
/** * @param $activityId * @return array */ public function getRecipientRegionData($activityId) { return $this->activity->findOrFail($activityId)->recipient_region; }
/** * @param $activityId * @return model */ public function getActivityScopeData($activityId) { return $this->activity->findorFail($activityId)->activity_scope; }
/** * @param $activityId * @return array */ public function getParticipatingOrganizationData($activityId) { return $this->activity->findOrFail($activityId)->participating_organization; }
/** * @param $organization_id * @return mixed */ protected function getActivities($organization_id) { return $this->activity->where('organization_id', $organization_id)->get(); }
/** * @param $activityId * @return model */ public function getContactInfoData($activityId) { return $this->activity->findorFail($activityId)->contact_info; }
/** * update title and description * @param array $activityDetails * @param Activity $activity * @return bool */ public function update(array $activityDetails, Activity $activity) { $activity->title = $activityDetails['title']; $activity->description = $activityDetails['description']; return $activity->save(); }