/** * @param string|null $position * @return Widget[] */ protected function getWidgets($position) { static $widgets, $positions = []; if (null === $widgets) { $widgets = Widget::where(['status' => 1])->get(); } if (!($pos = $this->positions->get($position))) { return []; } if (!isset($positions[$position])) { $positions[$position] = []; foreach ($pos['assigned'] as $id) { if (!isset($widgets[$id]) or !($widget = $widgets[$id]) or !$widget->hasAccess(App::user()) or $nodes = $widget->nodes and !in_array(App::node()->id, $nodes) or !($type = App::widget($widget->type))) { continue; } $result = $type->render($widget); $widget->set('result', $result); $positions[$position][] = $widget; } } return $positions[$position]; }