Starting with setting up database tables
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 26 Nov 2014 16:00:49 +0000 (11:00 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 26 Nov 2014 16:00:49 +0000 (11:00 -0500)
setup hooks for activation db updates and uninstall

controllers/admin.php [new file with mode: 0644]
glm-members.php
models/database.php [new file with mode: 0644]

diff --git a/controllers/admin.php b/controllers/admin.php
new file mode 100644 (file)
index 0000000..321fe8a
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * admin.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+
+/**
+ * Gaslight Members Admin Controller
+ *
+ * Controller for all admin
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class admin
+{
+    public $wpdb;
+
+    public function __construct($wpdb)
+    {
+        $this->wpdb = $wpdb;
+    }
+}
index a33e6e6..f2023b1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-Plugin Name: Members
+Plugin Name: Gaslight Media Members
 Plugin URI:
 Description: Gaslight Media Members Database Plugin
 Version: 1.0.0
@@ -9,3 +9,15 @@ Author URI:
 License: Gaslght Media All Rights Reserved
 */
 
+define('GLM_MEMBERS_VERSION', '1.0');
+define('GLM_MEMBERS_VRS_OPTION_NAME', 'glm_member_db_version');
+define('GLM_MEMBERS_MEMBER_TABLE', 'members');
+define('GLM_MEMBERS_LOCATION_TABLE', 'locations');
+define('GLM_MEMBERS_CONTACT_TABLE', 'contacts');
+define('GLM_MEMBERS_REGION_TABLE', 'regions');
+define('GLM_MEMBERS_COUNTY_TABLE', 'counties');
+define('GLM_MEMBERS_CITY_TABLE', 'cities');
+define('GLM_MEMBERS_PLUGIN_FILE_PATH', __FILE__);
+
+require_once 'models/database.php';
+$glm_member_db = new glm_members_models_database($GLOBALS['wpdb']);
diff --git a/models/database.php b/models/database.php
new file mode 100644 (file)
index 0000000..569fdef
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * database.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+
+/**
+ * Toolkit_Package_database
+ *
+ * Description of database
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class glm_members_models_database
+{
+    public $wpdb;
+    public $membersTable;
+    public $locationTable;
+    public $contactTable;
+    public $regionTable;
+    public $countyTable;
+    public $cityTable;
+
+    public function __construct($wpdb)
+    {
+        $this->wpdb = $wpdb;
+        register_activation_hook(
+            GLM_MEMBERS_PLUGIN_FILE_PATH,
+            array($this, 'install')
+        );
+        register_uninstall_hook(
+            GLM_MEMBERS_PLUGIN_FILE_PATH,
+            array($this, 'delete')
+        );
+        add_action('plugins_loaded', array($this, 'glm_members_update_db_check'));
+
+        $this->membersTable  = $this->wpdb->prefix . GLM_MEMBERS_MEMBER_TABLE;
+        $this->locationTable = $this->wpdb->prefix . GLM_MEMBERS_LOCATION_TABLE;
+        $this->contactTable  = $this->wpdb->prefix . GLM_MEMBERS_CONTACT_TABLE;
+        $this->regionTable   = $this->wpdb->prefix . GLM_MEMBERS_REGION_TABLE;
+        $this->countyTable   = $this->wpdb->prefix . GLM_MEMBERS_COUNTY_TABLE;
+        $this->cityTable     = $this->wpdb->prefix . GLM_MEMBERS_CITY_TABLE;
+    }
+
+    public function install()
+    {
+
+
+        $charset_collate = $this->wpdb->get_charset_collate();
+
+        $sql = "CREATE TABLE {$this->membersTable} (
+            id mediumint(9) NOT NULL AUTO_INCREMENT,
+            create_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
+            name text NOT NULL,
+            url text DEFAULT '' NOT NULL,
+            join_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
+            phone text DEFAULT '' NOT NULL,
+            logo text DEFAULT '' NOT NULL,
+            UNIQUE KEY id (id)
+            ) {$charset_collate}";
+        include ABSPATH . 'wp-admin/includes/upgrade.php';
+        dbDelta($sql);
+
+        update_option(GLM_MEMBERS_VRS_OPTION_NAME, GLM_MEMBERS_VERSION);
+    }
+
+    public function glm_members_update_db_check()
+    {
+        if (GLM_MEMBERS_VERSION != get_option(GLM_MEMBERS_VRS_OPTION_NAME)) {
+            $this->install();
+        }
+    }
+
+    public function delete()
+    {
+        $sql = "
+        DROP TABLE IF EXISTS {$this->membersTable} ";
+        $this->wpdb->query($sql);
+        delete_option(GLM_MEMBERS_VRS_OPTION_NAME);
+    }
+
+}