1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace DigitalWand\AdminHelper\Widget; |
4
|
|
|
|
5
|
|
|
use Bitrix\Main\Localization\Loc; |
6
|
|
|
|
7
|
|
|
Loc::loadMessages(__FILE__); |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Выводит textarea для редактирования длинных строк. |
11
|
|
|
* Урезает длинные строки при отображении в списке |
12
|
|
|
* |
13
|
|
|
* Доступные опции: |
14
|
|
|
* <ul> |
15
|
|
|
* <li><b>COLS</b> - ширина</li> |
16
|
|
|
* <li><b>ROWS</b> - высота</li> |
17
|
|
|
* </ul> |
18
|
|
|
*/ |
19
|
|
|
class TextAreaWidget extends StringWidget |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* количество отображаемых символов в режиме списка. |
23
|
|
|
*/ |
24
|
|
|
const LIST_TEXT_SIZE = 150; |
25
|
|
|
|
26
|
|
|
static protected $defaults = array( |
27
|
|
|
'COLS' => 65, |
28
|
|
|
'ROWS' => 5, |
29
|
|
|
'EDIT_IN_LIST' => false |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
|
|
protected function getEditHtml() |
36
|
|
|
{ |
37
|
|
|
$cols = $this->getSettings('COLS'); |
38
|
|
|
$rows = $this->getSettings('ROWS'); |
39
|
|
|
|
40
|
|
|
return '<textarea cols="' . $cols . '" rows="' . $rows . '" name="' . $this->getEditInputName() . '">' |
41
|
|
|
. static::prepareToOutput($this->getValue(), false) . '</textarea>'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
|
|
public function generateRow(&$row, $data) |
48
|
|
|
{ |
49
|
|
|
$text = $this->getValue(); |
50
|
|
|
|
51
|
|
|
if ($this->getSettings('EDIT_IN_LIST') AND !$this->getSettings('READONLY')) { |
|
|
|
|
52
|
|
|
$row->AddInputField($this->getCode(), array('style' => 'width:90%')); |
53
|
|
|
} else { |
54
|
|
View Code Duplication |
if (strlen($text) > self::LIST_TEXT_SIZE && !$this->isExcelView()) { |
|
|
|
|
55
|
|
|
$pos = false; |
56
|
|
|
$pos = $pos === false ? stripos($text, " ", self::LIST_TEXT_SIZE) : $pos; |
57
|
|
|
$pos = $pos === false ? stripos($text, "\n", self::LIST_TEXT_SIZE) : $pos; |
58
|
|
|
$pos = $pos === false ? stripos($text, "</", self::LIST_TEXT_SIZE) : $pos; |
59
|
|
|
$pos = $pos === false ? 300 : $pos; |
60
|
|
|
$text = substr($text, 0, $pos) . " ..."; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$text = static::prepareToOutput($text); |
64
|
|
|
|
65
|
|
|
$row->AddViewField($this->code, $text); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.