Service Browse.

@param AnCommandContext $context
422749
protected function _actionBrowse($context)
    {
        $entities = parent::_actionBrowse($context);

        if (isset($this->actor->id)) {
            $entities->actorId($this->actor->id);
        }

        return $entities;
    }
118405
protected function _actionForward(AnCommandContext $context)
    {
        $response = $this->getController()->getResponse();

        if (! $response->getContent()) {
            if (in_array($response->getStatusCode(), array(201, 205))) {
                $view = $this->getController()->getIdentifier()->name;
                $response->setContent($this->getController()->view($view)->execute('display', $context));

                if ($response->getStatusCode() == 205) {
                    $response->setStatus(200);
                }
            }
        }

        return $context->result;
    }
453705
protected function _actionBrowse(AnCommandContext $context)
    {
        $entities = parent::_actionBrowse($context);

        if (
            $this->getRepository()->hasBehavior('ownable') &&
            $this->filter == 'leaders'
        ) {
            $leaderIds = array($this->viewer->id);
            $leaderIds = array_merge($leaderIds, $this->viewer->getLeaderIds()->toArray());
            $entities->where('owner.id', 'IN', $leaderIds);
        } elseif (
            $this->getRepository()->hasBehavior('ownable') &&
            $this->actor && $this->actor->id > 0
        ) {
            $entities->where('owner', '=', $this->actor);
        }

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

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

            $edgeType = 'ComTagsDomainEntityTag,ComPeopleDomainEntityMention,com:people.domain.entity.mention';

            $query
            ->join('left', 'edges AS mention_edge', '('.$entityType.'.id = mention_edge.node_b_id AND mention_edge.type=\''.$edgeType.'\')')
            ->join('left', 'nodes AS mention', 'mention_edge.node_a_id = mention.id')
            ->join('left', 'people_people AS person', 'person.node_id = mention.id');

            foreach ($this->mention as $mention) {
                $username = $this->getService('com:people.filter.username')->sanitize($mention);

                if ($username != '') {
                    $usernames[] = $username;
                }
            }

            $query
            ->where('person.username', 'IN', $usernames)
            ->group($entityType.'.id');
        }
    }
582145
protected function _actionPost(AnCommandContext $context)
    {
        $action = $this->getItem() ? 'edit' : 'add';
        $result = $this->execute($action, $context);

        return $result;
    }
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));
        }
    }
1135683
public function execute($command, $context)
    {
        if (!$context instanceof  AnCommandContext) {
            $context = new AnCommandContext($context);
        }

        $parts = explode('.', $command);
        $method = '_'.$parts[0].'Entity'.ucfirst($parts[1]);
        $result = null;

        if (method_exists($this, $method)) {
            $result = $this->$method($context);
        }

        return $result;
    }
200338
protected function _actionRender(AnCommandContext $context)
    {
        if ($context->request->getFormat() == 'html' && AnRequest::type() == 'HTTP') {
            $this->_setPageTitle();
        }

        return parent::_actionRender($context);
    }
747823
protected function _actionAdd(AnCommandContext $context)
    {
        $entity = parent::_actionAdd($context);

        if ($entity->isPortraitable() && AnRequest::has('files.portrait')) {
            $file = AnRequest::get('files.portrait', 'raw');

            if ($this->bellowSizeLimit($file) && $file['error'] == 0) {
                $entity->setPortrait(array(
                   'url' => $file['tmp_name'],
                   'mimetype' => $file['type'],
                   )
               );
            }
        }

        return $entity;
    }
130467
protected function _authorizeAccess(AnCommandContext $context)
    {
        //if entity is not privatable then it doesn't have access to allow method
        if (!$this->_entity->isPrivatable()) {
            return true;
        }

        if ($this->_viewer->admin()) {
            return true;
        }

        if ($this->_entity->isFollowable() && $this->_entity->blocking($this->_viewer)) {
            return false;
        }

        if ($this->_entity->allows($this->_viewer, 'access')) {
            return true;
        }

        return false;
    }
737102
public function fetchRequester(AnCommandContext $context)
    {
        $data = $context->data;

        if ($this->getItem()) {
            $this->getState()
                 ->requester = $this->getItem()
                                    ->requesters
                                    ->fetch($data->requester);
        }
    }
1086880
final public function execute($name, AnCommandContext $context)
    {
        if ($context->config->filter) {
            $filters = (array) AnConfig::unbox($context->config->filter);

            if (!in_array($this->_name, $filters)) {
                return $context->data;
            }
        }

        if ($context->config->exclude) {
            $exclude = (array) AnConfig::unbox($context->config->exclude);

            if (in_array($this->_name, $exclude)) {
                return $context->data;
            }
        }

        $context->data = $this->filter($context->data, $context->config);
    }
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);
        }
    }
323463
protected function _actionAdd(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::CREATED;
        $entity = $this->getRepository()->getEntity()->setData($context['data']);
        $this->setItem($entity);

        return $this->getItem();
    }
126736
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        $query = $context->query;
        $services = array_keys(ComConnectHelperApi::getServices());
        $query->api($services);
    }
496023
protected function _actionVoteComment(AnCommandContext $context)
    {
        $this->getCommentController()->id($this->cid)->execute('vote', $context);
    }
1373554
protected function _beforeControllerGet(AnCommandContext $context)
    {
        if ($this->_mixer->getRequest()->get == 'accesstoken') {
            $this->_mixer->execute('getaccesstoken', $context);
            return false;
        } else {
            $this->api = $this->getAPI();
        }
    }