/** * Create or update a holiday * * @since 0.1 * * @return void */ public function holiday_create() { $this->verify_nonce('erp-leave-holiday'); $holiday_id = isset($_POST['holiday_id']) ? intval($_POST['holiday_id']) : 0; $title = isset($_POST['title']) ? sanitize_text_field($_POST['title']) : ''; $start_date = isset($_POST['start_date']) ? $_POST['start_date'] : ''; $end_date = isset($_POST['end_date']) && !empty($_POST['end_date']) ? $_POST['end_date'] : $start_date; $description = isset($_POST['description']) ? $_POST['description'] : ''; $range_status = isset($_POST['range']) ? $_POST['range'] : 'off'; $error = true; $holidays = erp_hr_get_holidays(array('number' => '-1')); if ($holidays) { foreach ($holidays as $holiday) { $prev_start = date('Y-m-d', strtotime($holiday->start)); $prev_end = date('Y-m-d', strtotime($holiday->end)); if (erp_check_date_range_in_range_exist($prev_start, $prev_end, $start_date, $end_date) && $holiday->id != $holiday_id) { $error = new \WP_Error('msg', __('Holiday exist in your selected date', 'wp-erp')); } if (erp_check_date_range_in_range_exist($start_date, $end_date, $prev_start, $prev_end) && $holiday->id != $holiday_id) { $error = new \WP_Error('msg', __('Holiday exist in your selected date', 'wp-erp')); } } } if ($range_status == 'off') { $end_date = $start_date; } if (is_wp_error($error)) { $this->send_error($error->get_error_message()); } $holiday_id = erp_hr_leave_insert_holiday(array('id' => $holiday_id, 'title' => $title, 'start' => $start_date, 'end' => $end_date, 'description' => $description)); if (is_wp_error($holiday_id)) { $this->send_error($holiday_id->get_error_message()); } $this->send_success(); }
/** * Prepare the class items * * @return void */ function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $per_page = 20; $current_page = $this->get_pagenum(); $offset = ($current_page - 1) * $per_page; $this->page_status = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : '2'; // only ncessary because we have sample data $args = array('offset' => $offset, 'number' => $per_page); if (!empty($_GET['s'])) { $args['s'] = $_GET['s']; } if (isset($_GET['from']) && $_GET['from'] != '') { $args['from'] = date('Y-m-d', strtotime($_GET['from'])); } if (isset($_GET['to']) && $_GET['to'] != '') { $args['to'] = date('Y-m-d', strtotime($_GET['to'])); } if (isset($_REQUEST['orderby']) && isset($_REQUEST['order'])) { $args['orderby'] = $_REQUEST['orderby']; $args['order'] = $_REQUEST['order']; } $this->items = erp_hr_get_holidays($args); $this->set_pagination_args(array('total_items' => erp_hr_count_holidays($args), 'per_page' => $per_page)); }