/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Document::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Upload New File and attach it to a document * * @param Int $document * @param Request $request * @return Response */ public function postFileToDocument($document, Request $request) { if (!$this->appKeyAvailable($request)) { return $this->notAuthorized($request); } $upload = array('file' => $request->file('file')); $rules = array('file' => 'required'); $validator = Validator::make($upload, $rules); if (!empty($document) && !$this->isDocument($document)) { $this->setResultError("Document not found", 404); } elseif ($validator->fails()) { $this->setResultError($validator->messages(), 400); } elseif (!$this->setSessionUser($request)) { $this->setResultError("Not logged in", 401); } elseif ($document !== null && Document::find($document)->user_id != $this->user->id && !$this->isModerator()) { $this->setResultError("Unauthorized action", 403); } else { if ($request->file('file')->isValid()) { $destinationPath = '../uploads'; $extension = Input::file('file')->getClientOriginalExtension(); $fileName = uniqid() . '.' . $extension; $file = new File(); $file->user_id = $this->user->id; $file->document_id = $document; $file->name = Input::file('file')->getClientOriginalName(); $file->mime = Input::file('file')->getMimeType(); $file->size = Input::file('file')->getSize(); $file->path = $destinationPath . '/' . $fileName; Input::file('file')->move($destinationPath, $fileName); $file->save(); $this->setAllowed(null, $file->id, $this->user->id, null, 'all'); $this->setResultOk(); $this->setFileData($file); } else { $this->setResultError('File is not valid', 400); } } return $this->setResponse(); }
/** * Revoke Permission on a Document for a Group * * @param String $name * @param Int $id * @param String $access * @param Int $group * @param Request $request * @return Response */ public function deleteGroupPermission($name, $id, $access, $group, Request $request) { if (!$this->appKeyAvailable($request)) { return $this->notAuthorized($request); } if (!$this->setSessionUser($request)) { $this->setResultError("Not logged in", 401); } elseif (!$this->isCollection($name)) { $this->setResultError("Collection '{$name}' doesn't exist", 401); } elseif (!in_array($access, ['read', 'update', 'delete', 'all'])) { $this->setResultError("Unknown permission '{$access}'", 400); } else { $document = Document::find($id); if (!$document) { $this->setResultError("Document is not found", 404); } elseif (!$this->isAllowed($request, 'document', $id, 'update') && !$this->isModerator()) { $this->setResultError("Unauthorized action", 403); } else { $this->setUnAllowed($id, null, null, $group, $access); $this->setResultOk(); } } return $this->setResponse(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $item = \App\Models\Item::find($id); $document = \App\Models\Document::find($item->document_id); $type = $document->os_type; switch ($type) { case 'movables' || 'value_movables': $variable = \App\Models\Item::find($id)->variable(); return View::make('item.edit', array('item' => $item, 'document' => $document, 'variable' => $variable)); break; case 'car': $variable = \App\Models\Item::find($id)->variable(); $car = \App\Models\Car::find($id)->car(); return View::make('item.edit', array('item' => $item, 'document' => $document, 'variable' => $variable, 'car' => $car)); break; case 'buildings': $variable = \App\Models\Item::find($id)->variable(); $building = \App\Models\Item::find($id)->building(); $address = \App\Models\Address::find($id)->address(); return View::make('item.edit', array('item' => $item, 'document' => $document, 'building' => $building, 'variable' => $variable, 'address' => $address)); break; case 'parcels': $parcel = \App\Models\Item::find($id)->parcel(); $address = \App\Models\Address::find($id)->address(); return View::make('item.edit', array('item' => $item, 'document' => $document, 'parcel' => $parcel, 'address' => $address)); break; } }
public function postImport($id) { $document = \App\Models\Document::find($id); $type = $document->os_type; if (Input::hasFile('file')) { $file = Input::file('file'); $filename = $file->getClientOriginalName(); $destinationPath = public_path() . '/uploads/'; Input::file('file')->move($destinationPath, $filename); $handle = fopen(public_path() . '/uploads/' . $filename, "r"); if ($handle !== FALSE) { if ($type == 'movables' || $type == 'value_movables') { while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) { $item = new \App\Models\Item(); $name = iconv("Windows-1251", "utf-8", $data[0]); $item->name = $name; $item->number = $data[1]; $os_date = date("Y-m-d", strtotime($data[2])); $item->os_date = $os_date; $okof = $data[5]; $okof = str_replace(" ", "", $okof); $item->okof = $okof; $carrying_amount = $data[6]; $carrying_amount = str_replace(",", ".", $carrying_amount); $carrying_amount = str_replace(" ", "", $carrying_amount); $item->carrying_amount = $carrying_amount; $item->financing_source = 1; $item->document_id = $id; $item->save(); $variable = new \App\Models\Variable(); $exploitation_date = date("Y-m-d", strtotime($data[3])); $variable->exploitation_date = $exploitation_date; $residual_value = $data[8]; $residual_value = str_replace(",", ".", $residual_value); $residual_value = str_replace(" ", "", $residual_value); $variable->residual_value = $residual_value; $monthly_rate = $data[10]; $monthly_rate = str_replace(",", ".", $monthly_rate); $variable->monthly_rate = $monthly_rate; $variable->useful_life = $data[11]; $item->variable()->save($variable); } } if ($type == 'car') { while (($data = fgetcsv($handle, 2000, ';')) !== FALSE) { $item = new \App\Models\Item(); $name = iconv("Windows-1251", "utf-8", $data[0]); $item->name = $name; $item->number = $data[1]; $os_date = date("Y-m-d", strtotime($data[2])); $item->os_date = $os_date; $okof = $data[5]; $okof = str_replace(" ", "", $okof); $item->okof = $okof; $carrying_amount = $data[6]; $carrying_amount = str_replace(",", ".", $carrying_amount); $carrying_amount = str_replace(" ", "", $carrying_amount); $item->carrying_amount = $carrying_amount; $item->financing_source = 1; $item->document_id = $id; $item->save(); $variable = new \App\Models\Variable(); $exploitation_date = date("Y-m-d", strtotime($data[3])); $variable->exploitation_date = $exploitation_date; $residual_value = $data[8]; $residual_value = str_replace(",", ".", $residual_value); $residual_value = str_replace(" ", "", $residual_value); $variable->residual_value = $residual_value; $monthly_rate = $data[10]; $monthly_rate = str_replace(",", ".", $monthly_rate); $variable->monthly_rate = $monthly_rate; $variable->useful_life = $data[11]; $item->variable()->save($variable); $car = new \App\Models\Car(); $car->brand = $data[12]; $car->model = $data[13]; $manufacture_year = date("Y-m-d", strtotime($data[14])); $car->manufacture_year = $manufacture_year; $vin = $data[15]; $vin = str_replace('"', '', $vin); $car->vin = $vin; $car->kpp = $data[16]; $car->engine = $data[17]; $car->power = $data[18]; if (isset($data[19])) { $car->color = $data[19]; } $item->car()->save($car); } } if ($type == 'buildings') { while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) { $item = new \App\Models\Item(); $name = iconv("Windows-1251", "utf-8", $data[0]); $item->name = $name; $item->number = $data[1]; $os_date = date("Y-m-d", strtotime($data[2])); $item->os_date = $os_date; $okof = $data[5]; $okof = str_replace(" ", "", $okof); $item->okof = $okof; $carrying_amount = $data[6]; $carrying_amount = str_replace(",", ".", $carrying_amount); $carrying_amount = str_replace(" ", "", $carrying_amount); $item->carrying_amount = $carrying_amount; $item->financing_source = 1; $item->document_id = $id; $item->save(); $variable = new \App\Models\Variable(); $exploitation_date = date("Y-m-d", strtotime($data[3])); $variable->exploitation_date = $exploitation_date; $residual_value = $data[8]; $residual_value = str_replace(",", ".", $residual_value); $residual_value = str_replace(" ", "", $residual_value); $variable->residual_value = $residual_value; $monthly_rate = $data[10]; $monthly_rate = str_replace(",", ".", $monthly_rate); $monthly_rate = str_replace(" ", "", $monthly_rate); $variable->monthly_rate = $monthly_rate; $variable->useful_life = $data[11]; $item->variable()->save($variable); $building = new \App\Models\Building(); $appointment = iconv("Windows-1251", "utf-8", $data[12]); $building->appointment = $appointment; $wall_material = iconv("Windows-1251", "utf-8", $data[13]); $building->wall_material = $wall_material; $date_construction = date("Y-m-d", strtotime($data[14])); $building->date_construction = $date_construction; $building->floors = $data[15]; $item->building()->save($building); $address = new \App\Models\Address(); $state = iconv("Windows-1251", "utf-8", $data[16]); $address->state = $state; $item->address()->save($address); } } if ($type == 'parcels') { while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) { $item = new \App\Models\Item(); $name = iconv("Windows-1251", "utf-8", $data[0]); $item->name = $name; $item->number = $data[1]; $os_date = date("Y-m-d", strtotime($data[2])); $item->os_date = $os_date; $carrying_amount = $data[3]; $carrying_amount = str_replace(",", ".", $carrying_amount); $carrying_amount = str_replace(" ", "", $carrying_amount); $item->carrying_amount = $carrying_amount; $item->financing_source = 1; $item->document_id = $id; $item->save(); $parcel = new \App\Models\Parcel(); $parcel->cadastral = $data[5]; $assigning_land = iconv("Windows-1251", "utf-8", $data[6]); $parcel->assigning_land = $assigning_land; $parcel->area = $data[7]; $item->parcel()->save($parcel); $address = new \App\Models\Address(); $state = iconv("Windows-1251", "utf-8", $data[8]); $address->state = $state; $state = iconv("Windows-1251", "utf-8", $data[8]); $item->address()->save($address); } } fclose($handle); } } return redirect()->back(); }
public function showServiceAgreementWithClient($id) { $serviceAgreement = Document::find($id); $file = $serviceAgreement->file_name; $extension = explode('.', $file); $extension = strtolower(end($extension)); $contentType = 'application/pdf'; if ($extension != 'pdf') { $contentType = 'image/' . $extension; } $shortFileName = explode('/', $file); $shortFileName = end($shortFileName); return Response::make(file_get_contents($file), 200, ['Content-Type' => $contentType, 'Content-Disposition' => 'inline; ' . $shortFileName]); }
/** * return document by id * @param $id * @return static */ public function getDocumentById($id) { return $this->document->find($id); }