/**
  * Update settings
  *
  * @param  int                   $id
  * @param SettingsRequestManager $settingRequest
  * @return
  * @internal param TempRequest|SettingsRequestManager $request
  */
 public function update($id, SettingsRequestManager $settingRequest)
 {
     $currentUser = auth()->user();
     if ($currentUser->isNotAdmin()) {
         return redirect()->back()->withResponse(['type' => 'warning', 'code' => ['message', ['message' => 'You do not have the correct privileges to view this page.']]]);
     }
     $input = $settingRequest->requestHandler->all();
     $newPublishingType = $input['publishing_type'][0]['publishing'];
     $oldIdentifier = $this->organization->reporting_org[0]['reporting_organization_identifier'];
     $settings = $this->settingsManager->getSettings($this->organization->id);
     $publishingType = $settings->publishing_type;
     $activities = $this->activityManager->getActivities($this->organization->id);
     if ($publishingType != $newPublishingType) {
         $publishedFiles = $this->activityManager->getActivityPublishedFiles(Session::get('org_id'));
         if (count($publishedFiles)) {
             $this->generateNewFiles($newPublishingType, $activities);
         }
     }
     $reportingOrgIdentifier = $input['reporting_organization_info'][0]['reporting_organization_identifier'];
     foreach ($activities as $activity) {
         $status = $activity['published_to_registry'];
         $otherIdentifier = (array) $activity->other_identifier;
         if ($status == 1 && !in_array(["reference" => $oldIdentifier, "type" => "B1", 'owner_org' => []], $otherIdentifier) && $oldIdentifier !== $reportingOrgIdentifier) {
             $otherIdentifier[] = ['reference' => $oldIdentifier, 'type' => 'B1', 'owner_org' => []];
             $this->otherIdentifierManager->update(['other_identifier' => $otherIdentifier], $activity);
         }
     }
     $result = $this->settingsManager->updateSettings($input, $this->organization, $this->settings);
     if (!$result) {
         $response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Settings']]];
         return redirect()->back()->withResponse($response);
     }
     $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Settings']]];
     return redirect()->to(config('app.admin_dashboard'))->withResponse($response);
 }
 /**
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $activities = $this->activityManager->getActivities($this->organization_id);
     foreach ($activities as $key => $activity) {
         if ($activity->activity_workflow == 3) {
             $filename = $this->getPublishedActivityFilename($this->organization_id, $activity);
             $filenames[$activity->id] = $filename;
             $activityPublishedStatus = $this->getPublishedActivityStatus($filename, $this->organization_id);
             $activityPublishedStats[$activity->id] = $activityPublishedStatus;
             $message = $this->getMessageForPublishedActivity($activityPublishedStatus, $filename);
             $messages[$activity->id] = $message;
         }
     }
     return view('Activity.index', compact('activities', 'filenames', 'activityPublishedStats', 'messages'));
 }
 /** Returns all the activities of the organization
  * @param $orgId
  * @return \App\Models\Activity\Activity
  */
 public function getActivitiesOfOrganization($orgId)
 {
     $activities = $this->activityManager->getActivities($orgId);
     return $activities;
 }