fix some issues with git
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Nov 2014 15:29:17 +0000 (10:29 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Nov 2014 15:29:17 +0000 (10:29 -0500)
controllers/admin.php
controllers/front.php [new file with mode: 0644]
glm-employment.php
models/job.php
views/jobList.php [new file with mode: 0644]
views/jobListOverview.php [new file with mode: 0644]
views/job_meta.php [new file with mode: 0644]

index b15d6e9..a824dda 100644 (file)
 <?php
+
 namespace Glm\Employment\Controller;
+use Glm\Employment\Model as Model;
+
 defined('ABSPATH') or die();
 
+/**
+ * AdminConroller
+ *
+ * Controller for all of the admin functionality
+ */
 class AdminController
 {
-    const TABLE_NAME = 'emp_app';
-    const DB_OPTION  = 'glm_emp_db_version';
-    const DB_VERSION = '1.2';
-
-    public function initalizeActivationHooks()
-    {
-        \register_activation_hook(
-            'glm-employment/glm-employment.php',
-            array($this, 'installApplication')
-        );
-        \register_activation_hook(
-            'glm-employment/glm-employment.php',
-            array($this, 'initializeData')
-        );
-        \add_action('plugins_loaded', array($this, 'pluginUpdateDbCheck'));
-        \add_action('admin_menu', array($this, 'adminMenuSetup'));
-    }
-
-    public function adminMenuSetup()
-    {
-        add_menu_page(
-            'My Page Title',
-            'GLM Jobs',
-            'edit_posts',
-            'glmjobs',
-            array($this, 'overview'),
-            'dashicons-businessman'
-        );
-        add_submenu_page(
-            'glmjobs',
-            'Add New Job',
-            'Add New Job',
-            'edit_posts',
-            'glmjobs_addjob',
-            array($this, 'addjob')
-        );
-    }
-
-    public function overview()
-    {
-        $jobListTable = new \listJobs();
-        $jobListTable->prepare_items();
-    ?>
-    <div class="wrap">
-
-        <div id="icon-users" class="icon32"><br/></div>
-        <h2>List Jobs</h2>
-
-        <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
-        <form id="movies-filter" method="get">
-            <!-- For plugins, we also need to ensure that the form posts back to our current page -->
-            <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
-            <!-- Now we can render the completed list table -->
-            <?php $jobListTable->display() ?>
-        </form>
-
-    </div>
-    <?php
-    }
 
-    public function addjob()
-    {
-        echo '<div class="wrap">Add Job</div>';
-    }
+    public $pluginDirName;
 
-    public function installApplication()
+    /**
+     * Register Hooks and Actions
+     */
+    public function __construct($path)
     {
-        global $wpdb;
-
-        $tableName = $wpdb->prefix . SELF::TABLE_NAME;
-
-        $charset_collate = '';
-
-        if (!empty($wpdb->charset)) {
-            $charset_collate .= "DEFAULT CHARACTER SET {$wpdb->charset}";
-        }
-
-        if (!empty($wpdb->collate)) {
-            $charset_collate .= " COLLATE {$wpdb->collate}";
-        }
-
-        $sql = "CREATE TABLE {$tableName} (
-            id mediumint (9) NOT NULL AUTO_INCREMENT,
-            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
-            name text NOT NULL,
-            description text,
-            qualifications text,
-            benefits text,
-            primary_shift text,
-            comments text,
-            expire_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
-            pay_grade text,
-            job_code text,
-            status text,
-            active bool DEFAULT 0,
-            hr_contact text,
-            hr_phone text,
-            hr_email text,
-            UNIQUE KEY id (id)
-        ) $charset_collate;";
-
-        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
-        \dbDelta($sql);
-
-        \update_option(SELF::DB_OPTION, SELF::DB_VERSION);
+        $this->pluginDirName = $path;
+//        \add_shortcode('glmjobs', array($this, 'glm_jobs'));
+        $jobs = new Model\Job($path);
     }
 
-    public function initializeData()
+    public function glm_jobs($atts)
     {
+        extract(\shortcode_atts(array('limit' => '10'), $atts));
         global $wpdb;
-
-        $tableName = $wpdb->prefix . SELF::TABLE_NAME;
-
-        $testData         = array(
-            'time'        => \current_time('mysql'),
-            'name'        => 'Test 1',
-            'expire_date' => '2015-02-12 00:00:00'
-        );
-        $wpdb->insert(
-            $tableName,
-            $testData
-        );
+        $sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'glm_jobs'";
+        $jobs = $wpdb->get_results($sql, OBJECT);
+        \ob_start();
+        include $this->pluginDirName . 'views/jobList.php';
+        $out = \ob_get_contents();
+        \ob_end_clean();
+        return $out;
     }
 
-    public function pluginUpdateDbCheck()
+    public function setPluginDir($dir)
     {
-        if (\get_option(SELF::DB_OPTION) != SELF::DB_VERSION) {
-            $this->installApplication();
-        }
+        $this->pluginDirName = $dir;
     }
 
 }
