class QueryController in Lightweight Directory Access Protocol (LDAP) 8.3
Same name and namespace in other branches
- 8.4 ldap_query/src/Controller/QueryController.php \Drupal\ldap_query\Controller\QueryController
Controller class for LDAP queries, in assistance to the entity itself.
Hierarchy
- class \Drupal\ldap_query\Controller\QueryController
Expanded class hierarchy of QueryController
6 files declare their use of QueryController
- DebuggingReviewForm.php in ldap_help/
src/ Form/ DebuggingReviewForm.php - GroupUserUpdateProcessor.php in ldap_user/
src/ Processor/ GroupUserUpdateProcessor.php - LdapQuery.php in ldap_query/
src/ Plugin/ views/ query/ LdapQuery.php - LdapUserAdminForm.php in ldap_user/
src/ Form/ LdapUserAdminForm.php - QueryTestForm.php in ldap_query/
src/ Form/ QueryTestForm.php
File
- ldap_query/
src/ Controller/ QueryController.php, line 11
Namespace
Drupal\ldap_query\ControllerView source
class QueryController {
private $results = [];
private $qid;
private $query;
/**
* Constructor.
*/
public function __construct($id) {
$this->qid = $id;
$this->query = QueryEntity::load($this->qid);
}
/**
* Returns the filter.
*
* @return string
* Set filter.
*/
public function getFilter() {
return $this->query
->get('filter');
}
/**
* Execute query.
*
* @param null|string $filter
* Optional parameter to override filters. Useful for Views and other
* queries requiring filtering.
*/
public function execute($filter = NULL) {
$count = 0;
if ($this->query) {
$ldap_server = Server::load($this->query
->get('server_id'));
$ldap_server
->connectAndBindIfNotAlready();
if ($filter == NULL) {
$filter = $this->query
->get('filter');
}
foreach ($this->query
->getProcessedBaseDns() as $base_dn) {
$result = $ldap_server
->search($base_dn, $filter, $this->query
->getProcessedAttributes(), 0, $this->query
->get('size_limit'), $this->query
->get('time_limit'), $this->query
->get('dereference'), $this->query
->get('scope'));
if ($result !== FALSE && $result['count'] > 0) {
$count = $count + $result['count'];
$this->results = array_merge($this->results, $result);
}
}
$this->results['count'] = $count;
}
else {
\Drupal::logger('ldap_query')
->warning('Could not load query @query', [
'@query' => $this->qid,
]);
}
}
/**
* Return raw results.
*
* @return array
* Raw results.
*/
public function getRawResults() {
return $this->results;
}
/**
* Return available fields.
*
* @return array
* Available fields.
*/
public function availableFields() {
$attributes = [];
// We loop through all results since some users might not have fields set
// for them and those are missing and not null.
foreach ($this->results as $result) {
if (is_array($result)) {
foreach ($result as $k => $v) {
if (is_numeric($k)) {
$attributes[$v] = $v;
}
}
}
}
return $attributes;
}
/**
* Returns all available LDAP query entities.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* Entity Queries.
*/
public static function getAllQueries() {
$query = \Drupal::entityQuery('ldap_query_entity');
$ids = $query
->execute();
return QueryEntity::loadMultiple($ids);
}
/**
* Returns all enabled LDAP query entities.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* Entity Queries.
*/
public static function getAllEnabledQueries() {
$query = \Drupal::entityQuery('ldap_query_entity')
->condition('status', 1);
$ids = $query
->execute();
return QueryEntity::loadMultiple($ids);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryController:: |
private | property | ||
QueryController:: |
private | property | ||
QueryController:: |
private | property | ||
QueryController:: |
public | function | Return available fields. | |
QueryController:: |
public | function | Execute query. | |
QueryController:: |
public static | function | Returns all enabled LDAP query entities. | |
QueryController:: |
public static | function | Returns all available LDAP query entities. | |
QueryController:: |
public | function | Returns the filter. | |
QueryController:: |
public | function | Return raw results. | |
QueryController:: |
public | function | Constructor. |