/** * Checks user permissions to view the results * * @param array $rows * * @return array */ public function checkPermissions($rows = array()) { $permissions = array(); if (!empty($this->config['checkPermissions'])) { $tmp = array_map('trim', explode(',', $this->config['checkPermissions'])); foreach ($tmp as $v) { $permissions[$v] = true; } } else { return $rows; } $total = $this->modx->getPlaceholder($this->config['totalVar']); foreach ($rows as $key => $row) { /** @var modAccessibleObject $object */ $object = $this->modx->newObject($this->config['class']); $object->_fields['id'] = $row['id']; if ($object instanceof modAccessibleObject && !$object->checkPolicy($permissions)) { unset($rows[$key]); $this->addTime($this->config['class'] . ' #' . $row['id'] . ' was excluded from results, because you do not have enough permissions'); $total--; } } $this->addTime('Checked for permissions "' . implode(',', array_keys($permissions)) . '"'); $this->modx->setPlaceholder($this->config['totalVar'], $total); return $rows; }
/** * @param $key * * @return mixed */ public function getPlaceholder($key) { return $this->modx->getPlaceholder($key); }