/** * Loops through to-do items * Passes a completed value, limit value and a category id * @param int $status * @param int $cat_id * @param $limit */ public function loop_through_todos($status = 0, $cat_id = 0, $limit = 100) { global $userdata, $current_user; get_currentuserinfo(); $limit = isset(CTDL_Loader::$dashboard_settings['dashboard_number']) ? CTDL_Loader::$dashboard_settings['dashboard_number'] : $limit; $limit = $limit == '-1' ? 1000 : $limit; $user = CTDL_Lib::check_permission('todo', 'view') ? $current_user->ID : $userdata->ID; if (CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] == 'cat_id' && $cat_id == 0) { $categories = CTDL_Categories::get_categories(); $items = 0; $posts_to_exclude = array(); foreach ($categories as $category) { $todo_items = CTDL_Lib::get_todos($user, $limit, $status, $category->term_id); if ($todo_items->have_posts()) { array_splice($posts_to_exclude, count($posts_to_exclude), 0, $this->show_todo_list_items($todo_items, $status, $category->term_id)); $items = 1; } } $todo_items = CTDL_Lib::get_todos($user, 0, $status, 0, $posts_to_exclude); if ($todo_items->have_posts()) { $this->show_todo_list_items($todo_items, $status); $items = 1; } if ($items == 0 && $status == 0) { echo '<p>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</p>'; } } else { $todo_items = CTDL_Lib::get_todos($user, $limit, $status, $cat_id); if ($todo_items->have_posts()) { $this->show_todo_list_items($todo_items, $status); } elseif ($status == 0) { echo '<p>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</p>'; } } }
/** * Creates the widget * @param $args * @param $instance * */ function widget($args, $instance) { global $ClevernessToDoList, $CTDL_widget_settings; $CTDL_widget_settings = $instance; get_currentuserinfo(); $title = apply_filters('widget_title', $instance['title']); $limit = $instance['number'] == '-1' ? 1000 : $instance['number']; $assigned_to = $instance['assigned_to']; $deadline = $instance['deadline']; $progress = $instance['progress']; $category = CTDL_Loader::$settings['categories'] == 1 ? $instance['category'] : 0; $individual = isset($instance['individual']) ? $instance['individual'] : 0; if ($individual == 1 && is_user_logged_in()) { global $current_user, $userdata; if (CTDL_Loader::$settings['list_view'] == '2') { $user = $current_user->ID; } else { $user = $userdata->ID; } } else { $user = 0; } echo $args['before_widget']; if ($title) { echo $args['before_title']; echo $title; echo $args['after_title']; } $ClevernessToDoList->list = ''; $visible = 0; if (CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] == 'cat_id' && $category == 0) { $categories = CTDL_Categories::get_categories(); $items = 0; $posts_to_exclude = array(); $visibility = get_option('CTDL_categories'); foreach ($categories as $category) { echo '<ol>'; $category_id = $category->term_id; $visible = $visibility["category_{$category->term_id}"]; $todo_items = CTDL_Lib::get_todos($user, $limit, 0, $category_id); if ($todo_items->have_posts()) { array_splice($posts_to_exclude, count($posts_to_exclude), 0, $this->show_todo_list_items($todo_items, $progress, $deadline, $assigned_to, 0, $visible)); $items = 1; } echo '</ol>'; } $todo_items = CTDL_Lib::get_todos($user, $limit, 0, 0, $posts_to_exclude); if ($todo_items->have_posts()) { echo '<ol>'; $this->show_todo_list_items($todo_items, $progress, $deadline, $assigned_to, 0, $visible); echo '</ol>'; $items = 1; } if ($items == 0) { echo '<p>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</p>'; } } else { echo '<ol>'; $todo_items = CTDL_Lib::get_todos($user, $limit, 0, $category); if ($todo_items->have_posts()) { $this->show_todo_list_items($todo_items, $progress, $deadline, $assigned_to, $category, $visible); } else { echo '<p>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</p>'; } } echo '</ol>'; echo $args['after_widget']; }
/** * Loop through to-do items * * @param int $completed * @param int $cat_id * @param int $limit */ protected function loop_through_todos($completed = 0, $cat_id = 0, $limit = 5000) { global $current_user, $userdata; $user = CTDL_Lib::get_user_id($current_user, $userdata); // if categories are enabled and sort order is set to cat id and we're not getting todos for a specific category if (CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] == 'cat_id' && $cat_id == 0) { $categories = CTDL_Categories::get_categories(); $items = 0; $visible = 0; $headings = 0; $posts_to_exclude = array(); $visibility = get_option('CTDL_categories'); foreach ($categories as $category) { $visible = $visibility["category_{$category->term_id}"]; $todo_items = CTDL_Lib::get_todos($user, 5000, $completed, $category->term_id); if ($todo_items->have_posts()) { if ($headings == 0) { $headings = $this->show_table_headings($completed); } array_splice($posts_to_exclude, count($posts_to_exclude), 0, $this->show_todo_list_items($todo_items, $completed, $visible)); $items = 1; } } $todo_items = CTDL_Lib::get_todos($user, 5000, $completed, 0, $posts_to_exclude); if ($todo_items->have_posts()) { if ($headings == 0) { $this->show_table_headings($completed); } $this->show_todo_list_items($todo_items, $completed); $items = 1; } if ($items == 0) { if ($completed == 0) { $this->list .= '<tr><td>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</td></tr>'; } else { $this->list .= '<tr><td>' . apply_filters('ctdl_no_completed_items', esc_html__('No completed items.', 'cleverness-to-do-list')) . '</td></tr>'; } } } else { $todo_items = CTDL_Lib::get_todos($user, 5000, $completed, $cat_id); if ($todo_items->have_posts()) { $this->show_table_headings($completed); $this->show_todo_list_items($todo_items, $completed); } else { if ($completed == 0) { $this->list .= '<tr><td>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</td></tr>'; } else { $this->list .= '<tr><td>' . apply_filters('ctdl_no_completed_items', esc_html__('No completed items.', 'cleverness-to-do-list')) . '</td></tr>'; } } } }