/**
 * Render object time widget
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_time($params, &$smarty)
{
    if (!module_loaded('timetracking')) {
        return '';
    }
    // if
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('$object', $object, '$object is expected to be a valid instance of ProjectObject class');
    }
    // if
    $show_time = '';
    $additional_class = '';
    if (array_var($params, 'show_time', true)) {
        $object_time = TimeRecords::sumObjectTime($object);
        if ($object->can_have_tasks) {
            $tasks_time = TimeRecords::sumTasksTime($object);
        } else {
            $tasks_time = 0;
        }
        // if
        $additional_class = 'with_text';
        $total_time = $object_time + $tasks_time;
        if ($object_time == 0 && $tasks_time == 0) {
            $show_time = '<span class="time_widget_text">' . lang('No time tracked') . '</span> ';
        } elseif ($tasks_time == 0) {
            $show_time = '<span class="time_widget_text">' . lang(':total hours logged', array('total' => float_format($total_time, 2))) . '</span> ';
        } else {
            $show_time = '<span class="time_widget_text">' . lang(':total hours logged - :object_time for the ticket and :tasks_time for tasks', array('type' => $object->getVerboseType(true), 'total' => float_format($total_time, 2), 'object_time' => float_format($object_time, 2), 'tasks_time' => float_format($tasks_time, 2))) . '</span> ';
        }
        // if
    }
    // if
    $wrapper_id = 'object_time_widget_' . $object->getId();
    $image_url = $object->getHasTime() ? get_image_url('clock-small.gif') : get_image_url('gray-clock-small.gif');
    return '<span id="' . $wrapper_id . '" class="time_popup_widget ' . $additional_class . '">' . $show_time . '<a href="' . $object->getTimeUrl() . '" title="' . lang('Time') . '"><img src="' . $image_url . '" alt="" /></a></span><script type="text/javascript">App.TimePopup.init("' . $wrapper_id . '")</script>';
}
 /**
  * Render popup content
  *
  * @param void
  * @return null
  */
 function _render_popup_content()
 {
     if (!instance_of($this->active_object, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (TimeRecord::canAdd($this->logged_user, $this->active_project)) {
         $add_record_url = timetracking_module_add_record_url($this->active_project, array('for' => $this->active_object->getId(), 'for_popup_dialog' => 1));
     } else {
         $add_record_url = false;
     }
     // if
     $object_time = TimeRecords::sumObjectTime($this->active_object);
     $tasks_time = $this->active_object->can_have_tasks ? TimeRecords::sumTasksTime($this->active_object) : 0;
     $this->smarty->assign(array('selected_user' => $this->logged_user, 'selected_date' => new DateValue(time() + get_user_gmt_offset($this->logged_user)), 'selected_billable_status' => BILLABLE_STATUS_BILLABLE, 'object_time' => float_format($object_time, 2), 'tasks_time' => float_format($tasks_time, 2), 'total_time' => float_format($object_time + $tasks_time, 2), 'add_url' => $add_record_url));
     $this->smarty->display(get_template_path('_popup', null, TIMETRACKING_MODULE));
     die;
 }