From: Steve Sutton Date: Thu, 13 Nov 2014 15:29:17 +0000 (-0500) Subject: fix some issues with git X-Git-Tag: v1.0.1~32 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3d640c497b75a75972b46ddf2dc2b25280a4d922;p=WP-Plugins%2Fglm-employment.git fix some issues with git --- diff --git a/controllers/admin.php b/controllers/admin.php index b15d6e9..a824dda 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -1,138 +1,46 @@ prepare_items(); - ?> -
- -

-

List Jobs

- - -
- - - - display() ?> -
- -
- Add Job'; - } + 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 index 0000000..114f267 --- /dev/null +++ b/controllers/front.php @@ -0,0 +1,70 @@ +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; + } + +} diff --git a/glm-employment.php b/glm-employment.php index a2391fa..1c7300f 100644 --- a/glm-employment.php +++ b/glm-employment.php @@ -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 diff --git a/models/job.php b/models/job.php index 90a3e52..a1bf9a1 100644 --- a/models/job.php +++ b/models/job.php @@ -1,10 +1,201 @@ 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 '
'.print_r($custom, true).'
';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" => "", + "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 . '
' . $enddate . ''; + break; + case "glmjobs_col_desc"; + \the_excerpt(); + break; + } + } } diff --git a/views/jobList.php b/views/jobList.php new file mode 100644 index 0000000..d8349d3 --- /dev/null +++ b/views/jobList.php @@ -0,0 +1,12 @@ +
+

List Jobs

+
+ +
+

post_title;?>

+
Status: glm_jobs_status;?>
+
Full Job Description
+
+ +
+
diff --git a/views/jobListOverview.php b/views/jobListOverview.php new file mode 100644 index 0000000..ac69e14 --- /dev/null +++ b/views/jobListOverview.php @@ -0,0 +1,14 @@ +
+ +

+

List Jobs

+ + +
+ + + + display() ?> +
+ +
diff --git a/views/job_meta.php b/views/job_meta.php new file mode 100644 index 0000000..6c0a57f --- /dev/null +++ b/views/job_meta.php @@ -0,0 +1,74 @@ + + +
+ +
+ + +