New assurer challenge feature
authorMichael Tänzer <neo@nhng.de>
Thu, 1 Jul 2010 16:52:43 +0000 (18:52 +0200)
committerMichael Tänzer <neo@nhng.de>
Thu, 1 Jul 2010 16:52:43 +0000 (18:52 +0200)
Signed-off-by: Michael Tänzer <neo@nhng.de>
manager/application/controllers/ManageAccountController.php
manager/application/views/scripts/manage-account/assurer-challenge-form.phtml [new file with mode: 0644]
manager/application/views/scripts/manage-account/assurer-challenge.phtml [new file with mode: 0644]

index cc7efa0..c893a4b 100644 (file)
@@ -153,6 +153,35 @@ class ManageAccountController extends Zend_Controller_Action
         return;
     }
     
+    
+    public function assurerChallengeAction()
+    {
+        // Validate form
+        $form = $this->getAssurerChallengeForm();
+        if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
+            $this->view->assurer_challenge_form = $form;
+            return $this->render('assurer-challenge-form');
+        }
+        
+        // Form is valid -> get values for processing
+        $values = $form->getValues();
+        
+        // Get user data
+        $user['id'] = $this->getUserId();
+        
+        // Assign the assurer challenge
+        $challenge = array(); // Make sure the array is empty
+        $challenge['user_id'] = $user['id'];
+        $challenge['variant_id'] = $values['variant'];
+        $challenge['pass_date'] = date('Y-m-d H:i:s');
+        $this->db->insert('cats_passed', $challenge);
+        
+        // Maybe user is now assurer
+        $this->fixAssurerFlag($user['id']);
+        
+        return;
+    }
+    
     /**
      * Get and check the user ID of the current user
      * 
@@ -312,4 +341,27 @@ class ManageAccountController extends Zend_Controller_Action
         
         return $form;
     }
+    
+    protected function getAssurerChallengeForm()
+    {
+        $form = new Zend_Form();
+        $form->setAction('/manage-account/assurer-challenge')
+            ->setMethod('post');
+        
+        $variant = new Zend_Form_Element_Select('variant');
+        $variant->setLabel(I18n::_('Variant'));
+        // Get the available variants from the database
+        $query = 'select `id`, `test_text` from `cats_variant`
+            where `type_id` = 1';
+        $options = $this->db->fetchPairs($query);
+        $variant->setOptions($options)
+            ->setRequired(true);
+        $form->addElement($variant);
+        
+        $submit = new Zend_Form_Element_Submit('submit');
+        $submit->setLabel(I18n::_('Challenge Me'));
+        $form->addElement($submit);
+        
+        return $form;
+    }
 }
diff --git a/manager/application/views/scripts/manage-account/assurer-challenge-form.phtml b/manager/application/views/scripts/manage-account/assurer-challenge-form.phtml
new file mode 100644 (file)
index 0000000..54c56a8
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+/**
+ * @author Michael Tänzer
+ * @todo Text
+ */
+?>
+
+<?php print $this->assurer_challenge_form ?>
diff --git a/manager/application/views/scripts/manage-account/assurer-challenge.phtml b/manager/application/views/scripts/manage-account/assurer-challenge.phtml
new file mode 100644 (file)
index 0000000..32919db
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+/**
+ * @author Michael Tänzer
+ * @todo Text
+ */
+?>
+
+<h1><?php print I18n::_('Assurer challenge added successfully')?></h1>