protected function importStakeholdersProfile()
 {
     $stakeholders = DB::connection('oldissue')->select('select stackeholderId,profile,enprofile from stackeholders');
     foreach ($stakeholders as $stakeholder) {
         $oldStakeholder = Stakeholder::find($stakeholder->stackeholderId);
         if ($oldStakeholder) {
             $translatableData = ['ro' => ['profile' => $stakeholder->profile ? $stakeholder->profile : ''], 'en' => ['profile' => $stakeholder->enprofile ? $stakeholder->enprofile : '']];
             $oldStakeholder->fill($translatableData);
             $oldStakeholder->save();
         }
     }
     echo sprintf("Au fost updatati: %s stakeholders.\n", Stakeholder::count());
     return true;
 }
 public function testStakeholdersConnected_RemovesOne_TheOthersAreStillThere()
 {
     // Initial state
     // a-->b
     // a-->c
     // Remove a-->c, result should be
     $a_news = $this->newsData();
     $a = News::create($a_news);
     $b_stakeholder = $this->stakeholderData();
     $b = Stakeholder::create($b_stakeholder);
     $c_stakeholder = $this->stakeholderData();
     $c = Stakeholder::create($c_stakeholder);
     // Connect a-->b, a-->c
     $a_news['stakeholders_connected'] = [$b->id, $c->id];
     $response = $this->call('PUT', action('NewsController@update', [$a]), $a_news);
     $this->assertEquals(200, $response->status());
     //news a won't be connected with stakeholder c
     $a_news['stakeholders_connected'] = [$b->id];
     $response = $this->call('PUT', action('NewsController@update', [$a]), $a_news);
     // Check a-x->c
     $c_found = false;
     foreach ($a->connectedStakeholders as $sc) {
         if ($sc->id == $c->id) {
             $c_found = true;
         }
     }
     $this->assertFalse($c_found);
     // Check a-->c
     $b_found = false;
     foreach ($a->connectedStakeholders as $sc) {
         if ($sc->id == $b->id) {
             $b_found = true;
         }
     }
     $this->assertTrue($b_found);
     $c->delete();
     $b->delete();
     $a->delete();
 }
 protected function importStakeholders()
 {
     $stakeholders = DB::connection('oldissue')->select('select * from stackeholders');
     foreach ($stakeholders as $stakeholder) {
         $newStakeholder = new Stakeholder();
         $newStakeholder->id = $stakeholder->stackeholderID;
         $newStakeholder->name = $stakeholder->first_name . ' ' . $stakeholder->last_name;
         if ($stakeholder->isauth === '0') {
             $newStakeholder->type = 'persoana';
         } else {
             $newStakeholder->type = 'organizatie';
         }
         $newStakeholder->site = $stakeholder->blog;
         $newStakeholder->email = $stakeholder->email ? $stakeholder->email : '';
         $newStakeholder->telephone = $stakeholder->phone ? $stakeholder->phone : '';
         $newStakeholder->public_code = str_random(40);
         $translatableData = ['ro' => ['profile' => $stakeholder->profile ? $stakeholder->profile : '', 'position' => $stakeholder->posAndApart ? $stakeholder->posAndApart : '', 'address' => $stakeholder->contact ? $stakeholder->contact : ''], 'en' => ['profile' => $stakeholder->enprofile ? $stakeholder->enprofile : '', 'position' => $stakeholder->enposAndApart ? $stakeholder->enposAndApart : '', 'address' => $stakeholder->encontact ? $stakeholder->encontact : '']];
         $newStakeholder->fill($translatableData);
         $newStakeholder->save();
     }
     return print_r('Au fost importati: ' . Stakeholder::count() . ' stakeholders.' . "\n");
 }
 public function queryStakeholder(Request $request)
 {
     $queryStakeholderName = $request->input('name');
     $stakeholders = Stakeholder::where('name', 'like', '%' . $queryStakeholderName . '%')->get();
     return $stakeholders;
 }
 public function queryInitiator(Request $request)
 {
     $queryInitiatorName = $request->name;
     $initiatorIds = StakeholderTranslation::where('org_name', 'like', '%' . $queryInitiatorName . '%')->lists('stakeholder_id');
     $initiators = Stakeholder::whereIn('id', $initiatorIds)->orWhere('name', 'like', '%' . $queryInitiatorName . '%')->with(['translations'])->get();
     $result = [];
     foreach ($initiators as $initiator) {
         $result[] = ['id' => $initiator->id, 'name' => $initiator->name ? $initiator->name : $initiator->org_name];
     }
     return $result;
 }
 public function testStakeholdersConnected_RemovesOne_TheOthersAreStillThere()
 {
     // Initial state
     // a-->b
     // a-->c
     // b-->d
     // Remove a-->c, result should be
     // a-->b
     // b-->d
     $a_data = $this->stakeholderData();
     $a = Stakeholder::create($a_data);
     $b_data = $this->stakeholderData();
     $b = Stakeholder::create($b_data);
     $c_data = $this->stakeholderData();
     $c = Stakeholder::create($c_data);
     $d_data = $this->stakeholderData();
     $d = Stakeholder::create($d_data);
     // Connect a-->b, a-->c
     $a_data['stakeholders_connected'] = [$b->id, $c->id];
     $response = $this->call('PUT', action('StakeholderController@update', [$a]), $a_data);
     $this->assertEquals(200, $response->status());
     // Connect b-->d
     // a will not be connected to b anymore
     $b_data['stakeholders_connected'] = [$d->id];
     $response = $this->call('PUT', action('StakeholderController@update', [$b]), $b_data);
     // Check a-x->b
     $b_found = false;
     foreach ($a->stakeholdersConnected as $sc) {
         if ($sc->id == $b->id) {
             $b_found = true;
         }
     }
     $this->assertFalse($b_found);
     // Check a-->c
     $c_found = false;
     foreach ($a->stakeholdersConnected as $sc) {
         if ($sc->id == $c->id) {
             $c_found = true;
         }
     }
     $this->assertTrue($c_found);
     // Check b-->d
     $d_found = false;
     foreach ($b->stakeholdersConnected as $sc) {
         if ($sc->id == $d->id) {
             $d_found = true;
         }
     }
     $this->assertTrue($d_found);
     $a->delete();
     $b->delete();
     $c->delete();
     $d->delete();
 }
 /**
  * Query the list of stakeholders for autocomplete purposes
  *
  * @return \Illuminate\Http\Response
  */
 public function queryList(Request $request)
 {
     $queryName = $request->get('name');
     $stakeholders = Stakeholder::where('name', 'like', '%' . $queryName . '%')->get();
     return response()->json($stakeholders);
 }
 public function getStakeholders(Request $request)
 {
     $user = \Auth::user();
     if (!$user or !$user->can_see_stakeholders) {
         abort(403);
     }
     $stakeholders = Stakeholder::paginate(10);
     if ($request->search) {
         $modelInstance = new Stakeholder();
         $stakeholders = $modelInstance->bySearchTerm($request->search)->paginate(10);
     }
     return view('frontend.pages.stakeholders', ['stakeholders' => $stakeholders, 'search' => $request->search ? $request->search : '']);
 }