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; }
protected function importLocationStepsForContinuedIssues() { $issues = DB::connection('oldissue')->select('select * from initlaws where currentphase <> 1 and originpropid > 0'); foreach ($issues as $issue) { $count = 0; $importSteps = DB::connection('oldissue')->select("select * from customsteps where marckfordelete = 0 and propid = {$issue->propid} order by id asc"); if (empty($importSteps)) { continue; } $newLocationStep = new LocationStep(); if (isset($importSteps[0]->optionlocation) && $importSteps[0]->optionlocation == 1) { $newLocationStep->location_id = 3; } elseif (isset($importSteps[0]->optionlocation) && $importSteps[0]->optionlocation == 2) { $newLocationStep->location_id = 4; } elseif ($importSteps[0]->lextypeid == 3 || $importSteps[0]->lextypeid == 4 || $importSteps[0]->lextypeid == 5) { $newLocationStep->location_id = 5; } else { $newLocationStep->location_id = 2; } $newLocationStep->issue_id = $issue->originpropid; $newLocationStep->step_order = 1; $newLocationStep->save(); foreach ($importSteps as $importStep) { $newFlowStep = new FlowStep(); $newFlowStep->id = $importStep->id; $newFlowStep->flow_name = StepAutocomplete::find($importStep->basestepid)->name; $newFlowStep->estimated_duration = $importStep->durata ? $importStep->durata : ''; $newFlowStep->location_step_id = $newLocationStep->id; $newFlowStep->flowstep_order = $count++; $newFlowStep->start_date = $importStep->dataStart; $newFlowStep->end_date = $importStep->dataEnd; $newFlowStep->finalizat = $importStep->dataEnd ? 1 : 0; $translatableData = ['ro' => ['observatii' => $importStep->obsv ? $importStep->obsv : ''], 'en' => ['observatii' => $importStep->enobsv ? $importStep->enobsv : '']]; $newFlowStep->fill($translatableData); $newFlowStep->save(); } } print_r("Au fost importati: " . LocationStep::count() . " locationSteps \n cu " . FlowStep::count() . " flowSteps."); return true; }