コード例 #1
0
ファイル: ApiTest.php プロジェクト: valera33/pdtask
 /**
  * A basic test example.
  *
  * @return void
  */
 public function testCreateRequest()
 {
     //$this->assertTrue(true);
     $testData = ["org_name" => "Paradise Island", "daughters" => [["org_name" => "Banana tree", "daughters" => [["org_name" => "Yellow Banana"], ["org_name" => "Brown Banana"], ["org_name" => "Green Banana"]]]]];
     //making store request
     $this->post('api/organizations/store', $testData)->seeJson(["success" => true]);
     //chcking if they exist in DB
     $this->seeInDatabase('organizations', ['org_name' => "Paradise Island"]);
     $this->seeInDatabase('organizations', ['org_name' => 'Banana tree']);
     $this->seeInDatabase('organizations', ['org_name' => 'Yellow Banana']);
     $this->seeInDatabase('organizations', ['org_name' => 'Brown Banana']);
     $this->seeInDatabase('organizations', ['org_name' => 'Green Banana']);
     $org = Organization::where('org_name', "Banana tree")->first();
     $org->load('parent', 'daughters');
     //checking relations
     $this->assertEquals("Paradise Island", $org->parent->org_name);
     $this->assertEquals("Yellow Banana", $org->daughters[0]->org_name);
     $this->assertEquals("Brown Banana", $org->daughters[1]->org_name);
     $this->assertEquals("Green Banana", $org->daughters[2]->org_name);
     //making get organization request, and expecting exact json
     //I need organization details to insert correct creation time to json
     $org1 = Organization::where('org_name', "Paradise Island")->first();
     $org2 = Organization::where('org_name', "Banana tree")->first();
     $org3 = Organization::where('org_name', "Yellow Banana")->first();
     $org4 = Organization::where('org_name', "Brown Banana")->first();
     $org5 = Organization::where('org_name', "Green Banana")->first();
     $expected = ["success" => true, "pipedrive_format" => [["type" => "parent", "rel_owner_org_id" => ["name" => "Paradise Island", "id" => "1"], "rel_linked_org_id" => ["name" => "Banana tree", "id" => "2"], "add_time" => $org2->created_at->toDateTimeString(), "calculated_type" => "parent"], ["type" => "parent", "rel_owner_org_id" => ["name" => "Banana tree", "id" => "2"], "rel_linked_org_id" => ["name" => "Yellow Banana", "id" => "3"], "add_time" => $org3->created_at->toDateTimeString(), "calculated_type" => "daughter"], ["type" => "parent", "rel_owner_org_id" => ["name" => "Banana tree", "id" => "2"], "rel_linked_org_id" => ["name" => "Brown Banana", "id" => "4"], "add_time" => $org4->created_at->toDateTimeString(), "calculated_type" => "daughter"], ["type" => "parent", "rel_owner_org_id" => ["name" => "Banana tree", "id" => "2"], "rel_linked_org_id" => ["name" => "Green Banana", "id" => "5"], "add_time" => $org5->created_at->toDateTimeString(), "calculated_type" => "daughter"]]];
     $this->get("api/organizations/" . $org->id)->seeJsonEquals($expected);
     //making delete request
     $this->delete('api/organizations')->seeJson(["success" => true]);
 }
コード例 #2
0
ファイル: CityController.php プロジェクト: w1lliams/sh
 /**
  * Удаление города
  *
  * @param City $city
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Exception
  */
 public function delete(City $city)
 {
     if (Organization::where('city_id', $city->id)->exists()) {
         dd('Есть организации с таким городом');
     }
     $city->delete();
     return redirect()->route('admin::city');
 }
コード例 #3
0
ファイル: TypeController.php プロジェクト: w1lliams/sh
 /**
  * Удаление типа
  *
  * @param Type $type
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Exception
  */
 public function delete(Type $type)
 {
     if (Organization::where('type_id', $type->id)->exists()) {
         dd('Есть организации с таким типом');
     }
     $type->delete();
     return redirect()->route('admin::type');
 }
コード例 #4
0
ファイル: StatusController.php プロジェクト: w1lliams/sh
 /**
  * Удаление статуса
  *
  * @param Status $status
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Exception
  */
 public function delete(Status $status)
 {
     if (Organization::where('status_id', $status->id)->exists()) {
         dd('Есть организации с таким статусом');
     }
     $status->delete();
     return redirect()->route('admin::status');
 }
コード例 #5
0
ファイル: OpfController.php プロジェクト: w1lliams/sh
 /**
  * Удаление ОПФ
  *
  * @param Opf $opf
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Exception
  */
 public function delete(Opf $opf)
 {
     if (Organization::where('opf_id', $opf->id)->exists()) {
         dd('Есть организации с таким ОПФ');
     }
     $opf->delete();
     return redirect()->route('admin::opf');
 }
