public static function time_entry_fields($context = 0, $hide_project_select = false)
 {
     $projects = array();
     $time_types = array();
     if (!$context) {
         $context = get_the_id();
     }
     // Get associated projects based on context
     switch (get_post_type($context)) {
         case SI_Project::POST_TYPE:
             $project_id = $context;
             // Projects
             $projects = array($project_id);
             break;
         case SI_Client::POST_TYPE:
             $client_id = $context;
             // Projects
             $projects = SI_Project::get_projects_by_client($client_id);
             break;
         case SI_Invoice::POST_TYPE:
             $invoice_id = $context;
             // Projects
             $invoice = SI_Invoice::get_instance($invoice_id);
             $project_id = $invoice->get_project();
             if ($project_id) {
                 $projects = array($project_id);
             }
             break;
         default:
             // Projects
             $args = array('post_type' => SI_Project::POST_TYPE, 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids');
             $projects = get_posts($args);
             break;
     }
     $fields = array();
     $project_options = array();
     foreach ($projects as $project_id) {
         $title = get_the_title($project_id);
         $title = $title == __('Auto Draft') ? __('Current Project', 'sprout-invoices') : $title;
         $project_options[$project_id] = $title;
     }
     $fields['project_id'] = array('weight' => 1, 'label' => __('Project', 'sprout-invoices'), 'type' => 'select', 'options' => $project_options);
     $description = sprintf(__('Select an activity, <a href="%s">create a new activity</a> or <a class="thickbox" href="%s" title="Edit Activities">manage existing activities</a>.', 'sprout-invoices'), 'javascript:void(0)" id="show_time_creation_modal"', admin_url('admin-ajax.php?action=sa_manage_time&width=750&height=450'));
     $time_types_options = SI_Time::get_activities();
     $fields['activity_id'] = array('weight' => 10, 'label' => __('Activity', 'sprout-invoices'), 'type' => 'select', 'description' => $description, 'options' => $time_types_options);
     $fields['time_inc'] = array('weight' => 20, 'label' => __('Time', 'sprout-invoices'), 'type' => 'text', 'description' => __('In hours, e.g. 1.25 for 75 minutes.', 'sprout-invoices'));
     $fields['note'] = array('weight' => 30, 'label' => __('Note', 'sprout-invoices'), 'type' => 'textarea', 'default' => '');
     $fields['date'] = array('weight' => 100, 'label' => __('Date', 'sprout-invoices'), 'type' => 'date', 'default' => date('Y-m-d', current_time('timestamp')), 'placeholder' => '');
     $fields['nonce'] = array('type' => 'hidden', 'value' => wp_create_nonce(self::SUBMISSION_NONCE), 'weight' => 10000);
     $fields = apply_filters('si_time_entry_form_fields', $fields);
     uasort($fields, array(__CLASS__, 'sort_by_weight'));
     return $fields;
 }
 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;
 }