Ejemplo n.º 1
0
 /**
  * get the instance of this class
  * @return	object	the instance
  */
 public static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
    /**
     * load data needed for board's javascript
     * @param  string $template the passed in template path
     * @return string           the same template path
     */
    static function send_page_data_to_template($template)
    {
        // make sure we're looking at the board
        if (!isset(Kanban_Template::get_instance()->slug) || Kanban_Template::get_instance()->slug != self::$slug) {
            return $template;
        }
        // make sure they don't need to upgrade
        if (Kanban::get_instance()->settings->records_to_move > 0) {
            ?>
			<p>
			<?php 
            echo sprintf(__('We\'ve found %s kanban records that need to be migrated for the latest version of Kanban for WordPress!', 'kanban'), Kanban::get_instance()->settings->records_to_move);
            ?>
			</p>
			<p>
			<?php 
            echo sprintf(__('Please visit the <a href="%s">Kanban welcome page</a> to migrate your data.', 'kanban'), add_query_arg('page', 'kanban_welcome', admin_url('admin.php')));
            ?>
			<?php 
            exit;
        }
        // get the template data
        global $wp_query;
        // attach our object to the template data
        $wp_query->query_vars['kanban'] = (object) array();
        $wp_query->query_vars['kanban']->board = (object) array();
        // add default filters
        $wp_query->query_vars['kanban']->board->filters = array('user' => (object) array(), 'project' => (object) array());
        // add passed alert
        $wp_query->query_vars['kanban']->board->alert = !empty($_GET['alert']) ? stripcslashes($_GET['alert']) : '';
        // get all data for the javascript
        $wp_query->query_vars['kanban']->board->settings = Kanban_Option::get_all();
        $wp_query->query_vars['kanban']->board->allowed_users = Kanban_User::get_allowed_users();
        $wp_query->query_vars['kanban']->board->estimates = Kanban_Estimate::get_all();
        $wp_query->query_vars['kanban']->board->statuses = Kanban_Status::get_all();
        $wp_query->query_vars['kanban']->board->projects = Kanban_Project::get_all();
        $wp_query->query_vars['kanban']->board->tasks = Kanban_Task::get_all();
        // get the current user from the allowed users
        $current_user_id = get_current_user_id();
        $wp_query->query_vars['kanban']->board->current_user = $wp_query->query_vars['kanban']->board->allowed_users[$current_user_id];
        // figure out percentages here (easier, quicker than in js)
        $wp_query->query_vars['kanban']->board->col_percent_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / count($wp_query->query_vars['kanban']->board->statuses) : 100;
        $wp_query->query_vars['kanban']->board->sidebar_w = count($wp_query->query_vars['kanban']->board->statuses) > 0 ? 100 / (count($wp_query->query_vars['kanban']->board->statuses) - 2) : 0;
        apply_filters('kanban_board_query_vars', $wp_query->query_vars['kanban']->board);
        return $template;
    }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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);
     }
 }