OEModule\PatientTicketing\models\Queue::getFormFields PHP Method

getFormFields() public method

Function to return a list of the fields that we are expecting an assignment form to contain for this queue.
public getFormFields ( ) : array(array('id'
return array(array('id'
    public function getFormFields()
    {
        $flds = array();
        // priority and notes are reserved fields and so get additional _ prefix for the field name
        if ($this->is_initial) {
            $flds[] = array('id' => '_priority', 'form_name' => self::$FIELD_PREFIX . '_priority', 'required' => $this->getQueueSet()->allow_null_priority ? false : true, 'choices' => \CHtml::listData(Priority::model()->findAll(), 'id', 'name'), 'label' => 'Priority');
        }
        $flds[] = array('id' => '_notes', 'form_name' => self::$FIELD_PREFIX . '_notes', 'required' => false, 'type' => 'textarea', 'label' => 'Notes');
        return array_merge($flds, $this->getAssignmentFieldDefinitions());
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Filters and purifies passed array to get data relevant to a ticket queue assignment.
  *
  * @param \OEModule\PatientTicketing\models\Queue $queue
  * @param $data
  * @param bool $validate
  *
  * @return array
  */
 public function extractQueueData(Queue $queue, $data, $validate = false)
 {
     $result = array();
     $errors = array();
     $p = new \CHtmlPurifier();
     foreach ($queue->getFormFields() as $field) {
         $field_name = $field['form_name'];
         if (@$field['type'] == 'widget') {
             $class_name = 'OEModule\\PatientTicketing\\widgets\\' . $field['widget_name'];
             $widget = new $class_name();
             if (isset($data[$field['form_name']])) {
                 // if widget is missing don't validate
                 $result[$field_name] = $widget->extractFormData($data[$field['form_name']]);
                 if ($validate) {
                     $errors = array_merge($errors, $widget->validate($data[$field['form_name']]));
                 }
             }
         } else {
             $result[$field_name] = $p->purify(@$data[$field_name]);
             if ($validate) {
                 if ($field['required'] && !@$data[$field_name]) {
                     $errors[$field_name] = $field['label'] . ' is required';
                 } elseif (@$field['choices'] && @$data[$field_name]) {
                     $match = false;
                     foreach ($field['choices'] as $k => $v) {
                         if ($data[$field_name] == $k) {
                             $match = true;
                             break;
                         }
                     }
                     if (!$match) {
                         $errors[$field_name] = $field['label'] . ': invalid choice';
                     }
                 }
             }
         }
     }
     if ($validate) {
         return array($result, $errors);
     } else {
         return $result;
     }
 }