/var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin/DocumentsController.php (3649B)
paginate($this->Documents);
$this->set(compact('documents'));
}
/**
* downloadFile method
*/
public function viewFile($file_path)
{
$document = $this->loadModel('Documents')->find()
->where(['Documents.file_path' => $file_path])
->first();
if (!empty($document)) {
if (file_exists(ROOT . DS . $document->upload_dir)) {
$ext = pathinfo($document->file_path, PATHINFO_EXTENSION);
$response = $this->response->withFile(ROOT . DS . $document->upload_dir . $document->file_path, ['download' => false, 'name' => \Cake\Utility\Inflector::camelize($document->name) . '.' . $ext]);
return $response;
} else {
$this->Flash->error(__('Acest document nu a fost găsit. #121532'));
}
} else {
$this->Flash->error(__('Acest document nu a fost găsit. #121533'));
}
return $this->redirect($this->referer());
}
/**
* Add method
*/
public function upload($model, $foreignKey, $foreignUuid)
{
$this->autoRender = false;
//$causeUuid = $this->Documents->Causes->get($foreignKey);
$document = $this->Documents->newEmptyEntity();
if ($this->request->is('post')) {
$document = $this->Documents->patchEntity($document, $this->request->getData());
$document->foreign_key = $foreignKey;
$document->model = $model;
$document->foreign_uuid = $foreignUuid;
if ($this->Documents->save($document)) {
// $this->Flash->success(__('The cause doc has been saved.'));
// return $this->redirect(['prefix' => 'Admin', 'controller' => 'Causes', 'action' => 'editDocs', $causeUuid->uuid]);
}
// $this->Flash->error(__('The cause doc could not be saved. Please, try again.'));
// return $this->redirect(['prefix' => 'Admin', 'controller' => 'Causes', 'action' => 'editDocs', $causeUuid->uuid]);
}
die;
}
// TODO
/**
* Edit method
*/
// public function edit($id = null)
// {
// $causeDoc = $this->CauseDocs->get($id, [
// 'contain' => [],
// ]);
// if ($this->request->is(['patch', 'post', 'put'])) {
// $causeDoc = $this->CauseDocs->patchEntity($causeDoc, $this->request->getData());
// if ($this->CauseDocs->save($causeDoc)) {
// $this->Flash->success(__('The cause doc has been saved.'));
// return $this->redirect(['action' => 'index']);
// }
// $this->Flash->error(__('The cause doc could not be saved. Please, try again.'));
// }
// $this->set(compact('causeDoc'));
// }
/**
* Delete method
*/
public function delete($id = null, $causeUuid = null)
{
$this->request->allowMethod(['post', 'delete']);
$document = $this->Documents->get($id);
if ($this->Documents->delete($document)) {
$this->Flash->success(__('The document has been deleted.'));
} else {
$this->Flash->error(__('The document could not be deleted. Please, try again.'));
}
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Causes', 'action' => 'editDocs', $causeUuid]);
}
}