Merci pour votre aide
<?php
class Sofi_Form_Add_Lot_Lot extends Default_Form_DialogForm {
public function init() {
$this->setAttrib('id', 'add-lot');
$mr_id = new Zend_Form_Element_Select('mr_id', array(
'label' => 'Train',
'required' => true,
'validators' => array(
array('NotEmpty', true)
),
'decorators' => $this->getElementDecorators()
));
$apps = new Zend_Form_Element_Select('app_id', array(
'label' => 'Application',
'required' => true,
'validators' => array(
array('NotEmpty', true)
),
'decorators' => $this->getElementDecorators()
));
$version = new Zend_Form_Element_Text('version', array(
'label' => 'Version',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('NotEmpty', true),
array('StringLength', true, array('max' => 20))
),
'decorators' => $this->getElementDecorators(),
'style' => 'width: 200px',
'maxlength' => 20
));
$activation = new Zend_Form_Element_Text('activation', array(
'label' => 'Date d\'activation',
'required' => false,
'filters' => array('StringTrim'),
'validators' => array(
array('NotEmpty', true),
array('Date', true, array('format' => 'dd-MM-yyyy')),
),
'decorators' => $this->getElementDecorators(),
'maxlength' => 10,
'style' => 'width: 60px'
));
$cab = new Zend_Form_Element_Text('cab', array(
'label' => 'Info SNP',
'required' => false,
'filters' => array('StringTrim'),
'validators' => array(
array('NotEmpty', true),
array('StringLength', true, array('max' => 20
//'mr_id' => array('onselect' => 'this.disabled=true;return true')
))
),
'decorators' => $this->getElementDecorators(),
'style' => 'width: 200px',
'maxlength' => 20
));
$spa_id = new Zend_Form_Element_Select('statut', array(
'label' => 'Statut Itération',
'required' => true,
'validators' => array(
array('NotEmpty', true)
),
'decorators' => $this->getElementDecorators()
));
$model = new Zend_Form_Element_Checkbox('model', array(
'label' => 'Modèle',
'required' => true,
'validators' => array(
array('NotEmpty', true)
),
'decorators' => $this->getCheckboxDecorators()
));
$pat_id = new Zend_Form_Element_Hidden('pat_id', array(
'validators' => array(
array('Db_RecordExists', true, array('rmt_patch', 'pat_id', null, parent::$rmt_adapter))
),
'decorators' => $this->getElementDecorators()
));
$submit = new Zend_Form_Element_Submit('submit', array(
'label' => 'Ajouter',
'decorators' => $this->getSubmitDecorators()
));
// Initialiser le selectmenu des statuts lots
$spa_id->addMultiOption(null, null);
$spa_table = new Application_Model_Rmt_Statut_Patch();
foreach ($spa_table->fetchAllEnable() as $spa) {
$spa_id->addMultiOption($spa->spa_id, $spa->spa_nom);
}
// Initialiser le selectmenu des Trains
$mr_id->addMultiOption(null, null);
$mr_table = new Application_Model_Rmt_MetaRelease_MetaRelease();
$options = array();
$last_mrt_id = null;
foreach ($mr_table->fetchAllMRAndType(false) as $mr) {
if ($last_mrt_id != $mr->mrt_id) {
$options[$mr->mrt_nom] = array();
$last_mrt_id = $mr->mrt_id;
}
$options[$mr->mrt_nom][$mr->mr_id] = $mr->mr_nom;
}
$mr_id->addMultiOptions($options);
// Initialiser le selectmenu des applications
$apps->addMultiOption(null, null);
$app_table = new Application_Model_Rmt_Appli();
foreach ($app_table->fetchAllEnable() as $app) {
$apps->addMultiOption($app->app_id, $app->app_nom);
}
//desactivation du champ infoSNP si train si train = requete technique
....................
}
public function isValidPartial(array $data) {
$valid = parent::isValidPartial($data);
$validator = new Zend_Validate_NotEmpty();
$mr_id_value = $this->getValue('mr_id');
$app_id_value = $this->getValue('app_id');
$version = $this->getElement('version');
$version_value = $version->getValue();
if ($validator->isValid($mr_id_value) && $validator->isValid($app_id_value) && $validator->isValid($version_value)) {
$exclude = 'pat_mr_id = ' . intval($mr_id_value) . ' AND pat_app_id = ' . intval($app_id_value);
$pat_table = new Application_Model_Rmt_Patch_Patch();
if ($pat_table->fieldExists('pat_version', $version_value, $exclude)) {
$version->addError('recordFound');
$valid = false;
}
}
return $valid;
}
}