+++ /dev/null
-<?php
- class ChangelogsController extends AppController {
- public $helpers = array('Html', 'Form');
- public $components = array('RequestHandler');
-
- public function index() {
- $changelogs = $this->Changelog->find('all');
- $this->set(array(
- 'changelogs' => $changelogs,
- '_serialize' => array('changelogs')
- ));
- }
-
- public function view($id = null) {
- if (!$id) {
- throw new NotFoundException(__('Mauvais historique'));
- }
-
- $changelog = $this->Changelog->findById($id);
- if (!$changelog) {
- throw new NotFoundException(__('Mauvais historique'));
- }
- $this->set('changelog', $changelog);
- }
-
- public function add() {
- if ($this->request->is('changelog')) {
- $this->Changelog->create();
- if ($this->Changelog->save($this->request->data)) {
- $this->Session->setFlash(__("L'historique a été enregistré."));
-
- // REDIRECTION TO APPLIANCES PAGE
- $this->redirect(array('controller' => 'appliances', 'action' => 'index'));
- }
- $this->Session->setFlash(__("Enregistrement de l'historique impossible."));
- }
- }
-
- public function edit($id = null) {
- if (!$id) {
- throw new NotFoundException(__('Historique introuvable'));
- }
-
- // GETTING THE CHANGELOG OF THE APPLIANCE
- $this->Changelog->id = $id;
- $changelog = $this->Changelog->findById($id);
- if (!$changelog) {
- throw new NotFoundException(__('Historique introuvable'));
- }
- $this->set('changelog', $changelog);
-
- // GETTING ALL WARNINGS FROM THE CHANGELOG
- if($this->Changelog->value('warnings')) {
- $warnings_id = explode('|', $this->Changelog->value('warnings'));
- App::import('Controller', 'Warnings');
- $warningsController = new WarningsController;
- $warnings = array();
- foreach ($warnings_id as $warning_id) {
- $warnings[] = $warningsController->Warning->findById($warning_id);
- }
-
- // SENDING DATA TO VIEW
- $this->set(array(
- 'warnings' => $warnings,
- '_serialize' => array('warnings')
- ));
- }
-
- if ($this->request->is(array('changelog', 'put'))) {
- $this->Changelog->id = $id;
- if ($this->Changelog->save($this->request->data)) {
- $this->Session->setFlash(__("L'historique a été mis à jour."));
-
- // REDIRECTION TO APPLIANCES PAGE
- $this->redirect(array('controller' => 'appliances', 'action' => 'index'));
- }
- $this->Session->setFlash(__("Mise à jour de l'historique impossible."));
- }
-
- if (!$this->request->data) {
- $this->request->data = $changelog;
- }
- }
-
- public function delete($id) {
-
- // DISABLE GET ACCESS ?
- /*if ($this->request->is('get')) {
- throw new MethodNotAllowedException();
- }
- */
- if ($this->Changelog->delete($id)) {
- $this->Session->setFlash(
- __("L'historique d'id: %s a été supprimé.", h($id))
- );
-
- // REDIRECTION TO APPLIANCES PAGE
- $this->redirect(array('controller' => 'appliances', 'action' => 'index'));
- }
- }
-
- public function acknowledgeWarning($id = null, $warning_id = null, $validate = false, $escapedApplianceReference = null) {
-
- // GETTING CHANGELOG
- $this->Changelog->id = $id;
- $changelog = $this->Changelog->findById($id);
- if (!$changelog) {
- throw new NotFoundException(__('Historique introuvable'));
- }
-
- // GETTING WARNINGS OF CHANGELOG
- App::import('Controller', 'Warnings');
- $warningsController = new WarningsController;
- $warning = $warningsController->Warning->findById($warning_id);
- if (!$warning) {
- throw new NotFoundException(__('Alerte introuvable'));
- }
-
- // ADDING VERSION AND DATE OF WARNING TO CHANGELOG IF NATURE OF WARNING IS EITHER CREATION OR VERSION
- $version_id = $warning['Warning']['version'];
- $version_date = $warning['Warning']['creation'];
- if(in_array($warning['Warning']['nature'], array('version', 'creation'))) {
- $versions_id = array();
- if($this->Changelog->value('versions')) {
- $versions_id = explode('|', $this->Changelog->value('versions'));
- }
- $versions_id[] = $version_id.";".$version_date;
- $this->Changelog->value('versions', implode('|', $versions_id));
- }
-
- // IN CASE OF VALIDATION => OPPORTUNITY CREATION IN SUGAR THROUGH ALLO SERVEUR CONNECTOR
- if($validate) {
- $applianceReference = str_replace("SLASH", "\\/", $escapedApplianceReference);
- $url = 'http://allo_serveur/?action=create_opportunity&appliance_reference='.$applianceReference."&version_id=".$version_id."&version_declaration=".$version_date;
- $options = array("http" => array("method" => "GET"));
- $context = stream_context_create($options);
- $response = file_get_contents($url, false, $context);
- if(isset($response)) {
- // USE THE ID SENT ?
- }
- }
-
- // DELETING WARNING
- $warningsController->Warning->delete($warning_id);
- $warnings_id = explode('|', $this->Changelog->value('warnings'));
- if(($key = array_search($warning_id, $warnings_id)) !== false) {
- unset($warnings_id[$key]);
- }
- $this->Changelog->value('warnings', implode('|', $warnings_id));
- $this->Changelog->save();
-
- // REDIRECTION TO APPLIANCES PAGE
- $this->redirect(array('controller' => 'appliances', 'action' => 'index'));
- }
- }