コード例 #6
0
ファイル: BulkImporter.php プロジェクト: jtoshmat/laravel
 protected static function updateDB($data)
 {
     foreach ($data as $title) {
         if ($title['STUDENT ID'] != '') {
             //creating or updating districts
             $DDBNNN = preg_split('/(?<=[0-9])(?=[a-z]+)/i', $title['DDBNNN']);
             $district = District::firstOrCreate(['code' => $DDBNNN[0], 'system_id' => 1]);
             $district->code = $DDBNNN[0];
             $district->system_id = 1;
             $district->title = 'District ' . $DDBNNN[0];
             $district->save();
             $organization = Organization::where(['code' => $DDBNNN[1]])->with(array('districts' => function ($query) use($district) {
                 $query->where('district_id', $district->id);
             }))->first();
             if (is_null($organization)) {
                 // TODO figure out if this can be replaced with a firstOrCreate;
                 $organization = new Organization();
             }
             $organization->code = $DDBNNN[1];
             $organization->title = $DDBNNN[1];
             $organization->save();
             if (!$organization->districts->contains($district->id)) {
                 $organization->districts()->attach($district->id);
             }
             $user = User::firstOrCreate(['student_id' => $title['STUDENT ID']]);
             $user->student_id = $title['STUDENT ID'];
             $user->first_name = $title['FIRST NAME'];
             $user->last_name = $title['LAST NAME'];
             $user->sex = $title['SEX'];
             $user->dob = $title['BIRTH DT'];
             $user->save();
         }
     }
     $notifier = new Notifier();
     $notifier->to = Auth::user()->email;
     $notifier->subject = "Your import is completed at " . date('m-d-Y h:i:s A');
     $notifier->template = "emails.import";
     $notifier->attachData(['user' => Auth::user()]);
     $notifier->send();
 }
コード例 #7
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request)
 {
     if ($organization = Organization::where('userId', Auth::user()->id)->first()) {
     } else {
         $organization = new Organization();
         $organization->userId = Auth::user()->id;
     }
     if ($request['brochure']) {
         $filepath = base_path() . "/public/uploads/" . $organization->brochure;
         is_file($filepath) ? file_exists($filepath) ? unlink($filepath) : " " : " ";
         $name = time() . "." . $request->file('brochure')->getClientOriginalExtension();
         $dest = base_path() . "/public/uploads";
         $request->file('brochure')->move($dest, $name);
         $organization->brochure = $name;
     }
     $organization->name = $request['name'];
     $organization->address = $request['address'];
     $organization->description = $request['description'];
     $organization->save();
     \Session::flash('success_message', 'Your record has been updated');
     return redirect('organization/edit');
 }
コード例 #8
0
 /**
  * @param $input
  * @param $organization
  * @throws GeneralException
  */
 private function checkOrganizationByEmail($input, $organization)
 {
     //Figure out if email is not the same
     if ($organization->email != $input['email']) {
         //Check to see if email exists
         if (Organization::where('email', '=', $input['email'])->first()) {
             throw new GeneralException('That email address belongs to a different organization.');
         }
     }
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Organization::where('organization_name', 'Organization One')->delete();
 }
コード例 #10
0
ファイル: ApiController.php プロジェクト: gfdeveloper/LCCB
 public function updateOrganization($id, Request $request)
 {
     $this->validate($request, ['name' => 'required|unique:organizations,name,' . $id]);
     Organization::where('id', $id)->update(['name' => $request->get('name')]);
     return "GTG";
 }
コード例 #11
0
 /**
  * Удаление организации
  * @param Organization $organization
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Exception
  */
 public function delete(Organization $organization)
 {
     // удаляем подразделения
     Organization::where('parent_id', $organization->id)->delete();
     // удаляем сотрудников
     Worker::where('organization_id', $organization->id)->delete();
     Snapshot::where('organization_id', $organization->id)->delete();
     // удаляем саму организацию
     $organization->delete();
     return redirect()->route('admin::organization');
 }
コード例 #12
0
ファイル: Controller.php プロジェクト: w1lliams/sh
 /**
  * Счетчики огранизаций и работников
  */
 protected function getCounters()
 {
     View::share('organizationCount', Organization::where('snapshot_id', '>', 0)->count());
     View::share('workersCount', Worker::count());
 }
コード例 #13
0
 /**
  * Get the organizations by id.
  *
  * @param string $id
  *
  * @return Collection
  */
 public function byId($id)
 {
     return Organization::where('id', $id)->first();
 }