Vous êtes sur la page 1sur 6

<?

php
require_once APP_ROOT . '/application/config/table/Clienttemplate.php';
require_once APP_ROOT . '/application/config/table/Administrationtemplate.php';
class Clients_AdresselivraisonController extends App_Crud_Controller_ActionAbstr
act {
protected $_validatorRules = array(
'term' => 'Alnum', // Validation du terme envoy pour l'action 'autocomplet
ecpville' de l'autocompletion
);
protected $_title = "adresses de livraison";
protected $_autoLeftMenu = false;
protected $_modelClass = 'Clients_Model_Adresselivraison';
//protected $_formClass = 'Clients_Form_Adresselivraison';
protected $_subTitle = array (
'liste' => 'Liste des clients',
'creer' => 'Cration',
'editer' => 'Modification',
'voir' => 'Visualisation',
);
/**
* @todo information_string
*/
public function autocompletecpvilleAction()
{
$data = array ();
//$term = $this->_getParam('term', '');
$term = $this->getRequest()->getParam('term');
$searchtype = $this->getRequest()->getParam('searchtype');
//param page is set from Client page,
//if null array($label => $value) else array($label => $label)
$isPage = $this->getRequest()->getParam('page');
$model = new Clients_Model_Autocompletion();
$list = $model->getCPVilleList($term, $searchtype);
if ( $isPage == null ) {
foreach ($list as $value => $label) {
// if page null : array($label => $value)
$data[] = array (
'label' => $label,
'value' => $value,
);
}
} else {
foreach ($list as $value => $label) {
// if page not null : array($label => $label)
$data[] = array (
'label' => $label,
'value' => $label,
);
}
}

$this->json($data);
}
public function creerAction() {
try {
$form = $this->getForm();
$form->adjustForm(true);
$entity = $this->getModelEntity(null);
$form->setDefaults($entity->toArray());
if ($this->isPost()) {
$taintedData = $this->getRequest()->getPost();
$typadresse = $this->getRequest()->getParam('typ
e');
$taintedData['type_adresse'] = $typadresse != nu
ll ? $typadresse : 'LIV';
if($taintedData['type_adresse'] == "LIVP" ){
$taintedData[CLIENT_ADRESSELIVRAISON_CHA
MP_NR_ADRESSE] = $this->getModel()->buildAndVerifyNRAdresse();
}
$taintedData[CLIENT_ADRESSELIVRAISON_CHAMP_ETAT_
ADRESSE] = 'ACTI';
$form->isValid($taintedData);
//Get data form
$data = $form->getValues();
//les clients crs via l'interface sont valide
$data[CLIENT_ADRESSELIVRAISON_CHAMP_VALIDE_CP] =
1;
// Supprime les valeurs vides lors de l'insertio
n pour qu'elles soient gres comme des NULL
$columnsOptions = $this->getColumnsOptions();
foreach ($columnsOptions as $columnName => $colu
mnsOptions) {
if (array_key_exists($columnName, $data)
&& $data[$columnName] === '') {
unset ($data[$columnName]);
}
}
$request = $this->getRequest();
echo "sdf";
echo $request->getParam('id_client');
exit;
$model = new Clients_Model_Adresselivraison();
$model->saveAdresseLIVP($data,$this->getRequest
()->getParam('id_client'));
//

$this->saveModelEntity($data)

//
if (isset ($_SESSION['ID_LIVP'])) {
//
$_SESSION['ID_LIVP']++;
//
$data[CLIENT_ADRESSELIVRAISON_CHAMP_ID_A
DRESSE] = $_SESSION['ID_LIVP'];
//
$_SESSION['ADRESSE_LIVP'][$_SESSION['ID_
LIVP']] = $data;

//
} else {
//
$_SESSION['ID_LIVP'] = 0;
//
$data[CLIENT_ADRESSELIVRAISON_CHAMP_ID_A
DRESSE] = $_SESSION['ID_LIVP'];
//
$_SESSION['ADRESSE_LIVP'][$_SESSION['ID_
LIVP']] = $data;
//
}
}
} catch (Exception $e) {
$this->addMessage('Cration impossible', self :: STATUS_ERR
);
$this->addMessage('Cration impossible : ' . $e->getMessage
(), self :: STATUS_DEBUG);
}
$this->renderForm($form);
}
public function editerAction()
{
// Allow general purpose hasAccessTo
$this->disableRendering();
if (!$this->hasAccessTo('editer')) {
$this->redirector($this->_defaultAction);
return;
}
$id = $this->_getParam('id', null);
if ($id === null) {
throw new Oft_Exception("Paramtre 'id' invalide");
}
try {
$form = $this->getForm();
if ( $this->isPost() ) {
$model = new Clients_Model_Adresselivraison();
$taintedData = $this->getRequest()->getPost();
$typadresse = $this->getRequest()->getParam('typ
e');
$taintedData['type_adresse'] = $typadresse != nu
ll ? $typadresse : 'LIV';
if ( $taintedData['type_adresse'] == "LIVP" ) {
//conserver le mm nradresse lors de la m
odification
if ( isset($_SESSION['ADRESSE_LIVP'][$id
][CLIENT_ADRESSELIVRAISON_CHAMP_NR_ADRESSE]) ) {
$nradresse = $_SESSION['ADRESSE_
LIVP'][$id][CLIENT_ADRESSELIVRAISON_CHAMP_NR_ADRESSE];
$taintedData[CLIENT_ADRESSELIVRA
ISON_CHAMP_NR_ADRESSE] = $nradresse;
}
}
$form->isValid($taintedData);
$data = $form->getValues();
//les clients modifis via l'interface sont valide
$data[CLIENT_ADRESSELIVRAISON_CHAMP_VALIDE_CP] =
1;

var_dump($data);exit;
$model = new Clients_Model_Adresselivraison();
$model->saveOrUpdateAdresse(null,$data);
//
//
//
DRESSE] = $id;
//
//
//
//
alide");
//

if ( $_SESSION['ADRESSE_LIVP'][$id] ) {
$data[CLIENT_ADRESSELIVRAISON_CHAMP_ID_A
$_SESSION['ADRESSE_LIVP'][$id] = $data;
} else {
throw new Oft_Exception("Paramtre 'id' inv
}
}
} catch (Exception $e) {
$this->addMessage('Edition impossible', self :: STATUS_E

RR);
$this->addMessage('Edition impossible : ' . $e->getMessa
ge(), self :: STATUS_DEBUG);
}
}
public function getcolumnOptionsArbitrage()
{
//$modelclients = new Clients_Model_Clients();
return $this->getModel()->_columnOptionsArbitrage;
}
public function getIteratorsInvalideCP($options)
{
$modelAL = new Clients_Model_Arbitrages();
return $modelAL->getSelect($options);
}
/**
* @todo information_string
*/
public function getIteratorsCPVILLE()
{
$modelAL = new Clients_Model_Autocompletion();
return $modelAL->_getIterator();
}
/**
* rcuperer les donnes pour la liste d'arbitrage
*/
public function gdataAction()
{
$this->disableRendering();
$idColumn
= CLIENT_ADRESSELIVRAISON_CHAMP_ID_ADRESSE;
$modelAL
= new Clients_Model_Arbitrages();
$columnsOptions = $modelAL->getColumnsOptions();
$options
= $this->getGridOptions();
//$iterator
= $this->getIteratorsInvalideCP($this->getIterat
orOptions());
$iterator
= $this->getIteratorsInvalideCP($this->getIterat
orOptions());

$vh = $this->getViewHelper();
echo Zend_Json::encode($vh->getAjaxData($idColumn, $iterator, $columnsOp
tions, $options), false, array('enableJsonExprFinder' => true));
}
/**
* recuperer les donnes pour la liste des adresses ponctuelles
*/
public function getDataAction()
{
$this->disableRendering();
$idColumn
= $this->getIdColumn();
$columnsOptions = $this->getAddColumnsOptions(); //getAddColumnsOptions(
);
$options

= $this->getGridOptions();

$request = $this->getRequest(); //$this should refer to a controller


// Rcupration des donnes
$iterator = $this->getModel()->getIteratorAdresse($this->getIteratorOpti
ons(),$request->getParam('id_client'));
$vh = $this->getViewHelper();
echo Zend_Json::encode($vh->getAjaxData($idColumn, $iterator, $columnsOp
tions, $options), false, array('enableJsonExprFinder' => true));
}
public function getAddColumnsOptions()
{
return $this->getModel()->getColumnsOptionsAdd();
}
public function gdataautocompletionAction()
{
$this->disableRendering();
$idColumn
= CLIENT_VILLE_CODE_POSTAL_CHAMP_ID;
$modelAL
= new Clients_Model_Autocompletion();
$columnsOptions = $modelAL->getColumnsOptions();
$options
= $this->getGridOptions();
$iterator
= $this->getIteratorsCPVILLE($this->getIteratorO
ptions());
$vh = $this->getViewHelper();
echo Zend_Json::encode($vh->getAjaxData($idColumn, $iterator, $columnsOp
tions, $options),
false, array('enableJson
ExprFinder' => true));
}
/**
* @todo mise jour des donnes
*/
public function updatedataAction()
{
/**

* pdv_nom=qsd&code_postal=222246&ville=qsqs&oper=edit&id=35
*/
$this->disableRendering();
$id = $_POST['id'];
$cp_ville = $_POST['cp-ville'];
$ville_cp = $_POST['ville-cp'];
$row = $this->getModel()->getEntity($id);
if ($row===null) {
throw new Oft_TechException("Enregistrement non trouv");
}
$row->code_postal = $cp_ville;
$row->ville = $ville_cp;
if (!$row->save()) {
throw new Oft_Exception("Impossible de sauver les donnes");
}
}
}
?>

Vous aimerez peut-être aussi