Ejemplo n.º 1
0
 /**
  * This returns an HTML string representing either an input field or a display
  * value, depending on permissions. 
  * @param string $name - the name of the TABLE field
  * @param string $type - the type of input. If just scalar input, default to 
  *   'text', if choice/array, default to 'select'
  * @param PkExtensions\PkModel $object - the object to check for allowable edits
  * @return string - HTML representing the existing display value OR the relevant HTML
  * input control
  */
 public function customInputField($name, PkModel $object, $value = null, $type = null, $options = [])
 {
     $valids = $object->canEditThisField($name);
     if ($valids === false) {
         return "\n<div class='display_val val'>" . $object->displayValue($name, $value) . "</div>\n";
     }
     if ($valids === true) {
         if (!$type) {
             $type = 'text';
         }
         if ($type === 'boolean') {
             return $this->boolean($name, 1, $object->{$name}, $options);
         }
         if ($type === 'textarea') {
             return $this->textarea($name, $object->{$name}, $options);
         }
         //return "\n<input type='text' class='display_val val' value='".$object->displayValue($name)."'/>\n";
         return $this->input($type, $name, $object->{$name}, $options);
     }
     if (is_array($valids)) {
         #Make a select option control, limited to the options
         if (!$type) {
             $type = 'select';
         }
         return $this->{$type}($name, $valids, $object->{$name}, $options);
     }
     throw new \Exception("Invalid 'valids' result from PkModel instance");
 }