public function getExternalIssueInfo($id, $name)
 {
     $issue = Issue::findOrFail($id);
     if ($name != Str::slug($issue->name)) {
         abort(403);
     }
     $newsList = $issue->connectedNews()->orderBy('date', 'DESC')->paginate(10);
     $stakeholdersList = $issue->connectedStakeholders->chunk(10);
     $initiatorsList = $issue->connectedInitiatorsStakeholders->chunk(10);
     $dateNow = (new \DateTime())->format('Y-m-d H:i:s');
     return view('frontend.external.issue', ['issue' => $issue, 'locations' => Location::all(), 'newsList' => $newsList, 'stakeholdersList' => $stakeholdersList, 'initiatorsList' => $initiatorsList, 'dateNow' => $dateNow]);
 }
 public function getIssueInfo($id, $name)
 {
     $issue = Issue::findOrFail($id);
     $issueDomains = $issue->connectedDomains;
     if (!$issueDomains || $issueDomains->isEmpty()) {
         abort(403);
     }
     $allowedDomains = Domain::getUserAndPublicDomains();
     $intersection = $allowedDomains->intersect($issueDomains);
     if (!$intersection || $intersection->isEmpty()) {
         abort(403);
     }
     if ($name != Str::slug($issue->name)) {
         abort(403);
     }
     $newsList = $issue->connectedNews()->orderBy('date', 'desc')->paginate(10);
     $stakeholdersList = $issue->connectedStakeholders->chunk(10);
     $initiatorsList = $issue->connectedInitiatorsStakeholders->chunk(10);
     $dateNow = (new \DateTime())->format('Y-m-d H:i:s');
     return view('frontend.pages.info-issue', ['issue' => $issue, 'domain' => $issueDomains[0]->id, 'locations' => Location::all(), 'newsList' => $newsList, 'stakeholdersList' => $stakeholdersList, 'initiatorsList' => $initiatorsList, 'dateNow' => $dateNow]);
 }
 public function queryIssue(Request $request)
 {
     $queryIssueName = $request->input('name');
     $issueIds = IssueTranslation::where('name', 'like', '%' . $queryIssueName . '%')->where('locale', \App::getLocale())->lists('issue_id');
     $issues = Issue::whereIn('id', $issueIds)->with(['translations'])->get();
     $result = [];
     foreach ($issues as $issue) {
         $result[] = ['id' => $issue->id, 'name' => $issue->name];
     }
     return $result;
 }
 protected function importDocuments()
 {
     $allFiles = [];
     $pathToFiles = sprintf('%s/var/www/andr_v2/uploads/reldocs', storage_path());
     $oldDocuments = DB::connection('oldissue')->select('select * from relateddoc
         where propid > 120 and stepid <> 0
     ');
     foreach ($oldDocuments as $document) {
         if (!$document->filepaths) {
             continue;
         }
         if (!Issue::find($document->propid)) {
             continue;
         }
         $documentPath = sprintf('%s/propid_%s/stepid_%s/', $pathToFiles, $document->propid, $document->stepid);
         try {
             $getFileNamesFromFolder = array_diff(scandir($documentPath), ['.', '..']);
             if (!$getFileNamesFromFolder) {
                 continue;
             }
             foreach ($getFileNamesFromFolder as $file) {
                 if (!$file) {
                     continue;
                 }
                 if (in_array($file, $allFiles)) {
                     continue;
                 }
                 $allFiles[] = $file;
                 $fullPathToFile = sprintf('%s%s', $documentPath, $file);
                 do {
                     $randomName = str_random(40);
                 } while (UploadedFile::where('file_name', $randomName)->count() > 0);
                 do {
                     $codPublic = str_random(40);
                 } while (Document::where('public_code', $codPublic)->count() > 0);
                 $uploadedFileData = ['file_name' => $randomName, 'folder' => '/documents/', 'original_file_name' => $file];
                 $this->moveFile($fullPathToFile, $uploadedFileData['file_name']);
                 $doc = factory(Document::class)->create(['public' => 1, 'uploaded_file_id' => factory(UploadedFile::class)->create($uploadedFileData)->id, 'public_code' => $codPublic, 'init_at' => $document->initat]);
                 $translatableData = ['ro' => ['title' => $document->content ? $document->content : ''], 'en' => ['title' => $document->encontent ? $document->encontent : '']];
                 $doc->fill($translatableData);
                 $doc->save();
                 try {
                     $doc->steps()->attach($document->stepid);
                 } catch (\Exception $e) {
                     print_r("Shiit! O relatie Document - FlowStep nu s-a putut importa.\n");
                 }
             }
         } catch (\Exception $e) {
             print_r("Shiit! Un folder nu exista.\n");
         }
     }
     echo sprintf("Au fost importate %s documente.\n", Document::count());
     return true;
 }