Example #1
0
 static function save_settings()
 {
     if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'kanban-options') || !is_user_logged_in()) {
         return;
     }
     $statuses = Kanban_Status::get_all();
     $status_ids = array_keys($statuses);
     // any statuses to delete?
     if (isset($_POST['statuses']['saved'])) {
         $deleted_statuses = array_diff($status_ids, array_keys($_POST['statuses']['saved']));
         if (!empty($deleted_statuses)) {
             foreach ($deleted_statuses as $key => $id) {
                 Kanban_Status::delete(array('id' => $id));
             }
         }
     }
     // add new statuses first
     if (isset($_POST['statuses']['new'])) {
         foreach ($_POST['statuses']['new'] as $status) {
             // save it
             $success = Kanban_Status::replace($status);
             if ($success) {
                 $status_id = Kanban_Status::insert_id();
                 // add it to all the statuses to save
                 $_POST['statuses']['saved'][$status_id] = $status;
             }
         }
     }
     // now save all statuses with positions
     if (isset($_POST['statuses']['saved'])) {
         foreach ($_POST['statuses']['saved'] as $status_id => $status) {
             $status['id'] = $status_id;
             Kanban_Status::replace($status);
         }
     }
     $estimates = Kanban_Estimate::get_all();
     $estimate_ids = array_keys($estimates);
     // any estimates to delete?
     if (isset($_POST['estimates']['saved'])) {
         $deleted_estimates = array_diff($estimate_ids, array_keys($_POST['estimates']['saved']));
         if (!empty($deleted_estimates)) {
             foreach ($deleted_estimates as $key => $id) {
                 Kanban_Estimate::delete(array('id' => $id));
             }
         }
     }
     // add new estimates first
     if (isset($_POST['estimates']['new'])) {
         foreach ($_POST['estimates']['new'] as $estimate) {
             // save it
             $success = Kanban_Estimate::replace($estimate);
             if ($success) {
                 $estimate_id = Kanban_Estimate::insert_id();
                 // add it to all the estimates to save
                 $_POST['estimates']['saved'][$estimate_id] = $estimate;
             }
         }
     }
     // now save all estimates with positions
     if (isset($_POST['estimates']['saved'])) {
         foreach ($_POST['estimates']['saved'] as $estimate_id => $estimate) {
             $estimate['id'] = $estimate_id;
             Kanban_Estimate::replace($estimate);
         }
     }
     // get current settings
     $settings = Kanban_Option::get_all_raw();
     $settings = Kanban_Utils::build_array_with_id_keys($settings);
     // save all single settings
     foreach ($_POST['settings'] as $key => $value) {
         if (is_array($value)) {
             $value = serialize($value);
         }
         $data = array('name' => $key, 'value' => $value);
         // see if it's already set
         $id = Kanban_Utils::find_key_of_object_by_property('name', $key, $settings);
         if ($id) {
             $data['id'] = $id;
         }
         Kanban_Option::_replace($data);
     }
     $url = add_query_arg(array('message' => urlencode(__('Settings saved', 'kanban'))), $_POST['_wp_http_referer']);
     wp_redirect($url);
     exit;
 }
Example #2
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);
     }
 }