function sa_load_time_tracking_addon() { if (class_exists('SI_Time')) { return; } require_once 'inc/Time.php'; require_once 'inc/Time_Tracking.php'; SI_Time::init(); SI_Time_Tracking_Premium::init(); }
public static function attempt_reassign_entries_to_default($post_id = 0) { // prevent looping and checking if a record has a record associated with it. if (get_post_type($post_id) !== SI_Record::POST_TYPE) { global $wpdb; $parent_update = array('post_parent' => SI_Time::default_time()); $parent_where = array('post_parent' => $post_id, 'post_type' => SI_Record::POST_TYPE); $wpdb->update($wpdb->posts, $parent_update, $parent_where); } }
/** * Remove single time to associated array * @param int $time_id */ public function remove_time_associated($time_id = 0) { // Delete time record $time = SI_Record::get_instance($time_id); if (is_a($time, 'SI_Record')) { $activity_id = $time->get_associate_id(); $activity = SI_Time::get_instance($activity_id); $activity->delete_time($time_id); } // Remove from associated array $times = $this->get_associated_times(); if (($key = array_search($time_id, $times)) !== false) { unset($times[$key]); } $this->set_associated_times($times); }
function change_si_get_time_title($title = '', SI_Time $time) { return get_the_title($time->get_id()); }
public static function toggl_entry_fields($project_id = 0) { $toggl_projects = array(0 => __('None', 'sprout-invoices'), 'create_new' => __('Create Project at Toggl', 'sprout-invoices')); foreach (Toggl_API::get_projects() as $key => $project) { $toggl_projects[$project->id] = $project->name; } $fields['toggl_id'] = array('weight' => 10, 'label' => __('Toggl Project', 'sprout-invoices'), 'type' => 'select', 'description' => __('Link a project at toggl or create a new one.', 'sprout-invoices'), 'options' => $toggl_projects, 'default' => self::get_projects_toggl_id($project_id), 'attributes' => array('class' => 'select2')); $fields['sync_time'] = array('weight' => 50, 'label' => __('Sync Time with Toggl', 'sprout-invoices'), 'type' => 'checkbox', 'default' => self::does_sync_time($project_id), 'description' => __('Automatically send time created here to Toggle and delete any time at Toggl if deleted here.', 'sprout-invoices')); $fields['pulldown_time'] = array('weight' => 60, 'label' => __('Retrieve Project Time from Toggl', 'sprout-invoices'), 'type' => 'checkbox', 'description' => __('Check, then save to import time for this project. Time does not import automatically (yet).', 'sprout-invoices')); $activities = SI_Time::get_activities(); $fields['default_activity'] = array('weight' => 70, 'label' => __('Activity for Imported Time', 'sprout-invoices'), 'type' => 'select', 'options' => $activities, 'default' => self::get_projects_default_time_import_activity($project_id), 'description' => __('Check, then save to import time for this project. Time does not import automatically (yet).', 'sprout -invoices'), 'attributes' => array('class' => 'select2')); $fields = apply_filters('si_toggl_time_entry_form_fields', $fields); uasort($fields, array(__CLASS__, 'sort_by_weight')); return $fields; }
?> </th> </tr> </thead> <tbody> <?php $shown_item = 0; krsort($unbilled_time); foreach ($unbilled_time as $time_id => $data) { $shown_item++; // only show 5 if ($shown_item > 5) { break; } $time = SI_Time::get_time_entry($time_id); $activity = SI_Time::get_instance($time->get_associate_id()); $cost = is_a($activity, 'SI_Time') ? $data['time_val'] * $activity->get_default_rate() : 0; $unbilled_total_time += (double) $data['time_val']; $unbilled_total_cost += $cost; $user = get_userdata($data['user_id']); ?> <tr id="<?php echo (int) $time_id; ?> "> <td><span class="time_submitted_by"><a href="<?php echo get_edit_user_link($user->ID); ?> "><?php echo $user->data->display_name; ?>
</th> <th><?php _e('Billable', 'sprout-invoices'); ?> </th> </tr> </thead> <tbody> <?php if (!empty($time)) { ?> <?php foreach ($time as $time_id) { ?> <?php $time = SI_Time::get_instance($time_id); if (!is_a($time, 'SI_Time')) { continue; } ?> <tr id="<?php echo (int) $time_id; ?> "> <td><span class="time_activity_deletion item_action item_delete" data-id="<?php echo (int) $time_id; ?> " data-nonce="<?php echo wp_create_nonce(SI_Time_Tracking_Premium::SUBMISSION_NONCE); ?> "></span></td>
public static function get_activities($time_types = array()) { if (empty($time_types)) { $args = array('post_type' => self::POST_TYPE, 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids'); $time_types = get_posts($args); } $time_types_options = array(); foreach ($time_types as $time_id) { $time = SI_Time::get_instance($time_id); if (is_a($time, 'SI_Time')) { $time_types_options[$time_id] = $time->get_title(); } } return $time_types_options; }