Esempio n. 1
0
 public function filterColumnValue($row, string $field, $value, array $column = null)
 {
     if (is_string($value)) {
         $length = strlen($value);
         if ($length > 0) {
             if (isset($column['summary']) && is_numeric($column['summary']) && $column['summary'] > 0) {
                 $value = $this->label(str_summary($value, $column['summary']), null, ['title' => $value]);
             } elseif (isset($column['strLen']) && is_numeric($column['strLen']) && $column['strLen'] > 0) {
                 $value = $this->label(str_len_cut($value, $column['strLen']), null, ['title' => $value]);
             } elseif (isset($column['strWidth']) && is_numeric($column['strWidth']) && $column['strWidth'] > 0) {
                 $value = $this->label(str_width_cut($value, $column['strWidth']), null, ['title' => $value]);
             }
         }
     } elseif (!empty($column['timestamp'])) {
         if (is_numeric($value) && $value > 0) {
             $value = date('Y-m-d H:i:s', $value);
         } else {
             $value = $this->getText(self::TEXT_NONE);
         }
     }
     if (isset($column['options'])) {
         $value = $column['options'][$value] ?? $value;
     }
     if (isset($column['before']) || isset($column['after'])) {
         $value = $this->wrap($value, $column['before'], $column['after'], $column['wrap'] ?? [], 'div');
     }
     if ($row instanceof Model) {
         if (isset($column['getter']) && is_callable([$row, $column['getter']])) {
             $value = call_user_func([$row, $column['getter']]);
         }
     }
     // todo: 这里会增加一些Model默认属性的处理
     if (isset($column['onShow']) && is_callable($column['onShow'])) {
         $value = call_user_func($column['onShow'], $this, $row, $value, $column);
     }
     return $value;
 }
Esempio n. 2
0
 function str_summary($content, $len = 256)
 {
     $content = nl2br($content);
     $content = strip_tags($content);
     $content = str_replace(' ', ' ', $content);
     $content = trim($content);
     $content = preg_replace('/([\\r\\n]+|[\\s]{2,})/i', ' ', $content);
     $content = str_len_cut($content, $len);
     return $content;
 }