From 377b513193b4d0c155eafa2f2cf13592190be17f Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Wed, 14 Sep 2011 22:21:12 +0000 Subject: improved the way validate conditions are set --- h-source/Application/Models/HardwareModel.php | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'h-source/Application/Models') diff --git a/h-source/Application/Models/HardwareModel.php b/h-source/Application/Models/HardwareModel.php index 7d5060c..d5aaffb 100644 --- a/h-source/Application/Models/HardwareModel.php +++ b/h-source/Application/Models/HardwareModel.php @@ -25,7 +25,7 @@ class HardwareModel extends Model_Map { public $id_user = 0; public $type = ''; //device type public $lastId = 0; //the id of the last record inserted - + public $formStruct = array( 'entries' => array( 'deleted'=> array('type'=>'Select','options'=>'no,yes'), @@ -68,10 +68,38 @@ class HardwareModel extends Model_Map { // $this->databaseConditions['update'] = array( // 'checkUniqueCompl' => 'model', // ); - + parent::__construct(); } + //set the soft and strong conditions + public function setConditions($worksOptions,$worksField,$interfaceOptions) + { + $this->strongConditions['update'] = array( + "checkNotEmpty" => "model|you have to fill the model name entry", + "checkMatch|/^[a-zA-Z0-9\-\_\.\+\s\(\)\@\[\]\/]+$/" => "model|characters not allowed in the model name entry", + "+checkMatch|/^[a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}$/" => "pci_id|VendorID:ProductID has to have the following format: [a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}", + "checkLength|99" => "model", + "+checkLength|299" => "distribution", + "++checkIsStrings|".Wifi::$commYear => "comm_year", + "+++checkIsStrings|".$worksOptions => $worksField, + "++++checkIsStrings|".$interfaceOptions => "interface", + ); + + $this->strongConditions['insert'] = $this->strongConditions['update']; + + $this->softConditions['update'] = array( + "checkMatch|/^[a-zA-Z0-9\-\_\.\+\s]+$/" => "kernel|characters not allowed in the kernel entry", + "checkLength|20000" => "description", + "+checkLength|49" => "kernel", + "++checkLength|49" => "driver", + "++checkMatch|/^[a-zA-Z0-9\-\_\.\+\s\/\,\:\;\(\)\[\]]+$/" => "driver|only the following characters are allowed for the driver entry: a-z A-Z 0-9 - _ . + s / , : ; ( ) [ ]", + "+++checkLength|1000" => "other_names|the other names entry exceeds the value of 1000 characters", + ); + + $this->softConditions['insert'] = $this->softConditions['update']; + } + public function permanentlyDelete($id) { $clean['id'] = (int)$id; -- cgit v1.2.3