/** * get the users that are allowed to access the board * @return array allowed user objects */ static function get_allowed_users() { if (!isset(Kanban_User::get_instance()->allowed_users)) { // get all settings $allowed_users = Kanban_Option::get_option('allowed_users'); // pull out allowed user id's $allowed_user_ids = array(); if (is_array($allowed_users)) { $allowed_user_ids = $allowed_users; } if (empty($allowed_user_ids)) { $allowed_user_ids = array(0); } // load actual users $users = get_users(array('include' => $allowed_user_ids, 'fields' => array('ID', 'user_email'))); // add users to object Kanban_User::get_instance()->allowed_users = Kanban_Utils::build_array_with_id_keys($users, 'ID'); // load extra data foreach (Kanban_User::get_instance()->allowed_users as $user_id => $user) { Kanban_User::get_instance()->allowed_users[$user_id]->caps = array('write'); // get gravatar if (self::validate_gravatar($user->user_email)) { Kanban_User::get_instance()->allowed_users[$user_id]->avatar = get_avatar($user->user_email); } // fancy name formating Kanban_User::get_instance()->allowed_users[$user_id]->long_name_email = Kanban_User::get_username_long($user); Kanban_User::get_instance()->allowed_users[$user_id]->short_name = Kanban_User::get_username_short($user, TRUE); Kanban_User::get_instance()->allowed_users[$user_id]->initials = Kanban_User::get_initials($user); } } return apply_filters(sprintf('%s_after_get_allowed_users', Kanban::get_instance()->settings->basename), Kanban_User::get_instance()->allowed_users); }
/** * 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; }
/** * get the users that are allowed to access the board * @return array allowed user objects */ static function get_allowed_users() { if (!isset(Kanban_User::get_instance()->allowed_users)) { global $wpdb; // get all settings $allowed_users = Kanban_Option::get_option('allowed_users'); // pull out allowed user id's $allowed_user_ids = array(); if (is_array($allowed_users)) { $allowed_user_ids = $allowed_users; } if (empty($allowed_user_ids)) { $allowed_user_ids = array(0); } // load actual users // $users = get_users(array( // 'include' => $allowed_user_ids, // 'fields' => array( // 'ID', // 'user_email', // ) // )); $allowed_user_ids_str = implode(',', $allowed_user_ids); $users = $wpdb->get_results("SELECT {$wpdb->users}.ID,\n\t\t\t{$wpdb->users}.user_email,\n\t\t\tfirst_name.meta_value AS 'first_name',\n\t\t\tlast_name.meta_value AS 'last_name'\n\t\t\tFROM {$wpdb->users}\n\t\t\tLEFT JOIN {$wpdb->usermeta} first_name\n\t\t\tON {$wpdb->users}.ID = first_name.user_id\n\t\t\tAND first_name.meta_key = 'first_name'\n\t\t\tLEFT JOIN {$wpdb->usermeta} last_name\n\t\t\tON {$wpdb->users}.ID = last_name.user_id\n\t\t\tAND last_name.meta_key = 'last_name'\n\t\t\tWHERE {$wpdb->users}.ID IN ({$allowed_user_ids_str});"); // add users to object Kanban_User::get_instance()->allowed_users = Kanban_Utils::build_array_with_id_keys($users, 'ID'); // load extra data foreach (Kanban_User::get_instance()->allowed_users as $user_id => $user) { Kanban_User::get_instance()->allowed_users[$user_id]->caps = array('write'); // get gravatar if (self::validate_gravatar($user->user_email)) { Kanban_User::get_instance()->allowed_users[$user_id]->avatar = get_avatar($user->user_email); } // fancy name formating Kanban_User::get_instance()->allowed_users[$user_id]->long_name_email = Kanban_User::get_username_long($user); Kanban_User::get_instance()->allowed_users[$user_id]->short_name = Kanban_User::get_username_short($user, TRUE); Kanban_User::get_instance()->allowed_users[$user_id]->initials = Kanban_User::get_initials($user); } } return apply_filters('kanban_user_get_allowed_users_return', Kanban_User::get_instance()->allowed_users); }
/** * 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; }
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); } }
<?php submit_button(__('Save your Settings', Kanban::get_text_domain()), 'primary', 'submit'); ?> </div><!-- tab-estimates --> <?php echo apply_filters(sprintf('%s_settings_tabs_content', Kanban::get_instance()->settings->basename), ''); ?> <?php wp_nonce_field(sprintf('%s-%s', Kanban::$instance->settings->basename, Kanban_Option::table_name()), Kanban_Utils::get_nonce()); ?> </form> </div><!-- wrap --> <script type="text/html" id="t-status"> <?php include sprintf('%s/t-status.php', __DIR__); ?>