Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Validator
- */
- class DoForm_Validator extends RequiredFields {
- protected $id;
- protected $customRequired = array('Number', 'Title', 'IssuingDate', 'Revision', 'RevisionDate');
- /**
- * Constructor
- * @param Int $id id of the DO we are validating, 0 for new ones
- */
- public function __construct($id = 0) {
- Debug::log('ID2: ' . $this->id);
- $this->id = $id;
- parent::__construct($this->customRequired);
- }
- /**
- * Verifica che il Number sia univoco
- *
- * @param array $data Submitted data
- * @return bool Returns TRUE if the submitted data is valid, otherwise
- * FALSE.
- */
- public function php($data) {
- $valid = parent::php($data);
- if ($valid) {
- Debug::log(print_r($data, true));
- $check = DoForm::get('DoForm', "Number='{$data['Number']}'");
- Debug::log('this ID: ' . $this->id);
- Debug::log('DB ID: ' . $check->First()->ID);
- Debug::log('Check count: ' . $check->count());
- if ($this->id !== 0) {
- // Modifica di un record - l'unico DO presente deve avere lo stesso ID
- // di quello che sto modificando
- Debug::log('Modifica');
- if ($check->First()->ID !== $this->ID) {
- $this->validationError(
- 'Number',
- "Esiste già il modulo numero {$data['Number']}",
- 'validation'
- );
- $valid = false;
- }
- } else {
- // Nuovo record - non dev'essere presente nessun DO con quel Number
- Debug::log('Inserimento');
- if ($check->count() > 0) {
- $this->validationError(
- 'Number',
- "Esiste già il modulo numero {$data['Number']}",
- 'validation'
- );
- $valid = false;
- }
- }
- }
- return $valid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement