Rename AddPoints to ManageAccount
authorMichael Tänzer <neo@nhng.de>
Mon, 28 Jun 2010 15:30:31 +0000 (17:30 +0200)
committerMichael Tänzer <neo@nhng.de>
Mon, 28 Jun 2010 15:30:31 +0000 (17:30 +0200)
The controller will contain all actions required to manage the test account

Signed-off-by: Michael Tänzer <neo@nhng.de>
manager/application/controllers/AddPointsController.php [deleted file]
manager/application/controllers/ManageAccountController.php [new file with mode: 0644]
manager/application/views/scripts/add-points/assurance.phtml [deleted file]
manager/application/views/scripts/add-points/assuranceform.phtml [deleted file]
manager/application/views/scripts/manage-account/assurance.phtml [new file with mode: 0644]
manager/application/views/scripts/manage-account/assuranceform.phtml [new file with mode: 0644]
manager/library/actions/ActionAddPoints.php [deleted file]
manager/library/actions/ActionManageAccount.php [new file with mode: 0644]

diff --git a/manager/application/controllers/AddPointsController.php b/manager/application/controllers/AddPointsController.php
deleted file mode 100644 (file)
index 95b524b..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-<?php
-/**
- * @author Michael Tänzer
- */
-
-class AddPointsController extends Zend_Controller_Action
-{
-    const MAX_POINTS_PER_ASSURANCE = 35;
-    const MAX_ASSURANCE_POINTS = 100;
-    
-    protected $db;
-    
-    public function init()
-    {
-        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',
-            APPLICATION_ENV);
-
-        $this->db = Zend_Db::factory($config->ca_mgr->db->auth->pdo,
-           $config->ca_mgr->db->auth);
-    }
-    
-    public function indexAction()
-    {
-        // Just render the view
-        return;
-    }
-    
-    public function assuranceAction()
-    {
-        // Validate form
-        $form = $this->getAssuranceForm();
-        if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
-            $this->view->assurance_form = $form;
-            return $this->render('assuranceform');
-        }
-        
-        // Form is valid -> get values for processing
-        $values = $form->getValues();
-        
-        
-        // Check identity of the user
-        $session = Zend_Registry::get('session');
-        if ($session->authdata['authed'] !== true) {
-            throw new Exception(__METHOD__ . ': you need to log in to use this feature');
-        }
-        $query = 'select `id` from `users` where `id` = :user';
-        $query_params['user'] = $session->authdata['authed_id'];
-        $result = $this->db->query($query, $query_params);
-        if ($result->rowCount() !== 1) {
-            throw new Exception(__METHOD__ . ': user ID not found in the data base');
-        }
-        $row = $result->fetch();
-        $user['id'] = $row['id'];
-        
-        
-        // Get current points of the user
-        $query = 'select sum(`points`) as `total` from `notary` where `to` = :user';
-        $query_params['user'] = $user['id'];
-        $row = $this->db->query($query, $query_params)->fetch();
-        if ($row['total'] === NULL) $row['total'] = 0;
-        $user['points'] = $row['total'];
-        
-        
-        // Do the actual assurances
-        $assurance = array(); // Make sure the array is empty
-        $assurance['to'] = $user['id'];
-        $assurance['location'] = $values['location'];
-        $assurance['date'] = $values['date'];
-        $assurance['when'] = new Zend_Db_Expr('now()');
-        $this->view->assurancesDone = array();
-        
-        $quantity = $values['quantity'];
-        do {
-            // split up into multiple assurances
-            if ($quantity > self::MAX_POINTS_PER_ASSURANCE) {
-                $assurance['awarded'] = self::MAX_POINTS_PER_ASSURANCE;
-                $quantity -= self::MAX_POINTS_PER_ASSURANCE;
-            } else {
-                $assurance['awarded'] = $quantity;
-                $quantity = 0;
-            }
-            
-            // Get the assurer for this assurance
-            $assurance['from'] = $this->getNewAssurer($user['id']);
-            
-            // only assign points whithin the limit
-            if ($user['points'] + $assurance['awarded'] > self::MAX_ASSURANCE_POINTS){
-                $assurance['points'] = self::MAX_ASSURANCE_POINTS - $user['points'];
-            } else {
-                $assurance['points'] = $assurance['awarded'];
-            }
-            
-            $this->db->insert('notary', $assurance);
-            
-            $user['points'] += $assurance['points'];
-            $this->view->assurancesDone[] = $assurance['points'];
-        } while ($quantity > 0);
-        
-        
-        // Fix the assurer flag
-        $query = 'UPDATE `users` SET `assurer` = 1 WHERE `users`.`id` = :user AND '.
-            
-            'EXISTS(SELECT * FROM `cats_passed` AS `cp`, `cats_variant` AS `cv` '.
-            'WHERE `cp`.`variant_id` = `cv`.`id` AND `cv`.`type_id` = 1 AND '.
-            '`cp`.`user_id` = :user) AND '.
-            
-                   '(SELECT SUM(`points`) FROM `notary` WHERE `to` = :user AND '.
-                   '`expire` < now()) >= 100';
-        $query_params['user'] = $user['id'];
-        $this->db->query($query, $query_params);
-        
-        return;
-    }
-    
-    /**
-     * Get the first assurer who didn't already assure the user
-     * 
-     * @param int $user_id The ID of the user who should get assured
-     * @return int The ID of the selected assurer
-     */
-    protected function getNewAssurer($user_id)
-    {
-        $query = 'select min(`id`) as `assurer` from `users` ' .
-               'where `email` like \'john.doe-___@example.com\' and ' .
-            '`id` not in (select `from` from `notary` where `to` = :user)';
-        $query_params['user'] = $user_id;
-        $row = $this->db->query($query, $query_params)->fetch();
-        
-        if ($row['assurer'] === NULL) {
-            throw new Exception(__METHOD__ . ': no more assurers that haven\'t '.
-                'already assured this account');
-        }
-        
-        return $row['assurer'];
-    }
-    
-    protected function getAssuranceForm()
-    {
-        $form = new Zend_Form();
-        $form->setAction('/add-points/assurance')->setMethod('post');
-        
-        $quantity = new Zend_Form_Element_Text('quantity');
-        $quantity->setRequired(true)
-                ->setLabel(I18n::_('Number of Points'))
-                ->addFilter(new Zend_Filter_Int())
-                ->addValidator(new Zend_Validate_Between(0, 100));
-        $form->addElement($quantity);
-        
-        $location = new Zend_Form_Element_Text('location');
-        $location->setRequired(true)
-                ->setLabel(I18n::_('Location'))
-                ->setValue(I18n::_('CAcert Test Manager'))
-                ->addValidator(new Zend_Validate_StringLength(1,255));
-        $form->addElement($location);
-        
-        $date = new Zend_Form_Element_Text('date');
-        $date->setRequired(true)
-            ->setLabel(I18n::_('Date of Assurance'))
-            ->setValue(date('Y-m-d H:i:s'))
-            ->addValidator(new Zend_Validate_StringLength(1,255));
-        $form->addElement($date);
-        
-        $submit = new Zend_Form_Element_Submit('submit');
-        $submit->setLabel(I18n::_('Assure Me'));
-        $form->addElement($submit);
-        
-        return $form;
-    }
-}
diff --git a/manager/application/controllers/ManageAccountController.php b/manager/application/controllers/ManageAccountController.php
new file mode 100644 (file)
index 0000000..0197fd8
--- /dev/null
@@ -0,0 +1,169 @@
+<?php
+/**
+ * @author Michael Tänzer
+ */
+
+class ManageAccountController extends Zend_Controller_Action
+{
+    const MAX_POINTS_PER_ASSURANCE = 35;
+    const MAX_ASSURANCE_POINTS = 100;
+    
+    protected $db;
+    
+    public function init()
+    {
+        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',
+            APPLICATION_ENV);
+
+        $this->db = Zend_Db::factory($config->ca_mgr->db->auth->pdo,
+           $config->ca_mgr->db->auth);
+    }
+    
+    public function indexAction()
+    {
+        // Just render the view
+        return;
+    }
+    
+    public function assuranceAction()
+    {
+        // Validate form
+        $form = $this->getAssuranceForm();
+        if (!$this->getRequest()->isPost() || !$form->isValid($_POST)) {
+            $this->view->assurance_form = $form;
+            return $this->render('assuranceform');
+        }
+        
+        // Form is valid -> get values for processing
+        $values = $form->getValues();
+        
+        
+        // Check identity of the user
+        $session = Zend_Registry::get('session');
+        if ($session->authdata['authed'] !== true) {
+            throw new Exception(__METHOD__ . ': you need to log in to use this feature');
+        }
+        $query = 'select `id` from `users` where `id` = :user';
+        $query_params['user'] = $session->authdata['authed_id'];
+        $result = $this->db->query($query, $query_params);
+        if ($result->rowCount() !== 1) {
+            throw new Exception(__METHOD__ . ': user ID not found in the data base');
+        }
+        $row = $result->fetch();
+        $user['id'] = $row['id'];
+        
+        
+        // Get current points of the user
+        $query = 'select sum(`points`) as `total` from `notary` where `to` = :user';
+        $query_params['user'] = $user['id'];
+        $row = $this->db->query($query, $query_params)->fetch();
+        if ($row['total'] === NULL) $row['total'] = 0;
+        $user['points'] = $row['total'];
+        
+        
+        // Do the actual assurances
+        $assurance = array(); // Make sure the array is empty
+        $assurance['to'] = $user['id'];
+        $assurance['location'] = $values['location'];
+        $assurance['date'] = $values['date'];
+        $assurance['when'] = new Zend_Db_Expr('now()');
+        $this->view->assurancesDone = array();
+        
+        $quantity = $values['quantity'];
+        do {
+            // split up into multiple assurances
+            if ($quantity > self::MAX_POINTS_PER_ASSURANCE) {
+                $assurance['awarded'] = self::MAX_POINTS_PER_ASSURANCE;
+                $quantity -= self::MAX_POINTS_PER_ASSURANCE;
+            } else {
+                $assurance['awarded'] = $quantity;
+                $quantity = 0;
+            }
+            
+            // Get the assurer for this assurance
+            $assurance['from'] = $this->getNewAssurer($user['id']);
+            
+            // only assign points whithin the limit
+            if ($user['points'] + $assurance['awarded'] > self::MAX_ASSURANCE_POINTS){
+                $assurance['points'] = self::MAX_ASSURANCE_POINTS - $user['points'];
+            } else {
+                $assurance['points'] = $assurance['awarded'];
+            }
+            
+            $this->db->insert('notary', $assurance);
+            
+            $user['points'] += $assurance['points'];
+            $this->view->assurancesDone[] = $assurance['points'];
+        } while ($quantity > 0);
+        
+        
+        // Fix the assurer flag
+        $query = 'UPDATE `users` SET `assurer` = 1 WHERE `users`.`id` = :user AND '.
+            
+            'EXISTS(SELECT * FROM `cats_passed` AS `cp`, `cats_variant` AS `cv` '.
+            'WHERE `cp`.`variant_id` = `cv`.`id` AND `cv`.`type_id` = 1 AND '.
+            '`cp`.`user_id` = :user) AND '.
+            
+                   '(SELECT SUM(`points`) FROM `notary` WHERE `to` = :user AND '.
+                   '`expire` < now()) >= 100';
+        $query_params['user'] = $user['id'];
+        $this->db->query($query, $query_params);
+        
+        return;
+    }
+    
+    /**
+     * Get the first assurer who didn't already assure the user
+     * 
+     * @param int $user_id The ID of the user who should get assured
+     * @return int The ID of the selected assurer
+     */
+    protected function getNewAssurer($user_id)
+    {
+        $query = 'select min(`id`) as `assurer` from `users` ' .
+               'where `email` like \'john.doe-___@example.com\' and ' .
+            '`id` not in (select `from` from `notary` where `to` = :user)';
+        $query_params['user'] = $user_id;
+        $row = $this->db->query($query, $query_params)->fetch();
+        
+        if ($row['assurer'] === NULL) {
+            throw new Exception(__METHOD__ . ': no more assurers that haven\'t '.
+                'already assured this account');
+        }
+        
+        return $row['assurer'];
+    }
+    
+    protected function getAssuranceForm()
+    {
+        $form = new Zend_Form();
+        $form->setAction('/add-points/assurance')->setMethod('post');
+        
+        $quantity = new Zend_Form_Element_Text('quantity');
+        $quantity->setRequired(true)
+                ->setLabel(I18n::_('Number of Points'))
+                ->addFilter(new Zend_Filter_Int())
+                ->addValidator(new Zend_Validate_Between(0, 100));
+        $form->addElement($quantity);
+        
+        $location = new Zend_Form_Element_Text('location');
+        $location->setRequired(true)
+                ->setLabel(I18n::_('Location'))
+                ->setValue(I18n::_('CAcert Test Manager'))
+                ->addValidator(new Zend_Validate_StringLength(1,255));
+        $form->addElement($location);
+        
+        $date = new Zend_Form_Element_Text('date');
+        $date->setRequired(true)
+            ->setLabel(I18n::_('Date of Assurance'))
+            ->setValue(date('Y-m-d H:i:s'))
+            ->addValidator(new Zend_Validate_StringLength(1,255));
+        $form->addElement($date);
+        
+        $submit = new Zend_Form_Element_Submit('submit');
+        $submit->setLabel(I18n::_('Assure Me'));
+        $form->addElement($submit);
+        
+        return $form;
+    }
+}
diff --git a/manager/application/views/scripts/add-points/assurance.phtml b/manager/application/views/scripts/add-points/assurance.phtml
deleted file mode 100644 (file)
index db45e0a..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/**
- * @author Michael Tänzer
- */
-?>
-
-<h1><?php print I18n::_('Points added successfully')?></h1>
-
-<p><?php print I18n::_('The following assurances were added to your account:')?></p>
-
-<table>
-       <thead>
-               <tr><th>#</th><th><?php print I18n::_('Number of points')?></th></tr>
-       </thead>
-       <tbody>
-               <?php foreach ($this->assurancesDone as $i => $points) {
-                   printf('<tr><td> %1$d </td><td> %2$d </td></tr>', $i, $points);
-               }?>
-       </tbody>
-</table>
diff --git a/manager/application/views/scripts/add-points/assuranceform.phtml b/manager/application/views/scripts/add-points/assuranceform.phtml
deleted file mode 100644 (file)
index b627b78..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-/**
- * @author Michael Tänzer
- */
-?>
-
-<h1><?php print I18n::_('Add Assurance Points to your Account') ?></h1>
-
-<h2><?php print I18n::_('Get Points by Automated Assurance') ?></h2>
-<p><?php print I18n::_('Assign the points by doing an automated assurance '.
-    'which looks just like a normal assurance done by a real person.') ?></p>
-<p><?php print I18n::_('If you enter more than 35 points they will be split '.
-    'into multiple assurances. You can do zero point assurances.') ?></p>
-<?php print $this->assurance_form ?>
diff --git a/manager/application/views/scripts/manage-account/assurance.phtml b/manager/application/views/scripts/manage-account/assurance.phtml
new file mode 100644 (file)
index 0000000..db45e0a
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+/**
+ * @author Michael Tänzer
+ */
+?>
+
+<h1><?php print I18n::_('Points added successfully')?></h1>
+
+<p><?php print I18n::_('The following assurances were added to your account:')?></p>
+
+<table>
+       <thead>
+               <tr><th>#</th><th><?php print I18n::_('Number of points')?></th></tr>
+       </thead>
+       <tbody>
+               <?php foreach ($this->assurancesDone as $i => $points) {
+                   printf('<tr><td> %1$d </td><td> %2$d </td></tr>', $i, $points);
+               }?>
+       </tbody>
+</table>
diff --git a/manager/application/views/scripts/manage-account/assuranceform.phtml b/manager/application/views/scripts/manage-account/assuranceform.phtml
new file mode 100644 (file)
index 0000000..b627b78
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+/**
+ * @author Michael Tänzer
+ */
+?>
+
+<h1><?php print I18n::_('Add Assurance Points to your Account') ?></h1>
+
+<h2><?php print I18n::_('Get Points by Automated Assurance') ?></h2>
+<p><?php print I18n::_('Assign the points by doing an automated assurance '.
+    'which looks just like a normal assurance done by a real person.') ?></p>
+<p><?php print I18n::_('If you enter more than 35 points they will be split '.
+    'into multiple assurances. You can do zero point assurances.') ?></p>
+<?php print $this->assurance_form ?>
diff --git a/manager/library/actions/ActionAddPoints.php b/manager/library/actions/ActionAddPoints.php
deleted file mode 100644 (file)
index ef71b2f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-
-require_once (FWACTIONS_PATH . '/FWAction.php');
-
-class AddPoints extends FWAction {
-       /**
-        * get a list of required permissions that are needed to access this action
-        * @return array
-        */
-       public static function getRequiredPermissions() {
-               return array();
-       }
-
-       /**
-        * get a role that is required for accessing that action
-        * @return string
-        */
-       public static function getRequiredRole() {
-               return 'User';
-       }
-
-       /**
-        * sort order for top navigation
-        * @return integer
-        */
-       public static function getTopNavPrio() {
-               return 50;
-       }
-
-       /**
-        * controller to invoke
-        * @return string
-        */
-       public static function getController() {
-               return 'add-points';
-       }
-
-       /**
-        * action to invoke
-        * @return string
-        */
-       public static function getAction() {
-               return 'index';
-       }
-
-       /**
-        * get text for menu, caller is responsible for translating
-        * @return string
-        */
-       public static function getMenuText() {
-               return 'Add Points';
-       }
-}
diff --git a/manager/library/actions/ActionManageAccount.php b/manager/library/actions/ActionManageAccount.php
new file mode 100644 (file)
index 0000000..30c8bb6
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+require_once (FWACTIONS_PATH . '/FWAction.php');
+
+class ManageAccount extends FWAction {
+       /**
+        * get a list of required permissions that are needed to access this action
+        * @return array
+        */
+       public static function getRequiredPermissions() {
+               return array();
+       }
+
+       /**
+        * get a role that is required for accessing that action
+        * @return string
+        */
+       public static function getRequiredRole() {
+               return 'User';
+       }
+
+       /**
+        * sort order for top navigation
+        * @return integer
+        */
+       public static function getTopNavPrio() {
+               return 50;
+       }
+
+       /**
+        * controller to invoke
+        * @return string
+        */
+       public static function getController() {
+               return 'manage-account';
+       }
+
+       /**
+        * action to invoke
+        * @return string
+        */
+       public static function getAction() {
+               return 'index';
+       }
+
+       /**
+        * get text for menu, caller is responsible for translating
+        * @return string
+        */
+       public static function getMenuText() {
+               return I18n::_('Manage Account');
+       }
+}