Beispiel #1
0
 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));
     $user_id_author = isset($_POST['user_id_author']) ? $_POST['user_id_author'] : get_current_user_id();
     if (empty($_POST['user_id_worked'])) {
         $_POST['user_id_worked'] = $user_id_author;
     }
     try {
         $operator = substr($_POST['operator'], 0, 1) == '-' ? '-' : '+';
         $val = sprintf('%s%s', $operator, abs(floatval($_POST['operator'])));
     } catch (Exception $e) {
         wp_send_json_error(array('message' => sprintf('Error saving %s', str_replace('_', ' ', self::$slug))));
     }
     eval(sprintf('$hours = 0%s;', $val));
     $data = array('task_id' => $_POST['task']['id'], 'worked_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'hours' => $hours, 'status_is' => $_POST['task']['status_id'], 'user_id_author' => $user_id_author, 'user_id_worked' => $_POST['user_id_worked']);
     $is_successful = self::_insert($data);
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     if (!empty($_POST['comment'])) {
         do_action(sprintf('%s_before_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug));
         Kanban_Comment::add($_POST['comment'], 'system', $_POST['task']['id']);
         do_action(sprintf('%s_after_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug));
     }
     if ($is_successful) {
         wp_send_json_success(array('message' => sprintf('%s saved', str_replace('_', ' ', self::$slug))));
     } else {
         wp_send_json_error(array('message' => sprintf('Error saving %s', str_replace('_', ' ', self::$slug))));
     }
 }
Beispiel #2
0
 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));
     $_POST['task']['modified_dt_gmt'] = Kanban_Utils::mysql_now_gmt();
     if (!isset($_POST['task']['user_id_author'])) {
         $_POST['task']['user_id_author'] = get_current_user_id();
     }
     $is_successful = self::_replace($_POST['task']);
     $task_id = isset($_POST['task']['id']) ? $_POST['task']['id'] : self::_insert_id();
     $post_data = self::get_row('id', $task_id);
     if (!$post_data) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     if (!empty($_POST['comment'])) {
         do_action(sprintf('%s_before_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug));
         Kanban_Comment::add($_POST['comment'], 'system', $task_id);
         do_action(sprintf('%s_after_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug));
     }
     if (isset($_POST['status_id_old'])) {
         do_action(sprintf('%s_before_%s_ajax_status_change_save', Kanban::get_instance()->settings->basename, self::$slug));
         Kanban_Status_Change::add($task_id, $post_data->status_id, $_POST['status_id_old']);
         do_action(sprintf('%s_after_%s_ajax_status_change_save', Kanban::get_instance()->settings->basename, self::$slug));
     }
     if ($is_successful) {
         wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data));
     } else {
         wp_send_json_error(array('message' => sprintf('Error saving %s', self::$slug)));
     }
 }
Beispiel #3
0
 static function add($task_id, $status_id_new, $status_id_old = 0, $user_id_author = NULL)
 {
     if (!$user_id_author) {
         $user_id_author = get_current_user_id();
     }
     $data = array('task_id' => $task_id, 'created_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'status_id_old' => $status_id_old, 'status_id_new' => $status_id_new, 'user_id_author' => $user_id_author);
     $id = self::_insert($data);
 }
Beispiel #4
0
 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));
     $_POST['project']['modified_dt_gmt'] = Kanban_Utils::mysql_now_gmt();
     $_POST['project']['user_id_author'] = get_current_user_id();
     $is_successful = self::_replace($_POST['project']);
     $project_id = isset($_POST['project']['id']) ? $_POST['project']['id'] : self::_insert_id();
     $post_data = self::get_row('id', $project_id);
     if (!$post_data) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     if ($is_successful) {
         wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data));
     } else {
         wp_send_json_error(array('message' => sprintf('Error saving %s', self::$slug)));
     }
 }
Beispiel #5
0
 static function add_defaults()
 {
     global $wpdb;
     $status_table = Kanban_Status::table_name();
     $sql = "SELECT count(`id`)\n\t\t\t\tFROM `{$status_table}`\n\t\t;";
     $status_count = $wpdb->get_var($sql);
     if ($status_count == 0) {
         $statuses = array('Backlog' => '#8224e3', 'Ready' => '#eeee22', 'In progress' => '#81d742', 'QA' => '#f7a738', 'Done' => '#1e73be', 'Archive' => '#333333');
         $i = 0;
         foreach ($statuses as $status => $color) {
             $data = array('title' => $status, 'color_hex' => $color, 'position' => $i);
             Kanban_Status::replace($data);
             $i++;
         }
     }
     $estimate_table = Kanban_Estimate::table_name();
     $sql = "SELECT count(`id`)\n\t\t\t\tFROM `{$estimate_table}`\n\t\t;";
     $estimate_count = $wpdb->get_var($sql);
     if ($estimate_count == 0) {
         $estimates = array('2' => '2h', '4' => '4h', '8' => '1d', '16' => '2d', '32' => '4d');
         $i = 0;
         foreach ($estimates as $hours => $title) {
             $data = array('title' => $title, 'hours' => $hours, 'position' => $i);
             Kanban_Estimate::replace($data);
             $i++;
         }
     }
     $boards_table = Kanban_Board::table_name();
     $sql = "SELECT count(`id`)\n\t\t\t\tFROM `{$boards_table}`\n\t\t;";
     $boards_count = $wpdb->get_var($sql);
     if ($boards_count == 0) {
         $data = array('title' => 'Your first kanban board', 'created_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'modified_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'user_id_author' => get_current_user_id(), 'is_active' => 1);
         Kanban_Board::replace($data);
     }
     $tasks_table = Kanban_Board::table_name();
     $sql = "SELECT count(`id`)\n\t\t\t\tFROM `{$tasks_table}`\n\t\t;";
     $tasks_count = $wpdb->get_var($sql);
     if ($tasks_count == 0) {
         $sql = "SELECT `id`\n\t\t\t\t\tFROM `{$boards_table}`\n\t\t\t\t\tLIMIT 1\n\t\t\t;";
         $board_id = $wpdb->get_var($sql);
         $data = array('title' => 'Your first task', 'board_id' => $board_id, 'created_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'modified_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'user_id_author' => get_current_user_id(), 'is_active' => 1);
         Kanban_Board::replace($data);
     }
     $options_table = Kanban_Option::table_name();
     $sql = "SELECT *\n\t\t\t\tFROM `{$options_table}`\n\t\t;";
     $options = $wpdb->get_results($sql);
     $options_arr = array();
     foreach ($options as $option) {
         $options_arr[$option->name] = $option->value;
     }
     $defaults = Kanban_Option::get_defaults();
     foreach ($defaults as $name => $value) {
         if (isset($options_arr[$name])) {
             continue;
         }
         $data = array('name' => $name, 'value' => $value);
         Kanban_Option::replace($data);
     }
 }