Search role
@param string $id
@param string $target
@param string $term
@return array
766900
public function actionRoleSearch($id, $target, $term = '')
    {
        $result = [
            'Roles' => [],
            'Permission' => [],
            'Routes' => [],
        ];
        $authManager = Yii::$app->authManager;
        if ($target == 'avaliable') {
            $children = array_keys($authManager->getChildren($id));
            $children[] = $id;
            foreach ($authManager->getRoles() as $name => $role) {
                if (in_array($name, $children)) {
                    continue;
                }
                if (empty($term) or strpos($name, $term) !== false) {
                    $result['Roles'][$name] = $name;
                }
            }
            foreach ($authManager->getPermissions() as $name => $role) {
                if (in_array($name, $children)) {
                    continue;
                }
                if (empty($term) or strpos($name, $term) !== false) {
                    if (isset($name[0])) {
                        $result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name;
                    } else {
                        $result['Permission'][$name] = $name;
                    }
                }
            }
        } else {
            foreach ($authManager->getChildren($id) as $name => $child) {
                if (empty($term) or strpos($name, $term) !== false) {
                    if ($child->type == Item::TYPE_ROLE) {
                        $result['Roles'][$name] = $name;
                    } else {
                        $result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name;
                    }
                }
            }
        }
        return Html::renderSelectOptions('', array_filter($result));
    }
753129
public function getUsersForRole($id)
    {
        if (is_null($id)) {
            throw new \Exception('name is required');
        }

        $result = array();
        try {
            $role = $this->findById($id);
            if(empty($role)) throw new \Exception('Role is not found');
            $users  = $this->_em->getRepository('\erdiko\users\entities\User')
                                ->findBy(array('role' => $role->getName()));
            $result  = $users;
        } catch (\Exception $e) {
            \error_log($e->getMessage());
            throw  $e;
        }
        return $result;
    }
906090
public function normalizeFromPost($entity, $target)
    {
        $key = $this->mapping['fieldname'];
        $accessor = 'get' . ucfirst($key);

        $outerCollection = $entity->$accessor();
        if ($outerCollection === null || $outerCollection instanceof Collections\Collection) {
            return null;
        }

        /** @var Collection\Taxonomy|Collection\Relations $collection */
        $collection = $this->em->createCollection($target);

        if (is_string($outerCollection)) {
            $outerCollection = [$outerCollection];
        }

        if (is_array($outerCollection)) {
            $related = [
                $key => $outerCollection,
            ];
            $collection->setFromPost($related, $entity);
        }

        return $collection;
    }
696648
public function getLeadNotes($id, $search = '', $start = 0, $limit = 0, $orderBy = '', $orderByDir = 'ASC')
    {
        $parameters = array(
            'search'        => $search,
            'start'         => $start,
            'limit'         => $limit,
            'orderBy'       => $orderBy,
            'orderByDir'    => $orderByDir,
        );

        $parameters = array_filter($parameters);

        return $this->makeRequest('contacts/'.$id.'/notes', $parameters);
    }
101376
public function getDescent($id)
    {
        $all_results = new Collection(DB::select($this->getDescentInitialQuery(), [':id' => $id]));

        if (count($all_results)) {
            $this->getRecursiveDescent($all_results, $all_results->lists('term_id'));
        }

        return $all_results;
    }
485168
function find_targets($where)
	{
		$xref_class_name = popval($where, 'xref_class_name');
		if(!$xref_class_name)
			$xref_class_name = $this->class_name();
		$target_class_name = popval($where, 'target_class_name');
		if(!$target_class_name)
			$target_class_name = $this->target_class_name();
		$target_field_name = popval($where, 'target_field_name');
		if(!$target_field_name)
			$target_field_name = $this->target_field_name();
		$target_where = popval($where, 'target', array());
		$xrefs = bors_find_all($xref_class_name, $where);
		$ids = bors_field_array_extract($xrefs, $target_field_name);
		$target_where['id IN'] = $ids;
		return bors_find_all($target_class_name, $target_where);
	}
635401
public function getAction($id)
    {
        $find = function($id) {
            /** @var RoleInterface $role */
            $role = $this->getRoleRepository()->findRoleById($id);

            return $this->convertRole($role);
        };

        $view = $this->responseGetById($id, $find);

        return $this->handleView($view);
    }
