public function ActivityPlugin::execute in Activity 8
Executes the query and fills the associated view object with according values.
Values to set: $view->result, $view->total_rows, $view->execute_time, $view->pager['current_page'].
$view->result should contain an array of objects. The array must use a numeric index starting at 0.
Parameters
view $view: The view which is executed.
Overrides QueryPluginBase::execute
File
- src/
Plugin/ views/ query/ ActivityPlugin.php, line 233
Class
- ActivityPlugin
- Activity views query plugin which display all activities.
Namespace
Drupal\activity\Plugin\views\queryCode
public function execute(ViewExecutable $view) {
parent::execute($view);
$count_query = $view->build_info['count_query'];
$count_query
->preExecute();
// Build the count query.
$count_query = $count_query
->countQuery();
try {
if ($view->pager
->useCountQuery() || !empty($view->get_total_rows)) {
$view->pager
->executeCountQuery($count_query);
}
$view->pager
->preExecute($query);
if ($this->activities instanceof Select) {
if (!empty($this->limit) || !empty($this->offset)) {
// We can't have an offset without a limit,
// so provide a very large limit instead.
$limit = intval(!empty($this->limit) ? $this->limit : 999999);
$offset = intval(!empty($this->offset) ? $this->offset : 0);
$this->activities
->range($offset, $limit);
}
$result = $this->activities
->execute();
$result
->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\\views\\ResultRow');
// Setup the result row objects.
$view->result = iterator_to_array($result);
array_walk($view->result, function (ResultRow $row, $index) {
$row->index = $index;
});
$view->pager
->postExecute($view->result);
$view->pager
->updatePageInfo();
$view->total_rows = $view->pager
->getTotalItems();
$this
->loadEntities($view->result);
}
} catch (DatabaseExceptionWrapper $e) {
$view->result = [];
if (!empty($view->live_preview)) {
drupal_set_message($e
->getMessage(), 'activity error view.');
}
else {
throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[{$view->storage->id()}]: {$e->getMessage()}");
}
}
}