Open ruudvh opened 11 years ago
For one who wants to stay with jQuery UI.
Include the progress bar:
<div id="progressbar"></div>
Initialize the progress bar:
//Progress bar
$( "#progressbar" ).progressbar({
value: <?php cp_count_complete_tasks( cp_get_project_id() ); ?>,
max: <?php cp_count_tasks( cp_get_project_id() ); ?>
});
Count all task and tasklist:
/**
* Count all tasks for specific project
*/
function cp_count_tasks( $project_id = 0 ){
global $wpdb;
$meta_key = '_cp-project-id';
$meta_value = $project_id;
$post_type = 'cp-tasks';
$completedtasks_sql = "SELECT p.ID
FROM $wpdb->postmeta pm
JOIN $wpdb->posts p ON (p.ID = pm.post_id)
WHERE pm.meta_key = '$meta_key'
AND pm.meta_value = '$meta_value'
AND p.post_type = '$post_type'
AND p.post_status = 'publish';
";
$completedtasks = $wpdb->get_col($wpdb->prepare($completedtasks_sql));
$task_status_list = array();
foreach ( $completedtasks as $item ) {
$task_status = cp_get_task_status( $item );
$task_status_list[] = $task_status;
}
$totaltasks = count ($task_status_list);
echo $totaltasks;
}
/**
* Count all completed tasks for specific project
*/
function cp_count_complete_tasks( $project_id = 0 ){
global $wpdb;
$meta_key = '_cp-project-id';
$meta_value = $project_id;
$post_type = 'cp-tasks';
$completedtasks_sql = "SELECT p.ID
FROM $wpdb->postmeta pm
JOIN $wpdb->posts p ON (p.ID = pm.post_id)
WHERE pm.meta_key = '$meta_key'
AND pm.meta_value = '$meta_value'
AND p.post_type = '$post_type'
AND p.post_status = 'publish';
";
$completedtasks = $wpdb->get_col($wpdb->prepare($completedtasks_sql));
$task_status_list = array();
foreach ( $completedtasks as $item ) {
$task_status = cp_get_task_status( $item );
$task_status_list[] = $task_status;
}
$completedtasks = count( array_keys( $task_status_list, "complete" ));
echo $completedtasks;
}
Thanks for the contribution! I would highly suggest using WP_Query vs a custom database query.
Thank you! I was thinking about using WP_Query, but doesn't WP_Query pull the entire post? If true, this seem a bit unnecessary?
True. If all you want is post IDs you could use get_posts() and specify the parameter 'fields' => 'ID'. That will only return IDs, and not the entire post data.
The performance hit from loading all post data in this case will be very minimal, as the page will be loaded very infrequently (as opposed to a public-facing page).
It's a good idea to use WP_Query where possible for a number of reasons. In this case, the notable reason is that WP will then take care of all necessary caching (both persistent caching and the slurping up of metadata and terms that are needed by CP), which is likely to outweigh any decrease in overhead you get from doing a direct query. :)
On 06/24/13 10:46, Brad Williams wrote:
True. If all you want is post IDs you could use get_posts() and specify the parameter 'fields' => 'ID'. That will only return IDs, and not the entire post data.
— Reply to this email directly or view it on GitHub https://github.com/WebDevStudios/CollabPress/issues/88#issuecomment-19911454.
Hi everyone, thanks for the contribution. But somehow i can't get it working. I have tried both codes in my content-single-project.php and also added the css definitions in new.css, without success. Could you give me a hint?!
This is not an issue, more like an enhancement. But a progress bar for the project, probably based on the task added vs tasks completed, would be a great enhancement to the project.
Something like this. PHP:
CSS:
I'm not a programmer, so please excuse my mistakes.