Method to fetch or create a location enitty

@param AnCommandContext $context
@return ComLocationsDomainEntityLocation entity
543359
public function fetchLocation(AnCommandContext $context)
   {
       $data = $context->data;

       if($data->location_id){
           $attr = array('id' => $data->location_id);
       } else {
           $attr = array(
              'latitude' => $data->latitude,
              'longitude' => $data->longitude,
              'name' => $data->name,
              'address' => $data->address,
              'city' => $data->city,
              'state_province' => $data->state_province,
              'country' => $data->country,
              'postalcode' => $data->postalcode
           );
       }

       $this->_location = $this->getService('repos:locations.location')->findOrAddNew($attr);

       return $this->_location;
   }
792644
public function process($context)
    {
        $context->setContents($this->setCDataPlaceholder($context->getContents(), $context->getPlaceholderContainer()));

        return $context->setContents($this->setConditionalCommentsPlaceholder($context->getContents(), $context->getPlaceholderContainer()));
    }
911674
protected function _actionDelete(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::NO_CONTENT;
        $entity = $this->getItem()->delete();

        return $entity;
    }
400416
public function getContextLocale($context)
    {
        return isset($this->contextLocales[$context]) ? $this->contextLocales[$context] : null;
    }
378272
public function getAvailable($context = null)
    {
        $enabledPlugins = $this->pluginManager->getEnabled(true);

        return $this->widgetRepository->findAllAvailable($enabledPlugins, $context);
    }
26606
public function getContext(ViewContextInterface $context = null)
    {
        $context = new ViewContext($context);
        $context->setEntity($this->getModel()->fetch());
        $context->setData($this->getData());
        $context->setParameters($this->getParameters());

        return $context;
    }
365669
public function fetchPhoto(AnCommandContext $context)
    {
        $data = $context->data;

        $data->append(array(
            'photo_id' => $this->photo_id,
        ));

        $photo_id = (array) AnConfig::unbox($data->photo_id);

        if (!empty($photo_id)) {
            $photo = $this->actor->photos->fetchSet(array('id' => $photo_id));

            if (count($photo) === 0) {
                $photo = null;
            }

            $this->photos = $this->photo = $photo;
        }

        return $this->photo;
    }
22838
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        $query = $context->query;
        //$query->where('@col(comment.id) IS NULL');
        $query->where('IF(@col(target.enabled) IS NULL, 1, @col(target.enabled) <> 0) AND IF(@col(subject.enabled) IS NULL, 1, @col(subject.enabled) <> 0)')
              ->link('target', array('type' => 'weak', 'bind_type' => false));

        //apply the privacy 
        $privtable = $this->getBehavior('com://site/medium.domain.behavior.privatable');

        $query->privacy = pick($query->privacy, new AnConfig());

        //weak link  the stories with object nodes
        //and use the object.access instead of the story access if there are ny
        $query->link('object', array('type' => 'weak', 'bind_type' => false));
        //we are using the object.access as the privacy reference
        $query->privacy->append(array(
             'use_access_column' => '@col(object.access)',
        ));

        $privtable->execute('before.fetch', $context);
    }
1133109
public function fetchEntity(AnCommandContext $context)
    {
        if (!$this->_entity) {
            $this->_entity = $this->getService('com:settings.domain.entity.setting')->load();
        }

        return $this->_entity;
    }
374211
protected function _actionGet(AnCommandContext $context)
    {
        $action = null;

        if ($this->_request->get) {
            $action = strtolower('get'.$this->_request->get);
        } else {
            $action = AnInflector::isPlural($this->view) ? 'browse' : 'read';
        }

        $result = null;

        if (in_array($action, $this->getActions())) {
            $result = $this->execute($action, $context);

            if (is_string($result) || $result === false) {
                $context->response->setContent($result.' ');
            }
        }

        $view = $this->getView();

        if (!$context->response->getContent()) {
            if ($context->params) {
                foreach ($context->params as $key => $value) {
                    $view->set($key, $value);
                }
            }
            $content = $view->display();
            //Set the data in the response
            $context->response->setContent($content);
        }

        $context->response->setContentType($view->mimetype);

        return $context->response->getContent();
    }
1061564
protected function loadContext($location)
    {
        $context = new Context();

        $cacheFile = $location . '/cache/apidoc.data';
        $this->stdout('Loading apidoc data from cache... ');
        if (file_exists($cacheFile)) {
            $context = unserialize(file_get_contents($cacheFile));
            $this->stdout('done.' . PHP_EOL, Console::FG_GREEN);
        } else {
            $this->stdout('no data available.' . PHP_EOL, Console::FG_YELLOW);
        }

        return $context;
    }
162738
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        $query = $context->query;

        if ($query->keyword) {
            $keywords = $query->keyword;

            if ($keywords) {
                if (strpos($keywords, ' OR ')) {
                    $keywords = explode(' OR ', $keywords);
                    $operation = 'OR';
                } else {
                    $keywords = explode(' ', $keywords);
                    $operation = 'AND';
                }

                if (!empty($operation)) {
                    $clause = $query->clause();
                    $search_column = array();

                    foreach ($this->_searchable_properties as $property) {
                        $search_column[] = "IF(@col($property) IS NULL,\"\",@col($property))";
                    }

                    $search_column = implode($search_column, ',');

                    foreach ($keywords as $keyword) {
                        $clause->where('CONCAT('.$search_column.') LIKE @quote(%'.$keyword.'%)', $operation);
                    }
                }
            }
        }
    }
335962
public function addCover(AnCommandContext $context)
    {
        $entity = $this->getItem();
        
        if ($entity->isCoverable() && AnRequest::has('files.cover')) {
            $file = AnRequest::get('files.cover', 'raw');

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

        return $entity;
    }
293197
protected function ensureContext(OperationContextInterface $context = null)
    {
        if ($context === null) {
            $context = $this->getSession()->getDefaultContext();
        }

        return $context;
    }
1097919
protected function _actionBrowse(AnCommandContext $context)
    {
        $entities = parent::_actionBrowse($context);

        if ($this->type) {
            $entities->where('folder', '=', $this->type);
        }

        $entities->order($this->sort);

        return $entities;
    }
773138
protected function _authorizeAction(AnCommandContext $context)
    {
        $method = '_authorize'.ucfirst($context->action);

        $ret = self::AUTH_NOT_IMPLEMENTED;

        if (method_exists($this, $method)) {
            $ret = $this->$method($context->resource);
        } elseif ($context->actor) {
            //check if it's enabled and assigned
            if ($this->_entity->isAssignable()) {
                $ret = $this->_entity->activeForActor($context->actor);
            }
        }

        return $ret;
    }
222204
public function getContext(TemplateContextInterface $context = null)
    {
        $context = new TemplateContext($context);
        $context->setData($this->getData());
        $context->setParameters($this->getParameters());

        return $context;
    }