/**
  * @param                          $id
  * @param Request                  $request
  * @param ActivityElementValidator $activityElementValidator
  * @return \Illuminate\Http\RedirectResponse
  */
 public function updateStatus($id, Request $request, ActivityElementValidator $activityElementValidator)
 {
     $activityData = $this->activityManager->getActivityData($id);
     if (Gate::denies('ownership', $activityData)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorize('edit_activity', $activityData);
     $input = $request->all();
     $activityWorkflow = $input['activity_workflow'];
     if ($activityWorkflow == 3) {
         $this->authorize('publish_activity', $activityData);
     }
     $settings = $this->settingsManager->getSettings($activityData['organization_id']);
     $transactionData = $this->activityManager->getTransactionData($id);
     $resultData = $this->activityManager->getResultData($id);
     $organization = $this->organizationManager->getOrganization($activityData->organization_id);
     $orgElem = $this->organizationManager->getOrganizationElement();
     $activityElement = $this->activityManager->getActivityElement();
     $xmlService = $activityElement->getActivityXmlService();
     if ($activityWorkflow == 1) {
         $validationMessage = $activityElementValidator->validateActivity($activityData, $transactionData);
         if ($validationMessage) {
             $response = ['type' => 'warning', 'code' => ['message', ['message' => $validationMessage]]];
             return redirect()->back()->withResponse($response);
         }
         $messages = $xmlService->validateActivitySchema($activityData, $transactionData, $resultData, $settings, $activityElement, $orgElem, $organization);
         if ($messages != []) {
             $response = ['type' => 'danger', 'messages' => $messages, 'activity' => 'true'];
             return redirect()->back()->withResponse($response);
         }
     } elseif ($activityWorkflow == 3) {
         if (empty($settings['registry_info'][0]['publisher_id']) && empty($settings['registry_info'][0]['api_id'])) {
             $response = ['type' => 'warning', 'code' => ['settings_registry_info', ['name' => '']]];
             return redirect()->to('/settings')->withResponse($response);
         }
         $xmlService->generateActivityXml($activityData, $transactionData, $resultData, $settings, $activityElement, $orgElem, $organization);
         if ($settings['registry_info'][0]['publish_files'] == 'yes') {
             $publishedStatus = $this->publishToRegistry();
             $this->activityManager->updateStatus($input, $activityData);
             if ($publishedStatus) {
                 $this->activityManager->makePublished($activityData);
                 $this->activityManager->activityInRegistry($activityData);
                 $this->twitter->post($settings, $organization);
                 $response = ['type' => 'success', 'code' => ['publish_registry_publish', ['name' => '']]];
                 return redirect()->back()->withResponse($response);
             } else {
                 $response = ['type' => 'warning', 'code' => ['publish_registry', ['name' => '']]];
                 return redirect()->back()->withResponse($response);
             }
         }
     }
     $statusLabel = ['Completed', 'Verified', 'Published'];
     $response = $this->activityManager->updateStatus($input, $activityData) ? ['type' => 'success', 'code' => ['activity_statuses', ['name' => $statusLabel[$activityWorkflow - 1]]]] : ['type' => 'danger', 'code' => ['activity_statuses_failed', ['name' => $statusLabel[$activityWorkflow - 1]]]];
     return redirect()->back()->withResponse($response);
 }
 /**
  * @param $data
  * @param $activity
  * @return mixed
  */
 public function update(array $data, Activity $activity)
 {
     return $this->activityManager->updateStatus($data, $activity);
 }