Example #1
0
 function __construct($fieldName, $fieldInfo, $value)
 {
     if (empty($value)) {
         $value = !empty($fieldInfo['default']) ? $fieldInfo['default'] : date('Y-m-d H:i:s');
     }
     parent::__construct($fieldName, $fieldInfo, $value);
 }
Example #2
0
 public function __construct($fieldName, $fieldInfo, $value)
 {
     if (!isset($fieldInfo['values'])) {
         $error = sprintf('Sorry, but `%s` field config invalid. Attribute `values` in config options must be defined', $fieldName);
         throw new InvalidArgumentException($error);
     }
     parent::__construct($fieldName, $fieldInfo, $value);
     if (empty($value)) {
         $keys = array_keys($fieldInfo['values']);
         $key = array_shift($keys);
         $value = $key;
     }
     $this->setValue($value);
 }
Example #3
0
 public function setValue($newValue)
 {
     parent::setValue($newValue);
     $this->normalizeValue();
 }
Example #4
0
 public function setDocument($document)
 {
     parent::setDocument($document);
     $this->value = get_class($document);
 }
Example #5
0
 protected function executeColumnMethods(BaseColumn $column, $methods)
 {
     $safeCall = function ($methodName) use(&$column) {
         if (is_callable($methodName)) {
             $callback = $methodName;
         } else {
             $callback = array($column, $methodName);
         }
         if (!is_callable($callback)) {
             throw new InvalidArgumentException(sprintf('Column method not callable. Column - "%s", method - "%s"', $column->getFieldName(), $methodName));
         }
         return call_user_func($callback, $column);
     };
     //
     if (is_scalar($methods)) {
         $methodName = is_string($methods) && !empty($methods) ? $methods : 'getViewValue';
         $columnResult = $safeCall($methodName);
     } else {
         if (is_array($methods)) {
             $columnResult = array();
             foreach ($methods as $name => $methodName) {
                 $columnResult[$name] = $safeCall($methodName);
             }
         } else {
             if (is_callable($methods)) {
                 $columnResult = call_user_func($methods, $column);
             } else {
                 throw new Exception(sprintf('Unable to process parse data for column `%s`, unknown methods in model fields declaration  %s', $column->getFieldName(), print_r($methods, true)));
             }
         }
     }
     return $columnResult;
 }