コード例 #1
0
 /**
  * Checks to make sure the end date is after the start date for the person position.
  * @param I2CE_Form $form
  */
 public function validate_form_provider_instance($form)
 {
     if ($form->start_date->isValid() && $form->end_date->isValid()) {
         if ($form->start_date->compare($form->end_date) < 1) {
             $form->getField('end_date')->setInvalid("The end date must be after the start date.");
         }
     }
 }
コード例 #2
0
 /**
  * Perform extra validation for the trainingprovider form.
  * A new trainingprovider record needs to verify there aren't any existing 
  * records with the same name.
  * @param I2CE_Form $form
  */
 public function validate_form_trainingprovider($form)
 {
     $search = array();
     $name_ignore = false;
     if (isset($form->name_ignore)) {
         $name_ignore = $form->name_ignore;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage') && $form->getId() == 0 && !$name_ignore && I2CE_Validate::checkString($form->name)) {
         $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'name', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->name)))));
         $results = I2CE_FormStorage::listFields('trainingprovider', array('name'), false, $where, array('name'));
         if (count($results) > 0) {
             foreach ($results as $id => &$data) {
                 $data = implode(', ', $data);
             }
             $form->getField('name')->setInvalid("Duplicate records match this record's name:", array("viewprovider?id=" => $results));
         }
     }
     $value = $form->getField('email')->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $form->getField('email')->setInvalid('invalid_email');
     }
 }
コード例 #3
0
 /**
  * Populate the member variables of the object from the database.
  * @param I2CE_Form $form
  */
 public function populateHistory($form)
 {
     foreach ($form as $field => $field_obj) {
         if ($field_obj && $field_obj instanceof I2CE_FormField) {
             $field_obj->populateHistory();
         }
     }
     if (($parentField = $form->getField('parent')) instanceof I2CE_FormField) {
         $parentField->populateHistory();
     }
 }
コード例 #4
0
 /**
  * Populate the member variables of the object from the database.
  * @param I2CE_Form $form
  */
 public function populate($form)
 {
     $fields = array();
     foreach ($form as $field => $fieldObj) {
         if (!$fieldObj->isInDB()) {
             continue;
         }
         $fields[] = $field;
     }
     $fields[] = 'last_modified';
     $fields[] = 'created';
     $populateQry = $this->getRequiredFieldsQuery($form->getName(), $fields, $form->getId(), true);
     if (!$populateQry) {
         return false;
     }
     $populateQry .= ' LIMIT 1';
     $result = $this->db->getRow($populateQry);
     if (I2CE::pearError($result, "Error populating form " . $form->getName())) {
         return false;
     }
     $form_name = $form->getName();
     foreach ($fields as $field) {
         $fieldObj = $form->getField($field);
         if (!$fieldObj instanceof I2CE_FormField) {
             continue;
         }
         $ref = strtolower($form_name . '+' . $field);
         if (isset($result->{$ref})) {
             $fieldObj->setFromDB($result->{$ref});
         }
     }
     $ref = strtolower($form_name . '+parent');
     if (isset($result->{$ref})) {
         $form->setParent($result->{$ref});
     }
     $ref = strtolower($form_name . '+last_modified');
     if (isset($result->{$ref})) {
         $form->setLastModified($result->{$ref});
     }
     $ref = strtolower($form_name . '+created');
     if (isset($result->{$ref})) {
         $form->setCreated($result->{$ref});
     }
     return true;
 }
コード例 #5
0
 /**
  * Populate the member variables of the object from the Cross Sectional Data Set
  * @param I2CE_Form $form
  * @return boolean
  */
 public function populate($form)
 {
     $formName = $form->getName();
     $this->ensureLocations($formName);
     $id = $form->getId();
     if (!array_key_exists($id, $this->locations[$formName]) || ($location = $this->locations[$formName][$id]) === false) {
         return;
     }
     $data = $this->getFormData($formName, $location);
     foreach ($data as $field => $dbval) {
         if ($field == 'parent') {
             if ($dbval != '0') {
                 $form->setParent($dbval);
             }
         } else {
             $fieldObj = $form->getField($field);
             if (!$fieldObj instanceof I2CE_FormField) {
                 continue;
             }
             $fieldObj->setFromDB($dbval);
         }
     }
     return true;
 }
