Kushal124 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/125372

Change subject: [WIP]Make review setting configurable
......................................................................

[WIP]Make review setting configurable

This commit adds Settings subclass for accessing review settings from database.
Bug: 58071

Change-Id: Ib37d14a069d56d32eaec86e11d17c5c5bc71b608
---
A data/db/migrations/20140411-01-congifurable-settings.mysql
M data/db/schema.mysql
M src/Wikimania/Scholarship/App.php
M src/Wikimania/Scholarship/Dao/Apply.php
A src/Wikimania/Scholarship/Dao/Settings.php
5 files changed, 92 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/wikimania-scholarships 
refs/changes/72/125372/1

diff --git a/data/db/migrations/20140411-01-congifurable-settings.mysql 
b/data/db/migrations/20140411-01-congifurable-settings.mysql
new file mode 100644
index 0000000..5d7a26b
--- /dev/null
+++ b/data/db/migrations/20140411-01-congifurable-settings.mysql
@@ -0,0 +1,17 @@
+-- Bug: 58071
+-- Add settings table 
+
+DROP TABLE IF EXISTS settings;
+CREATE TABLE IF NOT EXISTS settings (
+    id              INT(11) NOT NULL AUTO_INCREMENT
+  , settingName     VARCHAR(255) NOT NULL
+  , value           FLOAT(4,2) NOT NULL DEFAULT '0'
+  , entered_on      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+  , PRIMARY KEY (id)
+) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
+
+INSERT IGNORE INTO settings (settingName, value) VALUES
+ ('phase1pass',3)
+,('weightonwiki',0.5)
+,('weightoffwiki',0.2)
+,('weightinterest',0.3);
\ No newline at end of file
diff --git a/data/db/schema.mysql b/data/db/schema.mysql
index 95371ef..94972e7 100644
--- a/data/db/schema.mysql
+++ b/data/db/schema.mysql
@@ -330,3 +330,17 @@
 ,('ZA','South Africa','Sub-Saharan Africa')
 ,('ZM','Zambia','Sub-Saharan Africa')
 ,('ZW','Zimbabwe','Sub-Saharan Africa');
+
+CREATE TABLE IF NOT EXISTS settings (
+    id              INT(11) NOT NULL AUTO_INCREMENT
+  , settingName     VARCHAR(255) NOT NULL
+  , value           FLOAT(4,2) NOT NULL DEFAULT '0'
+  , entered_on      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+  , PRIMARY KEY (id)
+) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
+
+INSERT IGNORE INTO settings (settingName, value) VALUES
+ ('phase1pass',3)
+,('weightonwiki',0.5)
+,('weightoffwiki',0.2)
+,('weightinterest',0.3);
\ No newline at end of file
diff --git a/src/Wikimania/Scholarship/App.php 
b/src/Wikimania/Scholarship/App.php
index 4f739b6..af4b18d 100644
--- a/src/Wikimania/Scholarship/App.php
+++ b/src/Wikimania/Scholarship/App.php
@@ -142,17 +142,24 @@
                                $c->log );
                });
 
+               $container->singleton( 'settingsDao', function ( $c ) {
+                       return new \Wikimania\Scholarship\Dao\Settings(
+                               $c->settings['db.dsn'],
+                               $c->settings['db.user'], 
$c->settings['db.pass'],
+                               $c->log );
+               });
+
                $container->singleton( 'authManager', function ( $c ) {
                        return new \Wikimania\Scholarship\AuthManager( 
$c->userDao );
                });
 
                $container->singleton( 'applyDao', function ( $c ) {
                        $uid = $c->authManager->getUserId();
-                       // FIXME: pass in settings
+                       $settings = $c->settingsDao->getSettings();
                        return new \Wikimania\Scholarship\Dao\Apply(
                                $c->settings['db.dsn'],
                                $c->settings['db.user'], 
$c->settings['db.pass'],
-                               $uid, null, $c->log );
+                               $uid, $settings, $c->log );
                });
 
                $container->singleton( 'wgLang', function ( $c ) {
diff --git a/src/Wikimania/Scholarship/Dao/Apply.php 
b/src/Wikimania/Scholarship/Dao/Apply.php
index f3456ee..63ccf13 100644
--- a/src/Wikimania/Scholarship/Dao/Apply.php
+++ b/src/Wikimania/Scholarship/Dao/Apply.php
@@ -41,12 +41,8 @@
        /**
         * @var array $settings
         */
-       protected $settings = array(
-               'phase1pass'     => 3,     // p1score needed to pass into phase2
-               'weightonwiki'   => 0.5,   // contribution of onwiki to final 
score
-               'weightoffwiki'  => 0.2,   // contribution of offwiki to final 
score
-               'weightinterest' => 0.3,   // contribution of interest to final 
score
-       );
+       protected $settings = array();
+
 
 
        /**
@@ -58,12 +54,13 @@
         * @param LoggerInterface $logger Log channel
         */
        public function __construct( $dsn, $user, $pass,
-               $uid = false, $settings = null, $logger = null
+               $uid = false, $settings, $logger = null
        ) {
                parent::__construct( $dsn, $user, $pass, $logger );
                $this->userid = $uid;
                $settings = is_array( $settings ) ? $settings : array();
                $this->settings = array_merge( $this->settings, $settings );
+               $this->logger->debug( print_r( $this->settings, true ) );
        }
 
 
diff --git a/src/Wikimania/Scholarship/Dao/Settings.php 
b/src/Wikimania/Scholarship/Dao/Settings.php
new file mode 100644
index 0000000..5e946bc
--- /dev/null
+++ b/src/Wikimania/Scholarship/Dao/Settings.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * @section LICENSE
+ * This file is part of Wikimania Scholarship Application.
+ *
+ * Wikimania Scholarship Application is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Wikimania Scholarship Application is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Wikimania Scholarship Application.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * @file
+ */
+
+namespace Wikimania\Scholarship\Dao;
+
+/**
+ * Data access object for Admin Settings in scholarship applications.
+ */
+class Settings extends AbstractDao {
+
+       /**
+        * @var array $settings
+        */
+       protected $settings = array();
+
+
+       /**
+        * @return array Settings from DB
+        */
+       
+       public function getSettings(){           
+               $records = $this->fetchAll( 'SELECT settingName,value  FROM 
settings' );                
+                       foreach ( $records as $idx => $row ) {
+                               $settings[ $row[ 'settingName' ] ] = $row[ 
'value'  ];
+                       }
+               return $settings;
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/125372
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib37d14a069d56d32eaec86e11d17c5c5bc71b608
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/wikimania-scholarships
Gerrit-Branch: master
Gerrit-Owner: Kushal124 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to