From: Anthony Talarico Date: Mon, 25 Sep 2017 20:28:12 +0000 (-0400) Subject: adding job import tab in mgmt X-Git-Tag: v1.0.0~1^2~27 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=e70816550adf8f32de270d1295245cba5cad848f;p=WP-Plugins%2Fglm-member-db-jobs.git adding job import tab in mgmt adding separate tab in mgmt to import content from ds4. not complete --- diff --git a/models/admin/management/jobsImport.php b/models/admin/management/jobsImport.php new file mode 100644 index 0000000..236f00b --- /dev/null +++ b/models/admin/management/jobsImport.php @@ -0,0 +1,289 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +/** + * This class performs the work for the default action of the "Members" menu + * option, which is to display the members dashboard. + * + */ +class GlmMembersAdmin_management_jobsImport +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This contractor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + public function addScheme($url, $scheme = 'http://') + { + return parse_url($url, PHP_URL_SCHEME) === null ? + $scheme . $url : $url; + } + + /** + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successful and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the controller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ($actionData = false) + { + + + $resultMessage = ''; + $success = false; + $haveMembers = false; + $import = false; + $importNotice = ''; + $option = ''; + + if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') { + $option = $_REQUEST['option']; + } + + switch($option) { + case 'upload_file': + // We're given a CSV file. + // We need to parse it out. File must have header line. + // $file_data = $file_headers = $data = $members = array(); + + // if ( isset( $_FILES ) && isset( $_FILES['file_upload'] ) && ( $fh = fopen( $_FILES['file_upload']['tmp_name'], 'r' ) ) !== false ) { + // $row = 0; + // while( ( $data = fgetcsv( $fh, 1000, ',' ) ) !== false ) { + // if ( $row === 0 ) { + // // First row grab as headers. + // $file_headers = $data; + // } else { + // // All other rows are data. + // $file_data[] = array_combine( $file_headers, $data ); + // } + // $row++; + // } + // fclose( $fh ); + // } + // $resultMessage .= $this->importMemberData( $file_data ); + //$resultMessage .= '
$file_data: ' . print_r( $file_data, true ) . '
'; + break; + + case 'importItems': + $table = GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'jobs'; + define('BASE_URL', 'http://www.migcsa.org'); + define('PG_DSN', 'pgsql: host=ds4 dbname=migcsa2_update user=postgres'); + + try { + $dsn = PG_DSN; + $driverOptions = array( + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ); + $dbh = new PDO($dsn, null, null, $driverOptions); + $dbh->setAttribute( + PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION + ); + // JOBS + $job_titles_sql = "SELECT * FROM job_department;"; + $stmt = $dbh->query($job_titles_sql); + $job_titles = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach($job_titles as $key=>$value){ + $wpdb->insert( GLM_MEMBERS_JOBS_PLUGIN_DB_PREFIX . 'job_titles', + array( + 'old_id'=>$value['id'], + 'job_title'=>$value['name'] + ), + array( + '%d', + '%s' + ) + ); + } + $job_sql = "SELECT * FROM job ORDER BY id;"; + $stmt = $dbh->query($job_sql); + $jobs = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach($jobs as $key=>$value){ + // echo '
', print_r($value), '
'; + $post_date = false; + // echo $value ['operation'] . " : " . $value['requirements'] . " |
"; + // echo '
'; + if( $value['post'] == "30 days" ){ + $post_date = 30; + }else if( $value['post'] == "60 days" ){ + $post_date = 60; + } + // $url + // $wpdb->insert( $table, + // array( + // 'old_id'=>$value['id'], + // 'title'=>$value['departmentid'], + // 'descr'=>$value['descr'], + // 'company'=>$value['operation'], + // 'salary'=>$value['salary'], + // 'descr'=>$value['descr'], + // 'resume_location'=>$value['location'], + // 'email_location'=>$value['contactemail'], + // 'contact_name'=>$value['contactname'], + // 'contact_phone'=>$value['contactphone'], + // 'visible'=>$value['visable'], + // 'facility_operation'=>$value['course_operations'], + // 'duration'=>$value['duration'], + // 'benefits'=>$value['bentext'], + // 'post_date'=>$value['ds'], + // 'requirements'=>$value['requirements'], + // 'member'=>$value['member'], + // 'position_available'=>$value['position_available'], + // 'duration'=>$value['duration'], + // 'deadline'=>$value['deadline'], + // 'job_expiration'=>$post_date, + // 'job_location'=>$value['joblocation'], + // ), + // array( + // '%d', + // '%d', + // '%s', + // '%s', + // '%s', + // '%s', + // '%s', + // '%s', + // '%s', + // '%s', + // '%d', + // '%s', + // '%s', + // '%s', + // '%d', + // '%s', + // '%d', + // '%s', + // '%s', + // '%s', + // '%d', + // '%s', + // ) + // ); + } + echo '
', print_r($jobs), '
'; + + + } catch(PDOException $e) { + echo '
'.print_r($e, true).'
'; + } + + if ( isset( $_REQUEST['start'] ) ) { + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + } else { + $start = 0; + } + // global $wpdb; + + + $url = get_site_url() . '/wp-admin/admin.php?page=glm-members-admin-menu-management&glm_action=jobImport&option=importJobs'; + $limit = 200; + + // $sql = "SELECT name,mother_name,misc_info, courier_date FROM chxctyitem LIMIT $limit OFFSET $start"; + // $jobs = $wpdb->get_results( $sql, ARRAY_A ); + + $count = 0; + // foreach($jobs as $column=>$data ){ + // $count++; + // // $insert = array(); + + // } +// echo '
', print_r($insert), '
'; + // $wpdb->insert($table, $insert); + + $resultMessage = "
Start: $start
"; + $start += $limit; + $resultMessage .= "

Next

"; + + break; + + default: + break; + } + + $templateData = array( + 'success' => $success, + 'option' => $option, + 'resultMessage' => $resultMessage + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/jobsImport.html', + 'data' => $templateData + ); + } +} diff --git a/setup/adminTabs.php b/setup/adminTabs.php index eb01c70..b2570b7 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -51,4 +51,20 @@ if (current_user_can('glm_members_members')) { ); } + if (apply_filters('glm_members_permit_admin_members_management_tab', true)) { + + add_filter('glm-member-db-add-tab-for-management', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Jobs Import', + 'menu' => 'management', + 'action' => 'jobsImport' + ), + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); + } } diff --git a/views/admin/management/jobsImport.html b/views/admin/management/jobsImport.html new file mode 100644 index 0000000..e69de29