[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Vtiger/uitypes/ -> Time.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  
  11  class Vtiger_Time_UIType extends Vtiger_Base_UIType {
  12  
  13      /**
  14       * Function to get the Template name for the current UI Type object
  15       * @return <String> - Template Name
  16       */
  17  	public function getTemplateName() {
  18          return 'uitypes/Time.tpl';
  19      }
  20  
  21      /**
  22       * Function to get display value for time
  23       * @param <String> time
  24       * @return <String> time
  25       */
  26  	public static function getDisplayTimeValue($time) {
  27          $date = new DateTimeField($time);
  28          return $date->getDisplayTime();
  29      }
  30  
  31      /**
  32       * Function to get time value in AM/PM format
  33       * @param <String> $time
  34       * @return <String> time
  35       */
  36  	public static function getTimeValueInAMorPM($time) {
  37          if($time){
  38              list($hours, $minutes, $seconds) = explode(':', $time);
  39              $format = vtranslate('PM');
  40  
  41              if ($hours > 12) {
  42                  $hours = (int)$hours - 12;
  43              } else if ($hours < 12) {
  44                  $format = vtranslate('AM');
  45              }
  46  
  47              //If hours zero then we need to make it as 12 AM
  48              if($hours == '00') {
  49                  $hours = '12';
  50                  $format = vtranslate('AM');
  51              }
  52  
  53              return "$hours:$minutes $format";
  54          } else {
  55              return '';
  56          }
  57      }
  58  
  59      /**
  60       * Function to get Time value with seconds
  61       * @param <String> $time
  62       * @return <String> time
  63       */
  64  	public static function getTimeValueWithSeconds($time) {
  65          if($time){
  66              $timeDetails = explode(' ', $time);
  67              list($hours, $minutes, $seconds) = explode(':', $timeDetails[0]);
  68  
  69              //If pm exists and if it not 12 then we need to make it to 24 hour format
  70              if ($timeDetails[1] === 'PM' && $hours != '12') {
  71                  $hours = $hours+12;
  72              }
  73  
  74              if($timeDetails[1] === 'AM' && $hours == '12'){
  75                  $hours = '00';
  76              }
  77  
  78              if(empty($seconds)) {
  79                  $seconds = '00';
  80              }
  81  
  82              return "$hours:$minutes:$seconds";
  83          }else{
  84              return '';
  85          }
  86      }
  87      
  88      /**
  89       * Function to get the Display Value, for the current field type with given DB Insert Value
  90       * @param <Object> $value
  91       * @return $value
  92       */
  93  	public function getDisplayValue($value) {
  94          $userModel = Users_Privileges_Model::getCurrentUserModel();
  95          if($userModel->get('hour_format') == '12'){
  96              return self::getTimeValueInAMorPM($value);
  97          }
  98          return $value;
  99      }
 100      
 101      /**
 102       * Function to get the display value in edit view
 103       * @param $value
 104       * @return converted value
 105       */
 106  	public function getEditViewDisplayValue($value) {
 107          return self::getTimeValueInAMorPM($value);
 108      }
 109      
 110      public function getListSearchTemplateName() {
 111          return 'uitypes/TimeFieldSearchView.tpl';
 112      }
 113      
 114  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1