Adds a filter to the query based on the access mode.

@param AnCommandContext $context
434384
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        if (AnService::has('viewer')) {
            $query = $context->query;
            $repository = $query->getRepository();
            $viewer = get_viewer();

            if ($viewer->id) {
                $query->where("IF( FIND_IN_SET({$viewer->id}, @col(blockedIds)), 0, 1)");
            }
        }
    }
65575
public function redirect(AnCommandContext $context)
    {
        $url = null;

        if ($context->action === 'delete') {
            $viewer = $this->getService('com:people.viewer');

            if ($viewer->id == $this->getItem()->id) {
                $url = 'index.php?';
            } else {
                $url = 'option=com_people&view=people';
            }
        }

        if ($url) {
            $context->response->setRedirect(route($url));
        }
    }
1102951
protected function _beforeEntityInsert(AnCommandContext $context)
    {
        //if the entity default is set to 
        //true then, set the previous default entity to false
        if ($this->_mixer->isDefault === true) {
            $query = $this->getScopedQuery($context->entity);
            $this->getRepository()->update(array('isDefault' => false), $query);
        }
    }
582145
protected function _actionPost(AnCommandContext $context)
    {
        $action = $this->getItem() ? 'edit' : 'add';
        $result = $this->execute($action, $context);

        return $result;
    }
243390
protected function _actionRead(AnCommandContext $context)
    {
        $apis = ComConnectHelperApi::getServices();

        $this->getService('repos:connect.session');

        $sessions = $this->actor->sessions;

        foreach ($apis as $key => $api) {
            if (!$api->canAddService($this->actor)) {
                unset($apis[$key]);
            }
        }

        $this->apis = $apis;
        $this->sessions = $sessions;
    }
1077284
protected function _actionBrowse($context)
    {
        if (!$context->query) {
            $context->query = $this->getRepository()->getQuery();
        }

        $query = $context->query;
        $query->order('open', 'DESC');

        if ($this->sort == 'priority') {
            $query->order('priority', 'DESC');
        }

        return parent::_actionBrowse($context);
    }
349654
protected function _actionDispatch(AnCommandContext $context)
    {
        if (
            $this->getController()->getIdentifier()->name === 'session' &&
            $this->token != ''
        ) {
            $this->getController()->execute('tokenlogin', $context);
            $context->response->send();
            exit(0);
        }

        return parent::_actionDispatch($context);
    }
913934
protected function _authorizeAdd(AnCommandContext $context)
    {
        $can_publish = get_config_value($this->_entity->component, 'can_publish', self::CAN_ADD_ADMIN);

        switch ($can_publish) {
            case self::CAN_ADD_ADMIN :
                return $this->_viewer->admin();
            case self::CAN_ADD_SPECIAL :
                return $this->_viewer->usertype != 'Registered' && !$this->_viewer->guest();
            case self::CAN_ADD_ALL :
                return !$this->_viewer->guest();
            default :
                return false;
        }
    }
883066
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->set->setValue('photo_count', $this->set->photos->reset()->getTotal());
    }
512643
protected function _actionAdd($context)
    {
        $data = $context->data;
        $body = $data->body;

        return $this->setItem($this->parent->addComment($body))->getItem();
    }
323463
protected function _actionAdd(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::CREATED;
        $entity = $this->getRepository()->getEntity()->setData($context['data']);
        $this->setItem($entity);

        return $this->getItem();
    }
1066667
protected function _actionAddcomment(AnCommandContext $context)
    {
        $data = $context->data;
        $comment = $this->getCommentController()->add(array('body' => $data->body));
        $context->response->status = AnHttpResponse::CREATED;
        $context->comment = $comment;

        if ($this->isDispatched()) {
            $context->response->content = $this->getCommentController()->display();

            if ($context->request->getFormat() == 'html') {
                $offset = $this->getItem()->getCommentOffset($comment->id);
                $start = (int) ($offset / $this->limit) * $this->limit;
                $context->response->setRedirect(route($comment->parent->getURL().'&start='.$start).'#scroll='.$comment->id);
            } else {
                $context->response->setRedirect(route($comment->getURL()));
            }
        }

        return $comment;
    }
1064928
protected function _authorizeRemoveAdmin(AnCommandContext $context)
    {
        if ($this->_entity->isAdministrable()) {
            return ($this->_entity->administratorIds->count() >= 2);
        }

        return false;
    }
1100875
protected function _beforeControllerBrowse(AnCommandContext $context)
    {
        if (!$context->query) {
            $context->query = $this->_mixer->getRepository()->getQuery();
        }

        if ($this->hashtag) {
            $query = $context->query;
            $hashtags = array();
            $entityType = AnInflector::singularize($this->_mixer->getIdentifier()->name);
            $this->hashtag = (is_string($this->hashtag)) ? array($this->hashtag) : $this->hashtag;

            $edgeType = 'ComTagsDomainEntityTag,ComHashtagsDomainEntityTag,com:hashtags.domain.entity.tag';

            $query
            ->join('left', 'edges AS hashtag_edge', '('.$entityType.'.id = hashtag_edge.node_b_id AND hashtag_edge.type=\''.$edgeType.'\')')
            ->join('left', 'nodes AS hashtag', 'hashtag_edge.node_a_id = hashtag.id');

            foreach ($this->hashtag as $hashtag) {
                $hashtag = $this->getService('com:hashtags.filter.hashtag')->sanitize($hashtag);
                if ($hashtag != '') {
                    $hashtags[] = $hashtag;
                }
            }

            $query
            ->where('hashtag.name', 'IN', $hashtags)
            ->group($entityType.'.id');

            //print str_replace('#_', 'jos', $query);
        }
    }
427147
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->administrable->getRepository()
                            ->getBehavior('administrable')
                            ->resetStats(array(
                              $this->administrable,
                              $this->administrator, ));
    }
97314
public function addFilter(Filter $filter)
    {
        $key = $filter->getKey();
        $this->filters[$key] = $filter;
    }
225522
protected function _actionBrowse(AnCommandContext $context)
    {
        if (!$context->query) {
            $context->query = $this->getRepository()->getQuery();
        }

        $query = $context->query;

        if ($this->q) {
            $query->keyword = $this->getService('anahita:filter.term')->sanitize($this->q);
        }

        if ($this->hasBehavior('parentable') && $this->getParent()) {
            $query->parent($this->getParent());
        }

        if ($this->hasBehavior('ownable') && $this->hasBehavior('pinnable')) {
            $owner = $this->getActor();
            if (isset($owner)) {
                $query->order('pinned', 'DESC');
            }
        }

        switch ($this->sort) {
            case 'top':
                $identifierName = $this->_mixer->getIdentifier()->name;
                $query->order('(COALESCE('.$identifierName.'.comment_count,0) + COALESCE('.$identifierName.'.vote_up_count,0) + COALESCE('.$identifierName.'.subscriber_count,0) + COALESCE('.$identifierName.'.follower_count,0))', 'DESC');
            break;

            case 'updated':
                $query->order('updateTime', 'DESC');
            break;

            case 'oldest':
                $query->order('creationTime', 'ASC');
            break;

            case 'recent':
            case 'newest':
                $query->order('creationTime', 'DESC');
            break;
        }

        $query->limit($this->limit, $this->start);

        return $this->getState()->setList($query->toEntityset())->getList();
    }