コード例 #6
0
 /**
  * Perform extra validation for the person_id form.
  * Make sure the date of issue is before the date of expiration.
  * @param I2CE_Form $form
  */
 public function validate_form_person_id($form)
 {
     if ($form->issue_date->isValid() && $form->expiration_date->isValid()) {
         if ($form->issue_date->compare($form->expiration_date) < 1) {
             $form->setInvalidMessage('expiration_date', 'bad_date');
         }
     }
     /*Validate ID Pattern, this is optional*/
     $id_number = $form->getField('id_num')->getDBValue();
     $id_type = $form->getField('id_type')->getDBValue();
     $formObj = I2CE_FormFactory::instance()->createContainer($id_type);
     $formObj->populate();
     if (($patern_field = $formObj->getField('pattern')) instanceof I2CE_FormField) {
         $pattern = $pattern_field->getValue();
         if (trim($pattern) != '') {
             $matches = array();
             preg_match($pattern, $id_number, $matches);
             if (count($matches) == 0) {
                 $form->setInvalidMessage('id_num', 'wrong_pattern');
             }
         }
     }
 }
コード例 #7
0
 /**
  * Get the forms ids for joining on a given field of  a named child form's with the named parent form on a given field
  * @param string $childFormName the name of the child form in the relationship
  * @param I2CE_Form $parentFormObj
  * @param array $joinData The array containg the join data
  * @param array $where
  * @param array $limit
  * @return mixed. An array of form ids
  */
 public function getFormIdsJoiningOn_fields($childFormName, $parentFormObj, $joinData, $where, $limit)
 {
     if (!is_array($joinData)) {
         I2CE::raiseError("Join data  specified for parent_form/{$childFormName}");
         return array();
     }
     foreach (array('parent', 'child') as $field) {
         if (!array_key_exists($field, $joinData) || !is_string($joinData[$field]) || strlen($joinData[$field]) == 0) {
             I2CE::raiseError("Join {$field} field not specified for parent_form/{$childFormName}");
             return array();
         }
     }
     $form = $this->getForm($childFormName);
     $fieldObj = $parentFormObj->getField($joinData['field']);
     if (!$fieldObj instanceof I2CE_FormField) {
         I2CE::raiseError("Invalid field " . $joinData['field']);
         return array();
     }
     $sub_where = array('operator' => 'FIELD_LIMIT', 'field' => $joinDta['child'], 'style' => 'equals', 'data' => array('value' => $fieldObj->getDBValue()));
     if (count($where) > 0) {
         $where = array('operator' => 'AND', 'operand' => array($sub_where, $where));
     } else {
         $where = $sub_where;
     }
     $ids = I2CE_FormStorage::search($form, false, $where, array(), $limit);
     if (is_string($ids)) {
         $ids = array($ids);
     }
     if (is_array($ids)) {
         return $ids;
     } else {
         return array();
     }
     //return " JOIN $refChildForm AS `$childFormName` ON `$childFormName`.`{$joinData['child']}` = `parent_form`.`{$joinData['parent']}` " ;
 }
コード例 #8
0
 /**
  * Generates a limit expression for a form based on  limit data.  Called by {generateWhereClause()}
  * @param I2CE_Form $formObj
  * @param mixed $limit_data
  * array.
  * @param callback $field_refernece_callback.  A callback function whose first arguement is the form, the second arguements
  * is the field and which returns the way the field value should be references as a field.  If the callback is null (the default) then
  * the reference used is "$form+$field"
  * @param string $parent_ref.  Defaults to null.  If not null, it is the referent to the parent id of the form
  * @returns string SQL statement false on failure
  */
 public function generateLimit($formObj, $limit_data = array(), $field_reference_callback = null, $parent_ref = null)
 {
     if (!is_array($limit_data)) {
         I2CE::raiseError("Expected array for generating where sub-expression, but not received");
         return false;
     }
     if (!array_key_exists('field', $limit_data) || !is_string($limit_data['field'])) {
         I2CE::raiseError("Field name is not given at 'field' ");
         return false;
     }
     if (!($fieldObj = $formObj->getField($limit_data['field'])) instanceof I2CE_FormField) {
         I2CE::raiseError("Field {$limit_data['field']} is not a field of " . $formObj->getName());
         return false;
     }
     if ($field_reference_callback !== null) {
         if (!is_string($ref = call_user_func($field_reference_callback, $formObj->getName(), $limit_data['field']))) {
             I2CE::raiseError("Invalid field reference callback function");
             return false;
         }
     } else {
         $ref = '`' . $formObj->getName() . '+' . $limit_data['field'] . '`';
     }
     return $fieldObj->generateLimit($limit_data, $ref, $parent_ref);
 }