enrichissement/application/controllers/ProfilController.php
2012-04-06 13:11:46 +00:00

126 lines
3.0 KiB
PHP

<?php
class ProfilController extends Zend_Controller_Action
{
public function indexAction()
{
$db = Zend_Registry::get('db');
$profilM = new Application_Model_Profil($db);
$sql = $profilM->select()->order('reference ASC');
$rows = $profilM->fetchAll($sql);
$this->view->assign('profils', $rows);
}
public function detailAction()
{
$request = $this->getRequest();
$id = $request->getParam('id', null);
require_once 'Scores/Enrichissement.php';
$data = new Enrichissement();
if ( $id != null ) {
$profilM = new Application_Model_Profil();
$profil = $profilM->find($id);
$criteres = json_decode($profil->current()->criteres, true);
$tmp = array();
foreach ($criteres as $critere) {
$tmp[] = $data->getDicoLib($critere);
}
$this->view->assign('profil', $tmp);
$this->view->assign('reference', $profil->current()->reference);
}
}
public function createAction()
{
$request = $this->getRequest();
$id = $request->getParam('id', null);
require_once 'Scores/Enrichissement.php';
$data = new Enrichissement();
if ( $id != null ) {
$profilM = new Application_Model_Profil();
$profil = $profilM->find($id);
$criteres = json_decode($profil->current()->criteres, true);
$tmp = array();
foreach ($criteres as $critere) {
$values = false;
if (preg_match('/(.*)\((.*)\)/', $critere, $matches))
{
$values = $matches[2];
}
$tmp[$critere] = array(
'lib' => $data->getDicoLib($critere),
'values' => $values,
);
}
$this->view->assign('criteres', $tmp);
$this->view->assign('reference', $profil->current()->reference);
}
$this->view->assign('id', $id);
$this->view->assign('edit', true);
$this->view->assign('elements', $data->getDico());
}
public function saveAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$reference = $request->getParam('reference');
$criteres = $request->getParam('criteres');
$db = Zend_Registry::get('db');
$profilM = new Application_Model_Profil($db);
$data = array(
'reference' => $reference,
'criteres' => json_encode($criteres),
);
$id = $request->getParam('id', null);
if ( $id != null ) {
if ( $profilM->update($data, 'id='.$id) ){
echo '';
} else {
echo 'Erreur';
}
} else {
if ( $profilM->insert($data) ){
echo '';
} else {
echo 'Erreur';
}
}
}
public function setAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$idprofil = $request->getParam('idprofil');
$idfile = $request->getParam('idfile');
$db = Zend_Registry::get('db');
$commandesM = new Application_Model_Commandes($db);
$data = array(
'idProfil' => $idprofil,
);
if ( $commandesM->update($data, "id=$idfile") ){
echo '';
} else {
echo 'Erreur';
}
}
}