$this->set('_serialize', ['softwares', 'pagination', 'paging']);
}
- public function initialize() {
+ protected function getAverageStatistics () {
+
+ $tableAverageStatistics = TableRegistry::get("statistics_averages");
+
+ $LastAverageStatistics = $tableAverageStatistics->find("all")->last();
+
+ return $LastAverageStatistics;
+
+ }
+
- parent::initialize();
+
- $this->loadComponent('Search.Prg', [
- // This is default config. You can modify "actions" as needed to make
- // the PRG component work only for specified methods.
- 'actions' => ['index', 'lookup']
- ]);
+ public function addReview($id=null){
- $this->paginate = [
- 'limit' => Configure::read('LIMIT'),
- 'order' => [
- 'Softwares.softwarename' => Configure::read('ORDER')
- ],
- 'contain' => ['Licenses', 'Reviews', 'Screenshots', 'Relationships', 'SoftwaresStatistics', 'RawMetricsSoftwares']
- ];
+ if ($id==null){
+ $software = $this->Softwares->get($this->request->data['software_id'], [
+ 'contain' => []
+ ]);
+ }else {
+ $software = $this->Softwares->get($id, [
+ 'contain' => []
+ ]);
+ }
+
+
+ $review = $this->Softwares->Reviews->newEntity();
+ if ($this->request->is('post') && !$this->request->is('json')) {
+ $review = $this->Softwares->Reviews->patchEntity($review, $this->request->data);
+ if ($this->Softwares->Reviews->save($review)) {
+ $this->Flash->success(__('The review has been saved.'));
+ return $this->redirect(['action' => 'index']);
+ } else {
+ debug ($review);
+ $this->Flash->error(__('The review could not be saved. Please, try again.'));
+ }
+ $isAuthorized = $this->Auth->isAuthorized($this->Auth->user()); // La j'encule une mouche !!!
+ $user = $this->Auth->user();
+ $this->set(compact('review','user', 'isAuthorized', 'software'));
+ $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
+ }else if ($this->request->is('post') && $this->request->is('json')) {
+ $review = $this->Softwares->Reviews->patchEntity($review, $this->request->data);
+ if ($this->Softwares->Reviews->save($review)) {
+ $message = "Success";
+
+ $isAuthorized = $this->Auth->isAuthorized($this->Auth->user());
+ $user = $this->Auth->user();
+ $this->set(compact('review','user', 'isAuthorized', 'software'));
+ $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
+ } else {
+ debug($review->errors());
+ $message = "Error";
+ }
+ $this->set([
+ 'message' => $message,
+ 'review' => $review,
+ '_serialize' => ['message', 'review','licenses']
+ ]);
+ }else{//Pour le template vant le post des données.
+
+ $isAuthorized = $this->Auth->isAuthorized($this->Auth->user());
+ $user = $this->Auth->user();
+ $this->set(compact('review','user', 'isAuthorized', 'software'));
+ $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
+ }
}
+
+
}