Skip to content
Browse files

Feature #37

  • Loading branch information...
1 parent 64e4883 commit 3fbc59e620abc48326c20a63e013be1a44d364e3 @danielBingham committed Feb 27, 2012
View
32 application/controllers/AdminController.php
@@ -0,0 +1,32 @@
+<?php
+
+class AdminController extends Zend_Controller_Action {
+
+ // {{{ indexAction()
+
+ public function indexAction() {
+ if(!Zend_Auth::getInstance()->hasIdentity()) {
+ return $this->_helper->redirector('login', 'user');
+ }
+
+ if(Zend_Auth::getInstance()->getIdentity()->isAdmin == false) {
+ throw new RuntimeException('Only admin may view this page.');
+ }
+
+
+ $config = new Application_Service_Configuration();
+
+ if($this->getRequest()->isPost()) {
+ foreach($this->getRequest()->getPost() as $name=>$value) {
+ $config->set($name, $value);
+ }
+ }
+
+ $this->view->configurations = $config->getConfigurationList();
+ }
+
+ // }}}
+
+}
+
+?>
View
7 application/data/dummy.sql
@@ -92,4 +92,9 @@ INSERT INTO `users`
(2,'buyer@theroadgoeson.com','3be928357bda6967870bcd8afb400365',0),
(3,'dbingham@theroadgoeson.com','340511c3c30e3e06e28257e6980af6e9',1);
-
+INSERT INTO `configurations`
+ VALUES (1, 'paypal_username', ''), /* blank for commitment purposes */
+ (2, 'paypal_password', ''), /* blank for commitment purposes */
+ (3, 'paypal_signature', ''), /* blank for commitment purposes */
+ (4, 'paypal_version', '86.0'),
+ (5, 'paypal_test', 'true');
View
9 application/data/schema.sql
@@ -13,6 +13,7 @@ CREATE TABLE `users` (
`email` varchar(255),
`password` varchar(32),
`isGrower` tinyint,
+ `isAdmin` tinyint,
PRIMARY KEY (`id`),
KEY `email` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;
@@ -112,7 +113,13 @@ CREATE TABLE `product_tags` (
KEY `productID` (`productID`)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;
-
+CREATE TABLE `configurations` (
+ `id` int unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(255),
+ `value` varchar(1024),
+ PRIMARY KEY (`id`),
+ KEY `name` (`name`)
+) ENGINE=MyISAM DEFAULT CHARSET=UTF8;
View
15 application/models/Builder/Configuration.php
@@ -0,0 +1,15 @@
+<?php
+
+class Application_Model_Builder_Configuration extends Application_Model_Builder_Abstract {
+
+ // {{{ __construct()
+
+ public function __construct() {
+ $this->_haveBuilt = array();
+ }
+
+ // }}}
+
+}
+
+?>
View
15 application/models/Configuration.php
@@ -0,0 +1,15 @@
+<?php
+
+class Application_Model_Configuration extends Application_Model_Abstract {
+
+ // {{{ __construct($lazy=true)
+
+ public function __construct($lazy=true) {
+ parent::__construct('Configuration', array('id', 'name', 'value'), $lazy);
+ }
+
+ // }}}
+
+}
+
+?>
View
9 application/models/DbTable/Configuration.php
@@ -0,0 +1,9 @@
+<?php
+
+class Application_Model_DbTable_Configuration extends Zend_Db_Table_Abstract {
+ protected $_name = 'configurations';
+
+
+}
+
+?>
View
64 application/models/Persistor/Configuration.php
@@ -0,0 +1,64 @@
+<?php
+
+class Application_Model_Persistor_Configuration extends Application_Model_Persistor_Abstract {
+ private $_mapper;
+
+ // {{{ getMapper(): protected Application_Model_Mapper_Configuration
+
+ protected function getMapper() {
+ if(empty($this->_mapper)) {
+ $this->_mapper = new Application_Model_Mapper_Configuration();
+ }
+ return $this->_mapper;
+ }
+
+ // }}}
+ // {{{ clear(Application_Model_Configuration $configuration): protected void
+
+ protected function clear(Application_Model_Configuration $configuration) {
+ // TODO: write me?
+ }
+
+ // }}}
+
+ // {{{ save(Application_Model_Configuration $configuration): public void
+
+ public function save(Application_Model_Configuration $configuration) {
+ if($configuration->id !== false) {
+ $this->update($configuration);
+ } else {
+ $this->insert($configuration);
+ }
+ }
+
+ // }}}
+
+ // {{{ delete(Application_Model_Configuration $configuration): public void
+
+ public function delete(Application_Model_Configuration $configuration) {
+ parent::deleteRaw($configuration->id);
+ }
+
+ // }}}
+ // {{{ insert(Application_Model_Configuration $configuration): protected void
+
+ protected function insert(Application_Model_Configuration $configuration) {
+ $data = $this->getMapper()->toDbArray($configuration);
+ $configuration->id = parent::insertRaw($data);
+ }
+
+ // }}}
+ // {{{ update(Application_Model_Configuration $configuration): protected void
+
+ protected function update(Application_Model_Configuration $configuration) {
+ $data = $this->getMapper()->toDbArray($configuration);
+ parent::updateRaw($data, $configuration->id);
+ }
+
+ // }}}
+
+
+
+}
+
+?>
View
15 application/models/Query/Configuration.php
@@ -0,0 +1,15 @@
+<?php
+
+class Application_Model_Query_Configuration extends Application_Model_Query_Abstract {
+ protected $_model='Configuration';
+ protected static $_instance;
+
+ public static function getInstance() {
+ return parent::getInstanceForModel('Configuration');
+ }
+
+
+
+}
+
+?>
View
2 application/models/User.php
@@ -8,7 +8,7 @@ class Application_Model_User extends Application_Model_Abstract {
// {{{ __construct($lazy=true)
public function __construct($lazy=true) {
- parent::__construct('User', array('id', 'email','password', 'isGrower'), $lazy);
+ parent::__construct('User', array('id', 'email','password', 'isGrower', 'isAdmin'), $lazy);
}
// }}}
View
20 application/models/mappers/Configuration.php
@@ -0,0 +1,20 @@
+<?php
+
+class Application_Model_Mapper_Configuration extends Application_Model_Mapper_Abstract {
+
+ // Standard Mapper API
+ // {{{ getDbTable(): public Application_Model_DbTable_Configuration
+
+ public function getDbTable() {
+ if(empty($this->_dbTable)) {
+ $this->_dbTable = new Application_Model_DbTable_Configuration();
+ }
+ return $this->_dbTable;
+ }
+
+ // }}}
+
+
+}
+
+?>
View
49 application/services/Configuration.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+* Service to handle configuration options so that we can simply call "get"
+* and "set" on the service and not worry to much about what's happening in the
+* model underneath.
+*
+*/
+class Application_Service_Configuration {
+
+ // {{{ get($name): public string
+
+ public function get($name) {
+ $config = Application_Model_Query_Configuration::getInstance()->findOne(array('name'=>$name));
+ if($config !== null) {
+ return $config->value;
+ } else {
+ throw new RuntimeException('Invalid configuration.');
+ }
+ }
+
+ // }}}
+ // {{{ set($name, $value): public $this
+
+ public function set($name, $value) {
+ $config = Application_Model_Query_Configuration::getInstance()->findOne(array('name'=>$name));
+
+ if($config === null) {
+ throw new RuntimeException('Invalid configuration.');
+ }
+
+ $config->value = $value;
+
+ $persistor = new Application_Model_Persistor_Configuration();
+ $persistor->save($config);
+ return $this;
+ }
+
+ // }}}
+ // {{{ getConfigurationList(): public array(Application_Model_Configuration)
+
+ public function getConfigurationList() {
+ return Application_Model_Query_Configuration::getInstance()->fetchAll();
+ }
+
+ // }}}
+}
+
+?>
View
12 application/views/scripts/admin/index.phtml
@@ -0,0 +1,12 @@
+<div id="adminIndex">
+ <form method="POST" action="/admin">
+ <table id="configuration">
+ <?php foreach($this->configurations as $config) { ?>
+ <tr><td><?php echo $config->name; ?></td><td><input type="text" name="<?php echo $config->name; ?>" value="<?php echo $config->value; ?>"</td></tr>
+ <?php } ?>
+ </table>
+ <input type="submit" value="Change Configuration" />
+ </form>
+
+
+</div>
View
6 application/views/scripts/customer/register.phtml
@@ -1,4 +1,10 @@
<div id="customerRegister">
+
+ <div id="errors">
+ <?php foreach($this->errors as $error) { ?>
+ <p><?php echo $error; ?></p>
+ <?php } ?>
+ </div>
<form method="POST" action="<?php echo $this->url(); ?>">
<label for="email">Email</label><input type="text" name="email" /><br />
<label for="password">Password</label><input type="password" name="password" /><br />
View
3 application/views/scripts/user/login.phtml
@@ -1,5 +1,6 @@
<div id="userLogin">
- <p>Don't have a grower account yet? Then click here to register: <a href="/grower/register">Register</a>.</p>
+ <p>Don't have an account yet? Register as a customer here: <a href="/customer/register">Customer Signup</a>.</p>
+ <p>Are you a grower? Regsiter for a grower account here: <a href="/grower/regsiter">Grower Signup</a>.</p>
<form method="POST" action="/user/login">
<input type="text" name="email" value="" />
<input type="password" name="password" value="" />

0 comments on commit 3fbc59e

Please sign in to comment.
Something went wrong with that request. Please try again.