1198633
public function getSuggestions($term, $pageID, $limit = 5, $approved = true) {

		// Make sure the search matches the minimum autocomplete length.

		if($term && (strlen($term) > 2)) {

			// Make sure the current user has appropriate permission.

			$pageID = (int)$pageID;
			if(($page = ExtensibleSearchPage::get_by_id(ExtensibleSearchPage::class, $pageID)) && $page->canView()) {

				// Retrieve the search suggestions.

				$suggestions = ExtensibleSearchSuggestion::get()->filter(array(
					'Term:StartsWith' => $term,
					'Approved' => (int)$approved,
					'ExtensibleSearchPageID' => $pageID
				))->sort('Frequency', 'DESC')->limit($limit);

				// Make sure the search suggestions are unique.

				return $suggestions->column('Term');
			}
		}
		return array();
	}
1128555
public function getByTarget(Target $target, $limit = 50, $page = 0)
    {
        $dql = sprintf(self::DQL_BY_TARGET, Release::class);
        $params = ['target' => $target];

        return $this->getPaginator($dql, $limit, $page, $params);
    }
990564
private static function get_field( $target_id = 0, $field = '' ) {
		if ( self::is_active() ) {
			if ( $field ) {
				return self::get_single_field( $target_id, $field );
			} else {
				return self::get_all_fields( $target_id );
			}
		}
		return $field ? null : [];
	}
886322
public function load($term_id)
    {
        $info = get_term($term_id, $this->getTaxonomyKey());
        if (!is_object($info)) {
            return false;
        }

        $this->_info = (array) $info;

        // extra
        $option = get_option($this->getOptionID($term_id));
        if (!is_object($option) && !is_array($option)) {
            return true;
        }

        foreach ($option as $k => $v) {
            $this->set($k, $v);
        }

        return true;
    }
883195
protected function applySearchTermFilterToQueryBuilder($query, $target, $search)
    {
        // Make sure we have a target to work with
        $target = $target ?: $query->getModel()->getKeyName();

        $this->applyFilterStrategyToQuery($query, $target, $search);

        return $this;
    }
1339138
public function getMailer($target = null, $id = false, $orgId = false)
    {
        if(isset($this->mailTargets[$target])) {
            $target = ucfirst($target);
            return $this->_loadClass($target.'Mailer', true, array($id, $orgId));
        } else {
            return false;
        }
    }
39604
public function addRole($id, $role)
    {
        if (empty($role) || !$user = $this->getUser($id)) {
            return false;
        }

        // Add the role to the $user['roles'] array
        $user['roles'][] = $role;

        return $this->saveUser($user);
    }
1281895
public function createDeploymentStatus(int $id, string $state, string $targetUrl = '',
                                           string $description = ''): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/deployments/:id/statuses',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $id), Request::METHOD_POST, [
                'state'       => $state,
                'target_url'  => $targetUrl,
                'description' => $description
            ]);
    }
308838
public function GetForRole($RoleID = '', $Offset = '0', $Limit = '50') {
      if (!is_array($RoleID))
         $RoleID = array($RoleID);
      
      $Offset = is_numeric($Offset) ? $Offset : 0;
      if ($Offset < 0)
         $Offset = 0;

      $Limit = is_numeric($Limit) ? $Limit : 0;
      if ($Limit < 0)
         $Limit = 0;
      
      $this->ActivityQuery();
      $Result = $this->SQL
         ->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
         ->WhereIn('ur.RoleID', $RoleID)
         ->Where('t.Public', '1')
         ->OrderBy('a.DateInserted', 'desc')
         ->Limit($Limit, $Offset)
         ->Get();
         
      $this->EventArguments['Data'] =& $Result;
      $this->FireEvent('AfterGet');
      
      return $Result;
   }
53940
protected function _findRecord($id, Subject $subject)
    {
        $repository = $this->_table();
        $this->_configIndex($repository, $this->_request());

        if ($this->_request()->query('type')) {
            $repository->name($this->_request()->query('type'));
        }

        $query = $repository->find($this->findMethod());
        $query->where(['_id' => $id]);
        $subject->set([
            'repository' => $repository,
            'query' => $query
        ]);
        $this->_trigger('beforeFind', $subject);
        $entity = $query->first();
        if (!$entity) {
            return $this->_notFound($id, $subject);
        }
        $subject->set(['entity' => $entity, 'success' => true]);
        $this->_trigger('afterFind', $subject);

        return $entity;
    }