Commit 4cd1dbde authored by Pastor Mickaël's avatar Pastor Mickaël
Browse files

Related to #323 => Form structure for add a review...

Related to #323 => Form structure for add a review reviews/add.ctp and improve routing
parent 58b91dd2
......@@ -98,6 +98,7 @@ Router::prefix('api/v1', function ($routes) {
$routes->resources('Screenshots');
});
$routes->connect('/softwares/add-review/:software_id', ['controller' => 'Reviews', 'action' => 'add',"pass"=>["software_id"]]);
// $routes->connect('/softwares/lastAdded', ['controller' => 'Softwares', 'action' => 'lastAdded']);
// $routes->connect('/softwares/getProjectsById', ['controller' => 'Softwares', 'action' => 'getProjectsById']);
......
......@@ -83,33 +83,38 @@ class ReviewsController extends AppController
*/
public function add()
{
$this->request->allowMethod(['post']);
$this->request->allowMethod(['post','get']);
try {
$software = $this->Reviews->Softwares->get($this->request->params['software_id']);
$this->request->data['software_id'] = $software->id;
}
catch (\Exception $e) {
throw new \App\Network\Exception\SoftwareNotFoundException("The software with the id ". $this->request->params['software_id']. " does not exist");
}
$review = $this->Reviews->newEntity();
$message = "";
if ($this->request->is('post')) {
try {
$software = $this->Reviews->Softwares->get($this->request->params['software_id']);
$this->request->data['software_id'] = $software->id;
} catch (\Exception $e) {
throw new \App\Network\Exception\SoftwareNotFoundException("The software with the id " . $this->request->params['software_id'] . " does not exist");
}
try {
$user = $this->Reviews->Users->get($this->Auth->user('id'));
$this->request->data['user_id'] = $user->id;
}
catch (\Exception $e) {
throw new \App\Network\Exception\UserNotFoundException("The user with the id ". $this->Auth->user('id') . " does not exist");
}
try {
$user = $this->Reviews->Users->get($this->Auth->user('id'));
$this->request->data['user_id'] = $user->id;
} catch (\Exception $e) {
throw new \App\Network\Exception\UserNotFoundException("The user with the id " . $this->Auth->user('id') . " does not exist");
}
$review = $this->Reviews->newEntity();
$review = $this->Reviews->patchEntity($review, $this->request->data);
$review = $this->Reviews->patchEntity($review, $this->request->data);
if ($this->Reviews->save($review)) {
$message = "Success";
} else {
$message = "Error";
$review = $review->errors();
if ($this->Reviews->save($review)) {
$message = "Success";
if ( !$this->request->is('json') ){
$this->Flash->success(__d("Forms","Your review has been posted"));
$this->redirect(["controller"=>"Softwares","action"=>"view","language"=>$this->request->param("language"),$this->request->data['software_id']]);
}
} else {
$message = "Error";
}
}
$this->set([
'message' => $message,
......
<nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
<li><?= $this->Html->link(__('List Reviews'), ['action' => 'index']) ?></li>
<li><?= $this->Html->link(__('List Users'), ['controller' => 'Users', 'action' => 'index']) ?></li>
<li><?= $this->Html->link(__('New User'), ['controller' => 'Users', 'action' => 'add']) ?></li>
<li><?= $this->Html->link(__('List Softwares'), ['controller' => 'Softwares', 'action' => 'index']) ?></li>
<li><?= $this->Html->link(__('New Software'), ['controller' => 'Softwares', 'action' => 'add']) ?></li>
</ul>
</nav>
<div class="reviews form large-9 medium-8 columns content">
<?= $this->Form->create($review) ?>
<fieldset>
<legend><?= __('Add Review') ?></legend>
<?php
echo $this->Form->input('comment');
echo $this->Form->input('title');
echo $this->Form->input('user_id', ['options' => $users, 'empty' => true]);
echo $this->Form->input('software_id', ['options' => $softwares, 'empty' => true]);
echo $this->Form->input('evaluation');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
<?php
$this->layout("base");
$this->assign('title', __d("Forms",'Add a review{0}', isset($message) ? " - ".$message : ""));
?>
<div class="row">
<div class = "warning-form bg-warning col-xs-offset-3 col-xs-6">
<?= __d("Forms","Fields marked with an asterisk ({0}) are required.",'<span class = "asterisk">*</span>'); ?>
</div>
</div>
<div class="row">
<div class="reviews form col-xs-offset-3 col-xs-6 columns content">
<?= $this->Form->create($review,["enctype"=>"multipart/form-data"]) ?>
<fieldset>
<legend><?= __d("Forms",'Add Review') ?></legend>
<?= $this->Form->input(
'title',
[
'label'=>["class"=>"control-label","text"=>__d("Forms"," {0} Title: ", '<span class = "asterisk">*</span>')],
"class"=>"form-control",
"required"=>"required",
"escape"=>false,
]); ?>
<?= $this->Form->input("comment",
[
'label'=>["class"=>"control-label","text"=>__d("Forms"," {0} Comment: ", '<span class = "asterisk">*</span>')],
"class"=>"form-control",
"required"=>"required",
"type"=>"textarea",
"escape"=>false,
]); ?>
<label class = "control-label" for="evaluation"><?= __d("Forms"," {0} Evaluation: ", '<span class = "asterisk">*</span>')?></label>
<select name = "evaluation" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<div class='form-group'>
<?= $this->Form->input('software_id',
[
'value' => isset($softwareId) ? $softwareId : null,
'empty' => true,
"type"=>"hidden",
"required"=>"required",
"escape"=>false,
]);?>
</div>
</fieldset>
<?= $this->Form->button(__d("Forms",'Submit'),["class"=>"btn btn-default addmore"]) ?>
<?= $this->Form->end() ?>
</div>
</div>
<div class="reviews form large-9 medium-8 columns content">
<?= $this->Form->create(null,["enctype"=>"multipart/form-data",'url' => ['controller' => 'Softwares', 'action' => 'addReview']]) ?>
<fieldset>
<legend><?= __('Add Review') ?></legend>
<?php
echo $this->Form->input(__('title'),['label'=>'Title : ']);
echo $this->Form->input(__('comment'),['label'=>'Comment : ']);
echo $this->Form->input(__('evaluation'),['label'=>'Evalutation : ']);
echo $this->Form->input('user_id', ['value'=>$user['id'], 'empty' => true,"type"=>"hidden"]);
echo $this->Form->input('software_id', ['value' => $software->id, 'empty' => true,"type"=>"hidden"]);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment