public static function getInstance() { if (!self::$_instance) { self::$_instance = new CPM_Milestone(); } return self::$_instance; }
function get_events() { $projects = CPM_Project::getInstance()->get_projects(); unset($projects['total_projects']); if (cpm_get_option('task_start_field') == 'on') { $enable_start = true; } else { $enable_start = false; } $events = array(); if ($projects) { foreach ($projects as $project) { $project_id = $project->ID; if (absint($_POST['project_id']) && $project_id != absint($_POST['project_id'])) { continue; } //Get Milestones $milestones = CPM_Milestone::getInstance()->get_by_project($project_id); if ($milestones) { foreach ($milestones as $milestone) { //Milestone Event $events[] = array('id' => $milestone->ID, 'title' => $milestone->post_title, 'start' => $milestone->due_date, 'url' => cpm_url_milestone_index($project_id), 'color' => '#32b1c8', 'className' => $milestone->completed == 1 ? 'milestone competed' : 'milestone'); } } //Get Tasks if (cpm_user_can_access($project_id, 'tdolist_view_private')) { $task_lists = CPM_Task::getInstance()->get_task_lists($project_id, true); } else { $task_lists = CPM_Task::getInstance()->get_task_lists($project_id); } if ($task_lists) { foreach ($task_lists as $task_list) { $tasks = CPM_Task::getInstance()->get_tasks_by_access_role($task_list->ID, $project_id); foreach ($tasks as $task) { $image = ''; if (is_array($task->assigned_to)) { foreach ($task->assigned_to as $key => $user_id) { $image .= get_avatar($user_id, 16); } } else { $image .= get_avatar($task->assigned_to, 16); } //Tasks Event if ($enable_start) { if (isset($task->start_date) && !empty($task->start_date)) { $start_date = $task->start_date; } else { $start_date = $task->due_date; } $events[] = array('id' => $task->ID, 'img' => $task->assigned_to == -1 ? '' : $image, 'title' => $task->post_title, 'start' => $start_date, 'end' => $task->due_date, 'complete_status' => $task->completed == 1 ? 'yes' : 'no', 'url' => cpm_url_single_task($project_id, $task_list->ID, $task->ID), 'color' => 'transparent', 'textColor' => '#c86432', 'className' => date('Y-m-d', time()) < $task->due_date ? 'cpm-calender-todo cpm-task-running' : 'cpm-calender-todo cpm-expire-task'); } else { $events[] = array('id' => $task->ID, 'img' => $task->assigned_to == -1 ? '' : $image, 'title' => $task->post_title, 'start' => $task->due_date, 'complete_status' => $task->completed == 1 ? 'yes' : 'no', 'url' => cpm_url_single_task($project_id, $task_list->ID, $task->ID), 'color' => 'transparent', 'textColor' => '#c86432', 'className' => date('Y-m-d', time()) < $task->due_date ? 'cpm-calender-todo cpm-task-running' : 'cpm-calender-todo cpm-expire-task'); } } } } } } return $events; }
/** * Insert milestone type item * * @param init $project_id * * @since 1.1 * * @return type */ function cpm_insert_milestone($project_id) { global $wpdb; $table_name = $wpdb->prefix . 'cpm_project_items'; $milestones = CPM_Milestone::getInstance()->get_by_project($project_id, true); foreach ($milestones as $milestone) { $complete = $milestone->completed ? $milestone->completed_on : '0000-00-00 00:00:00'; CPM_Project::getInstance()->new_project_item($project_id, $milestone->ID, $milestone->private, 'milestone', false, $complete, $milestone->completed); } }
function instantiate() { $project = CPM_Project::getInstance(); $message = CPM_Message::getInstance(); $task = CPM_Task::getInstance(); $milestone = CPM_Milestone::getInstance(); $activity = new CPM_Activity(); $ajax = new CPM_Ajax(); $notification = new CPM_Notification(); }
/** * Instantiate all the required classes * * @since 0.1 */ function instantiate() { CPM_Project::getInstance(); CPM_Message::getInstance(); CPM_Task::getInstance(); CPM_Milestone::getInstance(); new CPM_Activity(); new CPM_Ajax(); new CPM_Notification(); // instantiate admin settings only on admin page if (is_admin()) { new CPM_Admin(); } }
function milestone_get() { check_ajax_referer('cpm_nonce'); $posted = $_POST; $project_id = isset($posted['project_id']) ? intval($posted['project_id']) : 0; $milestone_id = isset($posted['id']) ? intval($posted['id']) : 0; $milestone = CPM_Milestone::getInstance()->get($milestone_id); echo json_encode(array('success' => true, 'id' => $milestone_id, 'content' => cpm_milestone_form($project_id, $milestone))); exit; }
/** * Delete project child elements * * Delete all child task lists, messages and milestones when * a project is deleted. * * @param int $project_id * * @since 0.5.4 * * @return void */ function cpm_delete_project_child($project_id) { $childrens = get_posts(array('post_type' => array('task_list', 'message', 'milestone'), 'post_pre_page' => '-1', 'post_parent' => $project_id)); foreach ($childrens as $key => $children) { switch ($children->post_type) { case 'task_list': CPM_Task::getInstance()->delete_list($children->ID, true); break; case 'message': CPM_Message::getInstance()->delete($children->ID, true); break; case 'milestone': CPM_Milestone::getInstance()->delete($children->ID, true); break; } } }
/** * Instantiate all the required classes * * @since 0.1 */ function instantiate() { $this->project = CPM_Project::getInstance(); $this->message = CPM_Message::getInstance(); $this->task = CPM_Task::getInstance(); $this->milestone = CPM_Milestone::getInstance(); $this->activity = new CPM_Activity(); $this->ajax = new CPM_Ajax(); $this->notification = new CPM_Notification(); // instantiate admin settings only on admin page if (is_admin()) { $this->admin = new CPM_Admin(); $this->updates = new CPM_Updates(); $this->upgrade = new CPM_Upgrade(); } }
cpm_get_header(__('Milestones', 'cpm'), $project_id); ?> <h3 class="cpm-nav-title"> <?php _e('Milestones', 'cpm'); ?> <a id="cpm-add-milestone" href="#" class="add-new-h2"><?php _e('Add Milestone', 'cpm'); ?> </a> </h3> <?php $milestone_obj = CPM_Milestone::getInstance(); $milestones = $milestone_obj->get_by_project($project_id); $completed_milestones = array(); $late_milestones = array(); $upcoming_milestones = array(); if ($milestones) { foreach ($milestones as $milestone) { $due = strtotime($milestone->due_date); $is_left = cpm_is_left(time(), $due); $milestone_completed = (int) $milestone->completed; if ($milestone_completed) { $completed_milestones[] = $milestone; } else { if ($is_left) { $upcoming_milestones[] = $milestone; } else {
/** * Generates markup for a single milestone * * @since 0.1 * @param object $milestone * @param int $project_id */ function cpm_show_milestone($milestone, $project_id) { $milestone_obj = CPM_Milestone::getInstance(); $task_obj = CPM_Task::getInstance(); $due = strtotime($milestone->due_date); $is_left = cpm_is_left(time(), $due); $milestone_completed = (int) $milestone->completed; if ($milestone_completed) { $class = 'complete'; } else { $class = $is_left == true ? 'left' : 'late'; } $string = $is_left == true ? __('left', 'cpm') : __('late', 'cpm'); $milestone_private = $milestone->private == 'yes' ? 'cpm-lock' : 'cpm-unlock'; ?> <div class="cpm-milestone <?php echo $class; ?> "> <div class="milestone-detail"> <h3> <?php echo $milestone->post_title; ?> <?php if (!$milestone_completed) { ?> <span class="time-left">(<?php printf('%s %s - %s', human_time_diff(time(), $due), $string, cpm_get_date($milestone->due_date)); ?> )</span> <?php } ?> <?php if (cpm_user_can_delete_edit($project_id, $milestone)) { ?> <ul class="cpm-links cpm-right"> <li> <a class="cpm-icon-edit" <?php cpm_data_attr(array('id' => $milestone->ID, 'project_id' => $project_id)); ?> href="#" title="<?php esc_attr_e('Edit milestone', 'cpm'); ?> "><span><?php _e('Edit', 'cpm'); ?> </span></a> </li> <li> <a class="cpm-icon-delete cpm-milestone-delete" <?php cpm_data_attr(array('project' => $project_id, 'id' => $milestone->ID, 'confirm' => __('Are you sure?', 'cpm'))); ?> title="<?php esc_attr_e('Delete milestone', 'cpm'); ?> " href="#"><span><?php _e('Delete', 'cpm'); ?> </span></a> </li> <?php if ($milestone->completed == '0') { ?> <li><a class="cpm-icon-tick grey cpm-milestone-complete" data-project="<?php echo $project_id; ?> " data-id="<?php echo esc_attr($milestone->ID); ?> " title="<?php esc_attr_e('Mark as complete', 'cpm'); ?> " href="#"><span><?php _e('Mark as complete', 'cpm'); ?> </span></a></li> <?php } else { ?> <li><a class="cpm-icon-tick green cpm-milestone-open" data-project="<?php echo $project_id; ?> " data-id="<?php echo esc_attr($milestone->ID); ?> " title="<?php esc_attr_e('Mark un-complete', 'cpm'); ?> " href="#"><span><?php _e('Reopen', 'cpm'); ?> </span></a></li> <?php } ?> <li> <span class="<?php echo $milestone_private; ?> "></span> </li> </ul> <?php } ?> </h3> <div class="detail"> <?php echo cpm_get_content($milestone->post_content); ?> </p> </div> </div> <div class="cpm-milestone-edit-form"></div> <?php if (cpm_user_can_access($project_id, 'tdolist_view_private')) { $tasklists = $milestone_obj->get_tasklists($milestone->ID, true); } else { $tasklists = $milestone_obj->get_tasklists($milestone->ID); } if (cpm_user_can_access($project_id, 'msg_view_private')) { $messages = $milestone_obj->get_messages($milestone->ID, true); } else { $messages = $milestone_obj->get_messages($milestone->ID); } if ($tasklists) { ?> <h3><?php _e('To-do List', 'cpm'); ?> </h3> <ul class="dash"> <?php foreach ($tasklists as $tasklist) { ?> <li> <a href="<?php echo cpm_url_single_tasklist($project_id, $tasklist->ID); ?> "><?php echo stripslashes($tasklist->post_title); ?> </a> <div class="cpm-right"> <?php $complete = $task_obj->get_completeness($tasklist->ID, $project_id); echo cpm_task_completeness($complete['total'], $complete['completed']); ?> </div> <div class="cpm-clear"></div> </li> <?php } ?> </ul> <?php } ?> <?php if ($messages) { ?> <h3><?php _e('Messages', 'cpm'); ?> </h3> <ul class="dash"> <?php foreach ($messages as $message) { ?> <li> <a href="<?php echo cpm_url_single_message($project_id, $message->ID); ?> "><?php echo stripslashes($message->post_title); ?> </a> (<?php echo cpm_get_date($message->post_date, true); ?> | <?php echo get_the_author_meta('display_name', $message->post_author); ?> ) </li> <?php } ?> </ul> <?php } ?> <?php if ($milestone_completed) { ?> <span class="cpm-milestone-completed"> <?php _e('Completed on:', 'cpm'); ?> <?php echo cpm_get_date($milestone->completed_on, true); ?> </span> <?php } ?> </div> <?php }
/** * Instantiate all the required classes * * @since 0.1 */ function instantiate() { $this->project = CPM_Project::getInstance(); $this->message = CPM_Message::getInstance(); $this->task = CPM_Task::getInstance(); $this->milestone = CPM_Milestone::getInstance(); $this->activity = CPM_Activity::getInstance(); $this->ajax = CPM_Ajax::getInstance(); $this->notification = CPM_Notification::getInstance(); if (function_exists('json_api_init')) { $this->api = CPM_API::instance(); } // instantiate admin settings only on admin page if (is_admin()) { $this->admin = new CPM_Admin(); $this->upgrade = new CPM_Upgrade(); } do_action('cpm_instantiate', $this); }