Bitrix-D7  20.0.0
resultview.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage sender
6  * @copyright 2001-2018 Bitrix
7  */
9 
12 
13 /**
14  * Class ResultView
15  *
16  * @package Bitrix\Sender\Connector
17  */
18 Class ResultView
19 {
20  const Title = 'title';
21  const Draw = 'draw';
22  const Filter = 'filter';
23  const FilterModifier = 'filter-modifier';
24  const ColumnModifier = 'column-modifier';
25 
26  /** @var Base $connector Connector. */
27  protected $connector;
28 
29  /** @var array $callbacks Callbacks. */
30  protected $callbacks;
31 
32  /** @var PageNavigation $nav Page navigation. */
33  protected $nav;
34 
35  /**
36  * Constructor.
37  *
38  * @param Base $connector Connector.
39  */
40  public function __construct(Base $connector)
41  {
42  $this->connector = $connector;
43  }
44 
45  /**
46  * Set callback.
47  *
48  * @param string $name Name.
49  * @param callable $callable Callback.
50  * @return $this
51  * @throws ArgumentException
52  */
53  public function setCallback($name, $callable)
54  {
55  if (!is_callable($callable))
56  {
57  throw new ArgumentException('Parameter `$callable` should be callable.');
58  }
59 
60  $this->callbacks[$name] = $callable;
61 
62  return $this;
63  }
64 
65  protected function runCallback($name, array $arguments = [])
66  {
67  if (!isset($this->callbacks[$name]))
68  {
69  return null;
70  }
71 
72  return call_user_func_array($this->callbacks[$name], $arguments);
73  }
74 
75  /**
76  * Get filter.
77  *
78  * @return string|null
79  */
80  public function getTitle()
81  {
82  return $this->runCallback(self::Title) ?: $this->connector->getName();
83  }
84 
85  /**
86  * Modify result view filter.
87  *
88  * @param array $filter Filter.
89  * @return void
90  */
91  public function modifyFilter(array &$filter)
92  {
93  $this->runCallback(self::FilterModifier, [&$filter]);
94  }
95 
96  /**
97  * Modify result view columns.
98  *
99  * @param array $columns columns.
100  * @return void
101  */
102  public function modifyColumns(array &$columns)
103  {
104  $this->runCallback(self::ColumnModifier, [&$columns]);
105  }
106 
107  /**
108  * Set page navigation.
109  *
110  * @param PageNavigation|null $nav Page navigation.
111  * @return $this
112  */
113  public function setNav(PageNavigation $nav = null)
114  {
115  $this->nav = $nav;
116  return $this;
117  }
118 
119  /**
120  * Get page navigation.
121  *
122  * @return PageNavigation|null
123  */
124  public function getNav()
125  {
126  return $this->nav;
127  }
128 
129  /**
130  * Has page navigation.
131  *
132  * @return bool
133  */
134  public function hasNav()
135  {
136  return !empty($this->nav);
137  }
138 
139  /**
140  * Callback on filter of result view.
141  *
142  * @return void
143  */
144  public function onFilter()
145  {
146  $this->runCallback(self::Filter);
147  }
148 
149  /**
150  * Callback on draw of result view.
151  *
152  * @param array $raw Raw.
153  * @return void
154  */
155  public function onDraw(array &$raw)
156  {
157  $this->runCallback(self::Draw, [&$raw]);
158  }
159 }
Bitrix\Sender\Connector\$callbacks
$callbacks
Definition: resultview.php:30
Bitrix\Sender\Connector\modifyColumns
modifyColumns(array &$columns)
Modify result view columns.
Definition: resultview.php:102
Bitrix\Sender\Connector\hasNav
hasNav()
Has page navigation.
Definition: resultview.php:134
Bitrix\Main\UI\PageNavigation
Class PageNavigation.
Definition: main/lib/ui/pagenavigation.php:26
Bitrix\Sender\Connector\setNav
setNav(PageNavigation $nav=null)
Set page navigation.
Definition: resultview.php:113
Bitrix\Sender\Connector\ColumnModifier
const ColumnModifier
Definition: resultview.php:24
Bitrix\Sender\Connector\$nav
$nav
Definition: resultview.php:33
Bitrix\Sender\Connector
Definition: sender/lib/connector/base.php:8
Bitrix\Sender\Connector\onDraw
onDraw(array &$raw)
Callback on draw of result view.
Definition: resultview.php:155
Bitrix\Main\ArgumentException
Exception is thrown when function argument is not valid.
Definition: main/lib/exception.php:33
Bitrix\Sender\Connector\setCallback
setCallback($name, $callable)
Set callback.
Definition: resultview.php:53
Bitrix\Sender\Connector\FilterModifier
const FilterModifier
Definition: resultview.php:23
Bitrix\Sender\Connector\ResultView
Class ResultView
Definition: resultview.php:19
Bitrix\Sender\Connector\__construct
__construct(Base $connector)
Constructor.
Definition: resultview.php:40
Bitrix\Sender\Connector\$connector
$connector
Definition: resultview.php:27
Bitrix\Sender\Connector\Base
Definition: sender/lib/connector/base.php:13
Bitrix\Sender\Connector\getNav
getNav()
Get page navigation.
Definition: resultview.php:124
Bitrix\Sender\Connector\Draw
const Draw
Definition: resultview.php:21
Bitrix\Sender\Connector\Filter
const Filter
Definition: resultview.php:22
Bitrix\Sender\Connector\modifyFilter
modifyFilter(array &$filter)
Modify result view filter.
Definition: resultview.php:91
Bitrix\Sender\Connector\getTitle
getTitle()
Get filter.
Definition: resultview.php:80
Bitrix\Sender\Connector\runCallback
runCallback($name, array $arguments=[])
Definition: resultview.php:65
Bitrix\Sender\Connector\onFilter
onFilter()
Callback on filter of result view.
Definition: resultview.php:144