diff --git a/controllers/front.php b/controllers/front.php
new file mode 100644 (file)
index 0000000..114f267
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+namespace Glm\Employment\Controller;
+use Glm\Employment\Model as Model;
+
+defined('ABSPATH') or die();
+
+/**
+ * AdminConroller
+ *
+ * Controller for all of the admin functionality
+ */
+class FrontController
+{
+
+    public $pluginDirName;
+
+    /**
+     * Register Hooks and Actions
+     */
+    public function __construct($path)
+    {
+        $this->pluginDirName = $path;
+        \add_shortcode('glmjobs', array($this, 'glm_jobs_shortcode'));
+        $jobs = new Model\Job($path);
+    }
+
+    public function glm_jobs_shortcode($atts)
+    {
+        extract(\shortcode_atts(array('limit' => '10'), $atts));
+        global $wpdb;
+        $midnight = strtotime(date('Y-m-d',time()).' 00:00:00');
+        $querystr = "
+            SELECT *
+            FROM $wpdb->posts wposts, $wpdb->postmeta metastart, $wpdb->postmeta metaend
+            WHERE (wposts.ID = metastart.post_id AND wposts.ID = metaend.post_id)
+            AND (metaend.meta_key = 'glm_jobs_enddate' AND metaend.meta_value > $midnight )
+            AND (metastart.meta_key = 'glm_jobs_startdate' AND metastart.meta_value < $midnight )
+            AND wposts.post_type = 'glm_jobs'
+            AND wposts.post_status = 'publish'
+            ORDER BY wposts.post_title ASC LIMIT $limit
+         ";
+
+        $jobs = $wpdb->get_results($querystr, OBJECT);
+        foreach ($jobs as $job) {
+            $custom = get_post_custom($job->ID);
+            $job->glm_jobs_startdate = $custom['glm_jobs_startdate'][0];
+            $job->glm_jobs_enddate   = $custom['glm_jobs_enddate'][0];
+            $job->glm_jobs_contact   = $custom['glm_jobs_contact'][0];
+            $job->glm_jobs_status    = $custom['glm_jobs_status'][0];
+            $job->glm_jobs_pay_grade = $custom['glm_jobs_pay_grade'][0];
+            $job->glm_jobs_shift     = $custom['glm_jobs_shift'][0];
+            $job->glm_jobs_email     = $custom['glm_jobs_email'][0];
+            $job->glm_jobs_comments  = $custom['glm_jobs_comments'][0];
+            $job->glm_jobs_code      = $custom['glm_jobs_code'][0];
+        }
+
+        \ob_start();
+        include $this->pluginDirName . 'views/jobList.php';
+        $out = \ob_get_contents();
+        \ob_end_clean();
+        return $out;
+    }
+
+    public function setPluginDir($dir)
+    {
+        $this->pluginDirName = $dir;
+    }
+
+}
index a2391fa..1c7300f 100644 (file)
@@ -13,16 +13,30 @@ use Glm\Employment as Emp;
 defined('ABSPATH') or die();
 
 require_once 'controllers/admin.php';
-require_once 'models/listJobs.php';
+require_once 'controllers/front.php';
+require_once 'models/job.php';
+
 use Glm\Employment\Controller as Controller;
+use Glm\Employment\Model as Model;
 
