static function ajax_save()
 {
     if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     $status_id_old = Kanban_Utils::format_key(self::$slug, 'status_id_old');
     $status_id_new = Kanban_Utils::format_key(self::$slug, 'status_id_new');
     // build post data
     $post_data = array('post_type' => Kanban_Post_Types::format_post_type(self::$slug), 'post_title' => sprintf('changed task ID %s from %s to %s', $_POST['task_id'], $_POST['status_id_old'], $_POST['status_id_new']), 'post_parent' => $_POST['task_id'], 'postmeta' => array($status_id_old => $_POST['status_id_old'], $status_id_new => $_POST['status_id_new']), 'terms' => array());
     // save our work_hour
     $post_data = Kanban_Post::save($post_data);
     if (!$post_data) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data));
 }
示例#2
0
 static function get_all()
 {
     if (!isset(self::get_instance()->all_projects)) {
         $post_type_key = Kanban_Post_Types::format_post_type(self::$slug);
         $args = array('posts_per_page' => -1, 'post_type' => $post_type_key, 'post_status' => 'publish');
         $posts = get_posts($args);
         self::get_instance()->all_projects = Kanban_Post::apply_postmeta_and_terms_to_posts($posts);
     }
     return self::get_instance()->all_projects;
 }
示例#3
0
 static function get_all()
 {
     if (!isset(self::get_instance()->all_tasks)) {
         global $wpdb;
         $post_type_key = Kanban_Post_Types::format_post_type(self::$slug);
         $sql = "SELECT *\n\t\t\t\t\tFROM `{$wpdb->prefix}posts`\n\t\t\t\t\tWHERE `{$wpdb->prefix}posts`.`post_type` = '{$post_type_key}'\n\t\t\t\t\tAND `{$wpdb->prefix}posts`.`post_status` IN ('publish')\n\t\t\t;";
         $sql = apply_filters(sprintf('%s_sql_%s_get_all', Kanban::get_instance()->settings->basename, self::$slug), $sql);
         $posts = $wpdb->get_results($sql);
         self::get_instance()->all_tasks = Kanban_Post::apply_postmeta_and_terms_to_posts($posts);
     }
     return self::get_instance()->all_tasks;
 }
 static function ajax_save()
 {
     if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     $current_user_id = get_current_user_id();
     $comment_type_field = Kanban_Utils::format_key(self::$slug, 'comment_type');
     // build post data
     $post_data = array('post_type' => Kanban_Post_Types::format_post_type(self::$slug), 'post_title' => sprintf('%s comment for task %s', $_POST['comment_type'], $_POST['id']), 'post_content' => sanitize_text_field(str_replace("\n", '', $_POST['post_content'])), 'post_parent' => $_POST['id'], 'postmeta' => array($comment_type_field => $_POST['comment_type']));
     // save our work_hour
     $post_data = Kanban_Post::save($post_data);
     if (!$post_data) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data));
 }
 static function ajax_save()
 {
     if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::$instance->settings->basename)) || !isset($_POST[Kanban_Task::$slug]) || !is_user_logged_in()) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_before_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug));
     // build post data
     $post_data = array('post_type' => Kanban_Post_Types::format_post_type('work_hour'), 'post_title' => sanitize_text_field($_POST[Kanban_Task::$slug]['post_title']), 'postmeta' => array(), 'terms' => array());
     $hour_operator = Kanban_Utils::format_key('work_hour', 'operator');
     $post_data['postmeta'][$hour_operator] = $_POST['operator'];
     // set assignee as author of work hour
     $task_user_id_assigned_to = Kanban_Utils::format_key('task', 'user_id_assigned');
     if ($_POST[Kanban_Task::$slug]['postmeta'][$task_user_id_assigned_to] > 0) {
         $post_data['post_author'] = $_POST[Kanban_Task::$slug]['postmeta'][$task_user_id_assigned_to];
     }
     // link task to hour
     $hour_task_id = Kanban_Utils::format_key('work_hour', 'project_id');
     $post_data['postmeta'][$hour_task_id] = $_POST[Kanban_Task::$slug]['ID'];
     // link current user to hour
     $hour_user_id_logged = Kanban_Utils::format_key('work_hour', 'user_id_logged');
     $post_data['postmeta'][$hour_user_id_logged] = get_current_user_id();
     // set task project as work project
     $task_project_id = Kanban_Utils::format_key('task', 'project_id');
     $hour_project_id = Kanban_Utils::format_key('work_hour', 'project_id');
     $post_data['postmeta'][$hour_project_id] = $_POST[Kanban_Task::$slug]['postmeta'][$task_project_id];
     // set current task status for work hour
     $task_status = Kanban_Utils::format_key('task', 'status');
     $hour_status_id = Kanban_Utils::format_key('work_hour', 'task_status_id');
     $post_data['postmeta'][$hour_status_id] = $_POST[Kanban_Task::$slug]['terms'][$task_status][0];
     // save our work_hour
     $post_data = Kanban_Post::save($post_data);
     if (!$post_data) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug));
     wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data));
 }
示例#6
0
 /**
  * Apply all postmeta and terms to an array of posts
  * @param  arr $posts array of post objects
  * @return arr        array of posts, with ID's as keys, and all postmeta and terms applied
  */
 static function apply_postmeta_and_terms_to_posts($posts)
 {
     // make sure the first post has a post type
     if (empty($posts[0]->post_type)) {
         return $posts;
     }
     // build array of id's
     $post_id_arr = array();
     foreach ($posts as $post) {
         $post_id_arr[] = $post->ID;
     }
     // get postmeta for all posts
     $postmeta = Kanban_Post::get_postmeta_for_posts($post_id_arr, $posts[0]->post_type);
     // get terms for all posts
     $terms = Kanban_Terms::get_terms_for_posts($post_id_arr, $posts[0]->post_type);
     // apply post meta and terms to projects
     foreach ($posts as $post) {
         if (isset($postmeta[$post->ID])) {
             $post->postmeta = $postmeta[$post->ID];
         }
         if (isset($terms[$post->ID])) {
             $post->terms = $terms[$post->ID];
         }
     }
     // put get array with post id's as keys
     return Kanban_Utils::build_array_with_id_keys($posts);
 }