public static function updateGroups(Request $request) { $titles = $request::get('title'); $ids = $request::get('id'); $deleteId = $request::get('delete'); $newtitle = $request::get('newtitle'); $i = 0; if ($ids) { foreach ($ids as $id) { $group = Organization::find($id); $group->title = $titles[$i]; if (isset($deleteId[$i]) && $deleteId[$i] == $id) { $group->delete(); } else { $group->save(); } $i++; } } if ($newtitle) { $group = new Organization(); $group->title = $newtitle; $group->save(); } return true; }
/** * @param $id * @param bool $withRoles * @return mixed * @throws GeneralException */ public function findOrThrowException($id, $withRoles = false) { if ($withRoles) { $organization = Organization::with('roles')->withTrashed()->find($id); } else { $organization = Organization::find($id); } if (!is_null($organization)) { return $organization; } throw new GeneralException('That organization does not exist.'); }
public function show(Request $request, $id = 0) { $roles = $request->user()->roles; if ($id == 0 && !$roles->isEmpty()) { $id = $roles[0]->organization_id; } if ($roles->isEmpty()) { return redirect()->route('newOrganizationForm'); } $organization = Organization::find($id); return view('organizations.view', ['organization' => $organization, 'roles' => $roles]); }
public function update(Request $request, $id) { if (Gate::denies('adminOnly')) { abort(403); } $input = $request->all(); $organization = Organization::find($id); if ($organization) { $organization->update($input); } return $organization; }
public static function getRelationsByOrgId($org_id) { $target_org = Organization::find($org_id); if ($target_org == null) { return array('success' => false, 'error' => 'organization not found by ID ' . $org_id); } $result['success'] = true; $data = array(); $daughters = Relation::where('parent_org_id', $org_id)->get(); $parent = Relation::where('org_id', $org_id)->get()->first(); $parent_org = $parent == null ? $target_org : Organization::find($parent->parent_org_id); //is parent organization if ($parent != null) { $data[] = array('id' => $parent->relation_id, 'type' => $parent->type, 'calculated_type' => 'parent', 'parent_org' => array('id' => $parent_org->id, 'name' => $parent_org->name), 'daughter_org' => array('id' => $target_org->id, 'name' => $target_org->name)); } if ($daughters && count($daughters)) { foreach ($daughters as $key => $value) { $org = Organization::find($value->org_id); $data[] = array('id' => $value->relation_id, 'type' => $value->type, 'calculated_type' => 'daughter', 'parent_org' => array('id' => $parent_org->id, 'name' => $parent_org->name), 'daughter_org' => array('id' => $org->id, 'name' => $org->name)); } } $result['data'] = $data; return $result; }
protected function updateUser(Request $request) { $data = $request->input(); $user = User::findOrFail($data['id']); $role = Role::find($data["Roles"][0]["id"]); $organization = Organization::find($data["Organization"][0]["id"]); /* doesn't work yet $user->roles = $role; $user->organization = $organization; */ $user->name = $data["name"]; $user->email = $data["email"]; $user->save(); return json_encode(array('message' => 'ok', 'user' => $this->normalizeUsersData([$user]))); }
public function deleteOrganization($id) { $organization = Organization::find($id); $organization->delete(); return redirect("admin/organizations")->with("success", "Organizacija je obrisana."); }
public function getOrganization($id) { $organization = Organization::find($id); return $organization; }
/** * get the specified organization relations. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { if ($organization = Organization::find($id)) { $organization->load('daughters', 'parent'); $success = true; } else { $success = false; } if (isset($organization)) { //getting in pipedrive format: $pipedrive_format = []; //if organization has parent, on pipdrive it shows this org. + all prent's daughters (as sisters) //we just go through parent daughters if ($organization->parent) { foreach ($organization->parent->daughters as $daughter) { $pipedrive_format[] = ['type' => 'parent', 'rel_owner_org_id' => ['name' => $organization->parent->org_name, 'id' => $organization->parent->id], 'rel_linked_org_id' => ['name' => $daughter->org_name, 'id' => $daughter->id], 'add_time' => $daughter->created_at->toDateTimeString(), 'calculated_type' => $daughter->id == $organization->id ? 'parent' : 'sister']; } } //and we add this org.'s daughters foreach ($organization->daughters as $daughter) { $pipedrive_format[] = ['type' => 'parent', 'rel_owner_org_id' => ['name' => $organization->org_name, 'id' => $organization->id], 'rel_linked_org_id' => ['name' => $daughter->org_name, 'id' => $daughter->id], 'add_time' => $daughter->created_at->toDateTimeString(), 'calculated_type' => 'daughter']; } } //return Response::json(compact('organization', 'success', 'pipedrive_format')); return Response::json(compact('success', 'pipedrive_format')); }