+/**
+ * Setup class to call in the Controllers
+ */
 class Setup
 {
     public function __construct()
     {
-        $adminController = new Controller\AdminController();
-        $adminController->initalizeActivationHooks();
+        if (is_admin()) {
+            $adminController = new Controller\AdminController(
+                plugin_dir_path(__FILE__)
+            );
+        } else {
+            $frontController = new Controller\FrontController(
+                plugin_dir_path(__FILE__)
+            );
+        }
+
     }
 }
 
-$employmentApp = new Emp\Setup();
+$employmentApp = new Emp\Setup();
\ No newline at end of file
index 90a3e52..a1bf9a1 100644 (file)
 <?php
-namespace Glm\Employment\Models;
+
+namespace Glm\Employment\Model;
 
 class Job
 {
-    const TABLE_NAME = 'jobs';
-    const PRI_KEY    = 'id';
 
+    public $pluginDirName;
+
+    public function __construct($path)
+    {
+        $this->pluginDirName = $path;
+        \add_action('init', array($this, 'addPostTypes'));
+        \add_action('init', array($this, 'createJobTaxonomy'));
+
+        \add_filter('manage_edit-glm_jobs_columns',
+                    array($this, 'jobs_edit_columns'));
+        \add_action('manage_posts_custom_column',
+                    array($this, 'jobs_custom_columns'));
+        \add_action('admin_init', array($this, 'meta_dates'));
+        \add_action('save_post', array($this, 'save_emp_meta'));
+    }
+
+    public function meta_dates()
+    {
+        add_meta_box('glm_employment_meta', 'Position Information',
+                     array($this, 'edit_job_meta'), 'glm_jobs');
+    }
+
+    public function edit_job_meta()
+    {
+        global $post;
+        $custom  = get_post_custom($post->ID);
+        //echo '<pre>'.print_r($custom, true).'</pre>';exit;
+        extract($custom);
+        $meta_sd = (isset($custom['glm_jobs_startdate']))
+            ? $custom['glm_jobs_startdate'][0]
+            : time();
+        $meta_ed = (isset($custom['glm_jobs_enddate']))
+            ? $custom['glm_jobs_enddate'][0]
+            : time();
+
+        $clean_sd = date('D, M d, Y', $meta_sd);
+        $clean_ed = date('D, M d, Y', $meta_ed);
+
+        include $this->pluginDirName . 'views/job_meta.php';
+    }
+
+    public function save_emp_meta()
+    {
+        global $post;
+        // - still require nonce
+        if (!wp_verify_nonce($_POST['glm-jobs-nonce'], 'glm-jobs-nonce')) {
+            return $post->ID;
+        }
+
+        if (!current_user_can('edit_post', $post->ID)) {
+            return $post->ID;
+        }
+
+        // - convert back to unix & update post
+        if (!isset($_POST["glm_jobs_startdate"])) {
+            return $post;
+        }
+
+        $updatestartd = strtotime($_POST['glm_jobs_startdate']);
+        update_post_meta($post->ID, 'glm_jobs_startdate', $updatestartd);
+
+        if (!isset($_POST['glm_jobs_enddate'])) {
+            return $post;
+        }
+        $updateendd = strtotime($_POST['glm_jobs_enddate']);
+        update_post_meta($post->ID, 'glm_jobs_enddate', $updateendd);
+
+        update_post_meta($post->ID, 'glm_jobs_status', $_POST['glm_jobs_status']);
+        update_post_meta($post->ID, 'glm_jobs_pay_grade',
+                         $_POST['glm_jobs_pay_grade']);
+        update_post_meta($post->ID, 'glm_jobs_shift', $_POST['glm_jobs_shift']);
+        update_post_meta($post->ID, 'glm_jobs_contact',
+                         $_POST['glm_jobs_contact']);
+        update_post_meta($post->ID, 'glm_jobs_email', $_POST['glm_jobs_email']);
+        update_post_meta($post->ID, 'glm_jobs_comments',
+                         $_POST['glm_jobs_comments']);
+        update_post_meta($post->ID, 'glm_jobs_code', $_POST['glm_jobs_code']);
+    }
+
+    /**
+     * Create new Post type
+     */
+    public function addPostTypes()
+    {
+        $labels = array(
+            'name'               => _x('Jobs', 'job general name'),
+            'singular_name'      => _x('Job', 'job type singular name'),
+            'add_new'            => _x('Add New', 'job'),
+            'edit_item'          => __('Edit Job'),
+            'new_item'           => __('New Job'),
+            'all_items'          => __('All Jobs'),
+            'view_item'          => __('View Job'),
+            'search_items'       => __('Search Jobs'),
+            'not_found'          => __('No Jobs found'),
+            'not_found_in_trash' => __('No Jobs found in the Trash'),
+            'parent_item_colon'  => '',
+            'menu_name'          => 'Jobs'
+        );
+        $args   = array(
+            'label'           => __('Jobs'),
+            'labels'          => $labels,
+            'description'     => 'Stores Jobs and Job data',
+            'public'          => true,
+            'can_export'      => true,
+            'menu_position'   => 21,
+            'supports'        => array('title', 'editor', 'thumbnail'),
+            'has_archive'     => false,
+            'menu_icon'       => 'dashicons-businessman',
+            'capability_type' => 'post',
+            'hierarchical'    => false,
+//            'rewrite'         => array('slug' => 'jobs')
+        );
+        \register_post_type('glm_jobs', $args);
+    }
+
+    public function createJobTaxonomy()
+    {
+        $labels = array(
+            'name'                       => _x('Categories',
+                                               'taxonomy general name'),
+            'singular_name'              => _x('Category',
+                                               'taxonomy singular name'),
+            'search_items'               => __('Search Categories'),
+            'popular_items'              => __('Popular Categories'),
+            'all_items'                  => __('All Categories'),
+            'parent_item'                => null,
+            'parent_item_colon'          => null,
+            'edit_item'                  => __('Edit Category'),
+            'update_item'                => __('Update Category'),
+            'add_new_item'               => __('Add New Category'),
+            'new_item_name'              => __('New Category Name'),
+            'separate_items_with_commas' => __('Separate categories with commas'),
+            'add_or_remove_items'        => __('Add or remove categories'),
+            'choose_from_most_used'      => __('Choose from the most used categories'),
+        );
+
+        \register_taxonomy('glm_jobscategory', 'glm_jobs',
+                           array(
+            'label'        => __('Job Category'),
+            'labels'       => $labels,
+            'hierarchical' => true,
+            'show_ui'      => true,
+            'query_var'    => true,
+            'rewrite'      => array('slug' => 'job-category'),
+        ));
+    }
+
+    function jobs_edit_columns($columns)
+    {
+        $columns = array(
+            "cb"               => "<input type=\"checkbox\" />",
+            "glmjobs_col_cat"  => "Category",
+            "glmjobs_col_date" => "Dates",
+            "title"            => "Job",
+            "glmjobs_col_desc" => "Description",
+        );
+        return $columns;
+    }
+
+    function jobs_custom_columns($column)
+    {
+        global $post;
+        $custom = \get_post_custom();
+
+        switch ($column) {
+            case "glmjobs_col_cat":
+                // - show taxonomy terms -
+                $eventcats      = \get_the_terms($post->ID, "glm_jobscategory");
+                $eventcats_html = array();
+                if ($eventcats) {
+                    foreach ($eventcats as $eventcat) {
+                        array_push($eventcats_html, $eventcat->name);
+                    }
+                    echo implode($eventcats_html, ", ");
+                } else {
+                    _e('None', 'themeforce');
+                    ;
+                }
+                break;
+            case "glmjobs_col_date":
+                // - show dates -
+                $startd    = $custom['glm_jobs_startdate'][0];
+                $endd      = $custom['glm_jobs_enddate'][0];
+                $startdate = date("F j, Y", $startd);
+                $enddate   = date("F j, Y", $endd);
+                echo $startdate . '<br /><em>' . $enddate . '</em>';
+                break;
+            case "glmjobs_col_desc";
+                \the_excerpt();
+                break;
+        }
+    }
 
 }
