/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Alert::sendAllNewsAlerts();
     Alert::sendAllIssueAlerts();
     Alert::sendReportAlerts();
     Alert::deleteUnsentAlertsWithoutDestination();
 }
 public function preview($id)
 {
     if (Gate::denies('preview-alerts')) {
         abort(403);
     }
     $alert = Alert::find($id);
     return view('admin.backend.alerts.headpreview', ['alert' => $alert]);
 }
Example #3
0
 public static function updateAlert($item, $itemType)
 {
     $currentAlertNotSent = self::getUnsentAlert($item, $itemType);
     if ($currentAlertNotSent) {
         return $currentAlertNotSent;
     }
     $alert = Alert::createAlert($item, $itemType);
     return $alert;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(NewsRequest $request, $news)
 {
     if (Gate::denies('update-news')) {
         abort(403);
     }
     $news->setAll($request);
     if ($request->published) {
         Alert::updateAlert($news, 'Issue\\News');
     } else {
         Alert::deleteUnsentAlert($news, 'Issue\\News');
     }
     return $news;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $issue)
 {
     if (Gate::denies('update-issue')) {
         abort(403);
     }
     $issue->setAll($request);
     $issue->syncLocations($request->location);
     if ($request->published) {
         Alert::updateAlert($issue, 'Issue\\Issue');
     } else {
         Alert::deleteUnsentAlert($issue, 'Issue\\Issue');
     }
     if ($request->addToLegalNews) {
         $this->addToLegalNews($issue);
     }
     return $issue;
 }
 public function syncSteps($steps)
 {
     $currentSteps = $this->flowsteps()->get();
     if (!is_array($steps)) {
         $steps = [];
     }
     $index = 0;
     foreach ($steps as $id => $step) {
         $index++;
         $steps[$id]['flowstep_order'] = $index;
     }
     foreach ($currentSteps as $currentStep) {
         if (!array_key_exists($currentStep->id, $steps)) {
             $currentStep->delete();
             continue;
         }
         if (!array_key_exists('finalizat', $steps[$currentStep->id])) {
             $steps[$currentStep->id]['finalizat'] = 0;
         }
         $currentStep->fill($steps[$currentStep->id]);
         if (array_key_exists('observatii', $steps[$currentStep->id])) {
             foreach (\Config::get('app.all_locales') as $locale) {
                 $currentStep->translateOrNew($locale)->observatii = $steps[$currentStep->id]['observatii'][$locale];
             }
         }
         if (array_key_exists('start_date', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['start_date'] == '') {
                 $currentStep->start_date = null;
             }
         }
         if (array_key_exists('estimated_duration', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['estimated_duration'] == '') {
                 $currentStep->estimated_duration = null;
             }
         }
         if (array_key_exists('end_date', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['end_date'] == '') {
                 $currentStep->end_date = null;
             }
         }
         if (array_key_exists('delete_end_date', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['delete_end_date'] == '1') {
                 $currentStep->end_date = null;
             }
         }
         if (array_key_exists('delete_start_date', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['delete_start_date'] == '1') {
                 $currentStep->start_date = null;
             }
         }
         $this->flowsteps()->save($currentStep);
         if (array_key_exists('addToLegalNews', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['addToLegalNews'] == true) {
                 $legalNews = new LegalNews();
                 foreach (\Config::get('app.all_locales') as $locale) {
                     $legalNews->translateOrNew($locale)->title = $currentStep->flowstepsInLocation->issue->getAttribute('name:' . $locale);
                     $legalNews->translateOrNew($locale)->content = $currentStep->getAttribute('observatii:' . $locale);
                 }
                 $legalNews->issue_id = $currentStep->flowstepsInLocation->issue_id;
                 $legalNews->save();
             }
         }
         if (array_key_exists('published', $steps[$currentStep->id])) {
             if ($steps[$currentStep->id]['published'] == true && Alert::getUnsentAlert($currentStep, 'Issue\\FlowStep') == null) {
                 Alert::createAlert($currentStep, 'Issue\\FlowStep');
             }
         } else {
             Alert::deleteUnsentAlert($currentStep, 'Issue\\FlowStep');
         }
         if (!array_key_exists('document_id', $steps[$currentStep->id])) {
             $steps[$currentStep->id]['document_id'] = [];
         }
         $currentStep->syncStepDocuments($steps[$currentStep->id]['document_id']);
         unset($steps[$currentStep->id]);
     }
     foreach ($steps as $stepData) {
         $newFlowStep = new FlowStep();
         $newFlowStep->fill($stepData);
         if (array_key_exists('observatii', $stepData)) {
             foreach (\Config::get('app.all_locales') as $locale) {
                 $newFlowStep->translateOrNew($locale)->observatii = $stepData['observatii'][$locale];
             }
         }
         if (!array_key_exists('finalizat', $stepData)) {
             $stepData['finalizat'] = 0;
         }
         if (array_key_exists('start_date', $stepData)) {
             if ($stepData['start_date'] == '') {
                 $newFlowStep->start_date = null;
             }
         }
         if (array_key_exists('estimated_duration', $stepData)) {
             if ($stepData['estimated_duration'] == '') {
                 $newFlowStep->estimated_duration = null;
             }
         }
         if (array_key_exists('end_date', $stepData)) {
             if ($stepData['end_date'] == '') {
                 $newFlowStep->end_date = null;
             }
         }
         if (array_key_exists('delete_end_date', $stepData)) {
             if ($stepData['delete_end_date'] == '1') {
                 $newFlowStep->end_date = null;
             }
         }
         if (array_key_exists('delete_start_date', $stepData)) {
             if ($stepData['delete_start_date'] == '1') {
                 $newFlowStep->start_date = null;
             }
         }
         $this->flowsteps()->save($newFlowStep);
         if (array_key_exists('addToLegalNews', $stepData)) {
             if ($stepData['addToLegalNews'] == true) {
                 $legalNews = new LegalNews();
                 foreach (\Config::get('app.all_locales') as $locale) {
                     $legalNews->translateOrNew($locale)->title = $newFlowStep->flowstepsInLocation->issue->getAttribute('name:' . $locale);
                     $legalNews->translateOrNew($locale)->content = $newFlowStep->getAttribute('observatii:' . $locale);
                 }
                 $legalNews->issue_id = $newFlowStep->flowstepsInLocation->issue_id;
                 $legalNews->save();
             }
         }
         if (array_key_exists('published', $stepData)) {
             if ($stepData['published'] == true) {
                 Alert::createAlert($newFlowStep, 'Issue\\FlowStep');
             }
         }
         if (!array_key_exists('document_id', $stepData)) {
             $stepData['document_id'] = [];
         }
         $newFlowStep->syncStepDocuments($stepData['document_id']);
     }
     return true;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(ReportRequest $request, $report)
 {
     if (Gate::denies('update-reports')) {
         abort(403);
     }
     $report->setAll($request);
     if ($request->published) {
         Alert::updateAlert($report, 'Issue\\Report');
     } else {
         Alert::deleteUnsentAlert($report, 'Issue\\Report');
     }
     return $report;
 }