Add Action.

@param AnCommandContext $context Context parameter

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

        return $this->getItem();
    }
1038367
protected function _afterEntityInsert(AnCommandContext $context)
    {
        if ($this->isOwnable() && $this->owner->isNotifiable() && !$this->owner->eql($this->author)) {
            $this->addSubscriber($this->owner);
        } elseif (!empty($this->author)) {
            $this->addSubscriber($this->author);
        }
    }
641728
protected function _actionDelete(AnCommandContext $context)
    {
        $this->getResponse()->status = AnHttpResponse::NO_CONTENT;

        $token = $this->getService('repos:connect.session')->fetchSet(array(
                        'owner' => $this->actor,
                        'api' => $this->getAPI()->getName(),
                    ));

        $token->delete()->save();
    }
911885
protected function _actionEdit(AnCommandContext $context)
    {
        $data = $context->data;

        dispatch_plugin('user.onBeforeEditPerson', array('data' => $context->data));

        //dont' set the usertype yet, until we find the conditions are met
        $usertype = null;

        if ($data->usertype) {
            $usertype = $data->usertype;
            unset($context->data->usertype);
        }

        if ($data->password) {
            $_SESSION['reset_password_prompt'] = 0;
        }

        $person = parent::_actionEdit($context);

        //add the validations here
        $this->getRepository()
        ->getValidator()
        ->addValidation('givenName', 'required')
        ->addValidation('familyName', 'required')
        ->addValidation('username', 'uniqueness')
        ->addValidation('email', 'uniqueness');

        if ($person->validate() === false) {
            throw new AnErrorException($person->getErrors(), AnHttpResponse::BAD_REQUEST);
        }

        //now check to see if usertype can be set, otherwise the value is unchanged
        if (in_array($usertype, $this->_allowed_user_types) && $person->authorize('changeUsertype')) {
            $person->usertype = $usertype;
        }

        $person->timestamp();

        dispatch_plugin('user.onAfterEditPerson', array('person' => $person));

        $this->setMessage('LIB-AN-PROMPT-UPDATE-SUCCESS', 'success');

        $edit = ($data->password && $data->username) ? 'account' : $this->_request->edit;
        $url = sprintf($person->getURL(false)."&get=settings&edit=%s", $edit);
        $context->response->setRedirect(route($url));

        return $person;
    }
1354040
protected function _actionAddrequest(AnCommandContext $context)
    {
        if ($this->getItem()->eql($this->actor)) {
            throw new LibBaseControllerExceptionForbidden('Forbidden');
        }

        $this->getResponse()->status = AnHttpResponse::RESET_CONTENT;
        $this->getItem()->addRequester($this->actor);
        $this->createNotification(array(
            'subject' => $this->actor,
            'target' => $this->getItem(),
            'name' => 'actor_request',
          ));

        return $this->getItem();
    }
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;
    }
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();
    }
895649
protected function _actionBrowse(AnCommandContext $context)
    {
        $exclude = array(
          'base',
          'system',
          '.',
          '..',
          '.DS_Store'
        );

        $aliases = array_diff(scandir(ANPATH_THEMES), $exclude);
        $items = array();

        foreach ($aliases as $alias) {
            if ($item = $this->getService('com:settings.domain.entity.template')->load($alias)) {
               $items[] = $item;
            }
        }

        $this->getView()->set('items', $items);
    }
912074
final public function execute($action, AnCommandContext $context)
    {
        $method = '_'.AnInflector::variablize('authorize.'.$action);

        $result = self::AUTH_NOT_IMPLEMENTED;

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

        return $result;
    }
614091
protected function _actionAdd(ControllerContext $context)
    {
        $entity = $context->entity;

        //Only throw an error if the action explicitly failed.
        if($entity->save() === false)
        {
            $error = $entity->getStatusMessage();
            throw new ControllerExceptionActionFailed($error ? $error : 'Add Action Failed');
        }
        else
        {
            if ($entity instanceof ModelEntityInterface)
            {
                $url = clone $context->request->getUrl();

                if ($this->getModel()->getState()->isUnique())
                {
                    $states = $this->getModel()->getState()->getValues(true);

                    foreach ($states as $key => $value) {
                        $url->query[$key] = $entity->getProperty($key);
                    }
                }
                else $url->query[$entity->getIdentityKey()] = $entity->getProperty($entity->getIdentityKey());

                $context->response->headers->set('Location', (string) $url);
                $context->response->setStatus(HttpResponse::CREATED);
            }
        }

        return $entity;
    }
427147
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->administrable->getRepository()
                            ->getBehavior('administrable')
                            ->resetStats(array(
                              $this->administrable,
                              $this->administrator, ));
    }
847912
protected function _actionPost(AnCommandContext $context)
    {
        $context->append(array(
            'data' => AnRequest::get('post', 'raw', array()),
        ));

        //backward compatiblity
        if ($context->data['action']) {
            $context->data['_action'] = $context->data['action'];
        }

        $action = 'post';

        if ($context->data['_action']) {
            $action = $context->data['_action'];
            if (in_array($action, array('browse', 'read', 'display'))) {
                throw new LibBaseControllerExceptionMethodNotAllowed('Action: '.$action.' not allowed');
            }
        }

        if ($context->request->getFormat() == 'json' || $context->request->isAjax()) {
            $this->registerCallback('after.post', array($this, 'forward'));
        } else {
            $context->response->setRedirect(AnRequest::get('server.HTTP_REFERER', 'url'));
        }

        return $this->getController()->execute($action, $context);
    }
25211
protected function _actionEditcomment(AnCommandContext $context)
    {
        $data = $context->data;
        $comment = $this->getCommentController()->id($this->cid)->edit(array('body' => $data->body));
        $context->comment = $comment;

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

        return $comment;
    }
72644
protected function _actionOptions(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::OK;
        $context->response->set('Content-Length', 0);
    }
1058344
public function redirect(AnCommandContext $context)
    {
        if ($context->action === 'edit' || $context->action === 'add') {
            $context->response->setRedirect(route($this->getItem()->getURL().'&layout=edit'));
        } else {
            return parent::redirect($context);
        }
    }
1006533
protected function _actionAddsubscriber(AnCommandContext $context)
    {
        if ($subscription = $this->_subscriber->subscribeTo($this->getItem())) {
            $subscription->endDate = $context->data->endDate;
        }
    }
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;
    }