Exemple #1
0
 private function processForm()
 {
     $context = array(AMForm::kDataKey => $_POST);
     $form = AMForm::formWithContext($context);
     switch ($form->context) {
         case 'Update':
             $this->processUpdate($form);
             break;
         case 'Delete':
             $this->processDelete($form);
             break;
     }
 }
Exemple #2
0
 protected function initialize()
 {
     $context = array(AMForm::kDataKey => $_GET);
     $form = AMForm::formWithContext($context);
     $form->addValidator(new ApplicationIdValidator('id', true, 'Invalid application id'));
     if ($form->isValid) {
         $id = $_GET['id'];
         $applications = Renegade::database(RenegadeConstants::kDatabaseMongoDB, RenegadeConstants::kDatabaseApplications);
         $app = $applications->findOne(array('_id' => $id, 'owner' => $this->session->user));
         if (!$app) {
             Renegade::redirect('/applications');
         }
         $this->application = $app;
     } else {
         Renegade::redirect('/applications');
     }
 }
require $_SERVER['DOCUMENT_ROOT'] . '/application/lib/axismundi/forms/validators/AMInputValidator.php';
require $_SERVER['DOCUMENT_ROOT'] . '/application/forms/validators/UniqueChannelValidator.php';
require $_SERVER['DOCUMENT_ROOT'] . '/application/forms/validators/ApplicationIdValidator.php';
function form_prepare(&$item, $key)
{
    $item = trim($item);
    if ($key == 'inputId') {
        $item = strtolower($item);
    }
}
if (count($_POST)) {
    $session = Renegade::session();
    if (strlen($session->user) > 0) {
        array_walk($_POST, 'form_prepare');
        $context = array(AMForm::kDataKey => $_POST);
        $form = AMForm::formWithContext($context);
        $form->addValidator(new AMInputValidator('inputName', true, 4, null, 'Channel Name must be at least 4 characters long'));
        $form->addValidator(new AMPatternValidator('inputName', true, '/^[\\w ]+$/', 'Application Name may only container letters, numbers, spaces or _'));
        $form->addValidator(new AMPatternValidator('inputType', true, '/^forum$/', 'Invalid Application Type'));
        $form->addValidator(new ApplicationIdValidator('inputId', true, 'Invalid application id.  Please use reverse domain name style starting with com, net, org or edu e.g., com.galaxy.community'));
        /*$form->addValidator(new ApplicationIdValidator('inputUrl', true, 'Invalid application id.  Please use reverse domain name style starting with com, net, org or edu e.g., com.galaxy.community'));*/
        /*
        	TODO Need to create an AMUrlValidator
        */
        if ($form->isValid) {
            // The data for an application is sored in MongoDB, the rest is in Redis
            /* this is a 2 part process
            				Part 1: We need to create the auth info for the application
            				because this will be being used for access, and potentially MANY calls
            				it has to be fast, so we will store the auth token in Redis.
            				
Exemple #4
0
 public static function formWithContext($context)
 {
     $form = new AMForm();
     $form->setContext($context);
     return $form;
 }
Exemple #5
0
 public function topics_put(GalaxyContext $context)
 {
     // anything incoming as a PUT will be coming in as JSON
     $data = json_decode(file_get_contents('php://input'), true);
     // artifically add the author name for validation purposes
     $data['author_name'] = $data['author']['name'];
     $form_context = array(AMForm::kDataKey => $data);
     $form = AMForm::formWithContext($form_context);
     $form->addValidator(new AMInputValidator('author_name', AMValidator::kRequired, 1, null, 'author name required'));
     $form->addValidator(new AMInputValidator('title', AMValidator::kRequired, 1, null, 'title required'));
     $form->addValidator(new AMInputValidator('body', AMValidator::kRequired, 1, null, 'body required'));
     if ($form->isValid) {
         $status_topic = false;
         $status_message = false;
         $options = array('default' => GalaxyAPI::databaseForId($context->application));
         $channel = GalaxyAPI::database(GalaxyAPIConstants::kDatabaseMongoDB, GalaxyAPI::databaseForId($context->channel), $options);
         $topic = GalaxyForumTopic::topicWithContext($context);
         $topic->setTitle($data['title']);
         $topic->setAuthor($data['author']);
         $topic = $topic->data();
         $status_topic = $channel->insert($topic, true);
         if ($status_topic['ok']) {
             $message = GalaxyForumMessage::messageWithContext($context);
             $message->setTitle($data['title']);
             $message->setBody($data['body']);
             $message->setAuthor($data['author']);
             $message->setTopicOrigin(true);
             $message->setTopic($topic['_id']);
             $last_message = $message->last_message_snapshot();
             $message = $message->data();
             $status_message = $channel->insert($message, true);
             if ($status_message['ok']) {
                 // we can get the message id, and omit this update, but then if the topic set fails we will be left with an orphaned document
                 $channel->update(array('_id' => $topic['_id']), array('$set' => array('origin_message_id' => $message['_id'], 'last_message' => $last_message)));
             }
         }
         $data = array('topic' => array('status' => $status_topic['ok'] ? true : false, 'id' => $topic['_id']), 'message' => array('status' => $status_message['ok'] ? true : false, 'id' => $message['_id']));
         return GalaxyResponse::responseWithData($data);
     } else {
         return GalaxyResponse::errorResponseWithForm($form);
     }
 }