diff --git a/views/jobList.php b/views/jobList.php
new file mode 100644 (file)
index 0000000..d8349d3
--- /dev/null
@@ -0,0 +1,12 @@
+<div>
+    <h3>List Jobs</h3>
+    <div class="row">
+        <?php if ($jobs): foreach($jobs as $job) :?>
+        <div class="small-12 medium-6 columns" style="width:700px;float:left;background-color: #b4e0c2;padding: 15px;margin: 20px 0;">
+            <h2 style="width:45%;float:left;"><a href="<?php echo get_post_permalink($job->ID);?>"><?php echo $job->post_title;?></a></h2>
+            <div style="width:25%;float:left;"><strong>Status: </strong><?php echo $job->glm_jobs_status;?></div>
+            <div style="width:30%;float:left;"><a href="<?php echo get_post_permalink($job->ID);?>">Full Job Description</a></div>
+        </div>
+        <?php endforeach; endif;?>
+    </div>
+</div>
diff --git a/views/jobListOverview.php b/views/jobListOverview.php
new file mode 100644 (file)
index 0000000..ac69e14
--- /dev/null
@@ -0,0 +1,14 @@
+<div class="wrap">
+
+    <div id="icon-users" class="icon32"><br/></div>
+    <h2>List Jobs</h2>
+
+    <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
+    <form id="movies-filter" method="get">
+        <!-- For Plugins, we also need to ensure that the form posts back to our current page -->
+        <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
+        <!-- Now we can render the completed list table -->
+        <?php $jobListTable->display() ?>
+    </form>
+
+</div>
diff --git a/views/job_meta.php b/views/job_meta.php
new file mode 100644 (file)
index 0000000..6c0a57f
--- /dev/null
@@ -0,0 +1,74 @@
+<style>
+    .tf-meta {  }
+    .tf-meta ul li { height: 20px; clear:both; margin: 0 0 15px 0;}
+    .tf-meta ul li label { width: 160px; display:block; float:left; padding-top:4px; text-align: right;padding-right: 20px;}
+    .tf-meta ul li input { width:200px; display:block; float:left; }
+    .tf-meta ul li em { width: 200px; display:block; float:left; color:gray; margin-left:10px; padding-top: 4px}
+</style>
+<input type="hidden"
+       name="glm-jobs-nonce"
+       id="tf-events-nonce"
+       value="<?php echo wp_create_nonce( 'glm-jobs-nonce' );?>" />
+<div class="tf-meta">
+    <ul>
+        <li>
+            <label>Start Date</label>
+            <input name="glm_jobs_startdate" class="tfdate"
+                   value="<?php echo $clean_sd; ?>" />
+        </li>
+        <li>
+            <label>End Date</label>
+            <input name="glm_jobs_enddate" class="tfdate"
+                   value="<?php echo $clean_ed; ?>" />
+        </li>
+        <li>
+            <label>Status</label>
+            <input name="glm_jobs_status"
+                   value="<?php echo $glm_jobs_status[0]; ?>" />
+        </li>
+        <li>
+            <label>Pay Grade</label>
+            <input name="glm_jobs_pay_grade"
+                   value="<?php echo $glm_jobs_pay_grade[0]; ?>" />
+        </li>
+        <li>
+            <label>Primary Shift</label>
+            <input name="glm_jobs_shift"
+                   value="<?php echo $glm_jobs_shift[0]; ?>" />
+        </li>
+        <li>
+            <label>HR Contact Name</label>
+            <input name="glm_jobs_contact"
+                   value="<?php echo $glm_jobs_contact[0]; ?>" />
+        </li>
+        <li>
+            <label>HR Email</label>
+            <input name="glm_jobs_email"
+                   value="<?php echo $glm_jobs_email[0]; ?>" />
+        </li>
+        <li>
+            <label>Comments</label>
+            <input name="glm_jobs_comments"
+                   value="<?php echo $glm_jobs_comments[0]; ?>" />
+        </li>
+        <li>
+            <label>Job Code</label>
+            <input name="glm_jobs_code"
+                   value="<?php echo $glm_jobs_code[0]; ?>" />
+        </li>
+    </ul>
+</div>
+<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
+<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
+<script>
+    jQuery(document).ready(function (){
+        jQuery(".tfdate").datepicker({
+            dateFormat: 'D, M d, yy',
+            showOn: 'button',
+            buttonImage: 'http://app.gaslightmedia.com/assets/icons/calendar.png',
+            buttonImageOnly: true,
+            numberOfMonths: 1
+
+        });
+    });
+</script>