[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Calendar/ -> Calendar.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  require_once ('modules/Calendar/Appointment.php');
  12  require_once ('modules/Calendar/Date.php');
  13  class Calendar 
  14  {
  15      var $view='day';
  16      var $date_time;
  17      var $hour_format = 12;
  18      var $day_slice;
  19      var $week_slice;
  20      var $week_array;
  21      var $month_array;
  22      var $week_hour_slices = Array();
  23      var $slices = Array();
  24      /* for dayview */
  25      var $day_start_hour=0;
  26      var $day_end_hour=23;
  27      var $sharedusers=Array();
  28      /*
  29      constructor
  30      */
  31      //var $groupTable = Array('vtiger_activitygrouprelation','activityid');
  32  	function Calendar($view='',$data=Array())
  33      {
  34          $this->view = $view;
  35          $this->date_time = new vt_DateTime($data,true);
  36          $this->constructLayout();
  37      }
  38      /**
  39       * Function to get calendarview Label
  40       * @param string  $view   - calendarview
  41       * return string  - calendarview Label 
  42      */
  43  	function getCalendarView($view)
  44      {
  45          switch($view)
  46                  {
  47              case 'day':
  48                  return "DAY";
  49              case 'week':
  50                  return "WEEK";
  51              case 'month':
  52                  return "MON";
  53              case 'year':
  54                  return "YEAR";
  55          }
  56      }
  57  
  58      /**
  59       * Function to set values for calendar object depends on calendar view
  60      */
  61  	function constructLayout()
  62      {
  63          global $current_user;
  64          switch($this->view)
  65          {
  66              case 'day':
  67                  for($i=-1;$i<=23;$i++)
  68                  {
  69                      if($i == -1)
  70                      {
  71                          $layout = new Layout('hour',$this->date_time->getTodayDatetimebyIndex(0));
  72                          $this->day_slice[$layout->start_time->get_formatted_date().':notime'] = $layout;
  73                          $this->slices['notime'] = $layout->start_time->get_formatted_date().":notime";
  74                      }
  75                      else
  76                      {
  77                          $layout = new Layout('hour',$this->date_time->getTodayDatetimebyIndex($i));
  78                          $this->day_slice[$layout->start_time->get_formatted_date().':'.$layout->start_time->z_hour] = $layout;
  79                          array_push($this->slices,  $layout->start_time->get_formatted_date().":".$layout->start_time->z_hour);
  80                      }
  81                  }
  82                  break;
  83              case 'week':
  84                  $weekview_days = 7;
  85                  for($i=1;$i<=$weekview_days;$i++)
  86                  {
  87                      $layout = new Layout('day',$this->date_time->getThisweekDaysbyIndex($i));
  88                      $this->week_array[$layout->start_time->get_formatted_date()] = $layout;
  89  
  90                      for($h=-1;$h<=23;$h++)
  91                      {
  92                          if($h == -1)
  93                          {
  94                              $hour_list = new Layout('hour',$this->date_time->getTodayDatetimebyIndex(0,$layout->start_time->day,$layout->start_time->month,$layout->start_time->year));
  95                              $this->week_slice[$layout->start_time->get_formatted_date().':notime'] = $hour_list;
  96                              $this->week_hour_slices['notime'] = $layout->start_time->get_formatted_date().":notime"; 
  97                          }
  98                          else
  99                          {
 100                              $hour_list = new Layout('hour',$this->date_time->getTodayDatetimebyIndex($h,$layout->start_time->day,$layout->start_time->month,$layout->start_time->year));
 101                              $this->week_slice[$layout->start_time->get_formatted_date().':'.$hour_list->start_time->z_hour] = $hour_list;
 102                              array_push($this->week_hour_slices,  $layout->start_time->get_formatted_date().":".$hour_list->start_time->z_hour);
 103                          }
 104                      }
 105                      array_push($this->slices,  $layout->start_time->get_formatted_date());
 106                      
 107                  }
 108                  break;
 109              case 'month':
 110                  $arr = getCalendarDaysInMonth($this->date_time);
 111                  $this->month_array = $arr["month_array"];
 112                  $this->slices = $arr["slices"];
 113                  $this->date_time = $arr["date_time"];
 114                  break;
 115              case 'year':
 116                  $this->month_day_slices = Array();
 117                  for($i=0;$i<12;$i++){
 118                      $currMonth = $this->date_time->getThisyearMonthsbyIndex($i);
 119                      $layout = new Layout('month',$this->date_time->getThisyearMonthsbyIndex($i));
 120                      $this->year_array[$layout->start_time->z_month] = $layout;
 121                      
 122                      $arr = getCalendarDaysInMonth($currMonth);
 123                      $slices = $arr["slices"];
 124                      
 125                      $this->month_day_slices[$i] = $slices;
 126                      array_push($this->slices,  $layout->start_time->z_month);
 127                  }
 128                  break;
 129          }
 130      }
 131  
 132      /**
 133       * Function to get date info depends on calendarview
 134       * @param  string   $type  - string 'increment' or 'decrment'
 135       */
 136  
 137  	function get_datechange_info($type)
 138      {
 139          if($type == 'next')
 140              $mode = 'increment';    
 141          if($type == 'prev')
 142              $mode = 'decrment';
 143          switch($this->view)
 144          {
 145              case 'day':
 146                  $day = $this->date_time->get_changed_day($mode);
 147                  break;
 148              case 'week':
 149                  $day = $this->date_time->get_first_day_of_changed_week($mode);
 150                  break;
 151              case 'month':
 152                  $day = $this->date_time->get_first_day_of_changed_month($mode);
 153                  break;
 154              case 'year':
 155                  $day = $this->date_time->get_first_day_of_changed_year($mode);
 156                  break;
 157              default:
 158                  return "view is not supported";
 159          }
 160          return $day->get_date_str();
 161      }
 162      
 163      /**
 164       * Function to get activities
 165       * @param  array $current_user  - user data
 166       * @param  string $free_busy    - 
 167       */
 168  	function add_Activities($current_user,$free_busy='')
 169      {
 170          if(isset($current_user->start_hour) && $current_user->start_hour !='')
 171          {
 172              list($sthour,$stmin)= explode(":",$current_user->start_hour);
 173              $hr = $sthour+0;
 174              $this->day_start_hour=$hr;
 175          }    
 176          else
 177          {
 178              $this->day_start_hour=8;
 179          }
 180          if(isset($current_user->end_hour) && $current_user->end_hour !='')
 181          {
 182              list($endhour,$endmin)=explode(":",$current_user->end_hour);
 183              $endhour = $endhour+0;
 184              $this->day_end_hour=$endhour;
 185          }
 186          else
 187          {
 188              $this->day_end_hour=23;
 189          }
 190          if ( $this->view == 'week'){
 191              $start_datetime = $this->date_time->getThisweekDaysbyIndex(1);
 192              $end_datetime = $this->date_time->getThisweekDaysbyIndex(7);
 193          } elseif($this->view == 'month') {
 194              $start_datetime = $this->date_time->getThismonthDaysbyIndex(0);
 195              $end_datetime = $this->date_time->getThismonthDaysbyIndex($this->date_time->daysinmonth-1);
 196          } elseif($this->view == 'year'){
 197              $start_datetime = $this->date_time->getThisyearMonthsbyIndex(0);
 198              $end_datetime = $this->date_time->get_first_day_of_changed_year('increment');
 199          }else {
 200              $start_datetime = $this->date_time;
 201                          $end_datetime = $this->date_time->getTodayDatetimebyIndex(23);
 202                  }
 203          
 204          $activities = Array();
 205          $activities = Appointment::readAppointment($current_user->id,$start_datetime,$end_datetime,$this->view);
 206          if(!empty($activities))
 207          {
 208              foreach($activities as $key=>$value)
 209              {
 210                  if($this->view == 'day')
 211                  {
 212                      if(empty($this->day_slice[$value->formatted_datetime]->activities)) {
 213                          $this->day_slice[$value->formatted_datetime]->activities = array();
 214                      }
 215                      array_push($this->day_slice[$value->formatted_datetime]->activities, $value);
 216                  }
 217                  elseif($this->view == 'week')
 218                  {
 219                      if(empty($this->week_slice[$value->formatted_datetime]->activities)) {
 220                          $this->week_slice[$value->formatted_datetime]->activities = array();
 221                      }
 222                      array_push($this->week_slice[$value->formatted_datetime]->activities, $value);
 223                  }
 224                  elseif($this->view == 'month')
 225                  {
 226                      if(empty($this->month_array[$value->formatted_datetime]->activities)) {
 227                          $this->month_array[$value->formatted_datetime]->activities = array();
 228                      }
 229                      array_push($this->month_array[$value->formatted_datetime]->activities,$value);
 230                  }
 231                  elseif($this->view == 'year')
 232                  {
 233                      if(empty($this->year_array[$value->formatted_datetime]->activities)) {
 234                          $this->year_array[$value->formatted_datetime]->activities = array();
 235                      }
 236                      array_push($this->year_array[$value->formatted_datetime]->activities,$value);
 237                  }
 238                  else
 239                      die("view:".$this->view." is not defined");
 240  
 241              }
 242          }
 243          
 244      }
 245  }
 246  
 247  class Layout
 248  {
 249      var $view = 'day';
 250      var $start_time;
 251      var $end_time;
 252      var $activities = Array();
 253      
 254      /**
 255      * Constructor for Layout class
 256      * @param  string   $view - calendarview
 257      * @param  string   $time - time string 
 258      */
 259  
 260  	function Layout($view,$time)
 261          {
 262                  $this->view = $view;
 263                  $this->start_time = $time;
 264          if ( $view == 'month')
 265               $this->end_time = $this->start_time->getMonthendtime();
 266                  if ( $view == 'day')
 267                          $this->end_time = $this->start_time->getDayendtime();
 268                  if ( $view == 'hour')
 269                          $this->end_time = $this->start_time->getHourendtime();
 270          }
 271  
 272      /**
 273      * Function to get view 
 274      * return currentview
 275      */
 276  
 277  	function getView()
 278      {
 279          return $this->view;
 280      }
 281  }
 282  
 283  /**
 284   * this function returns the days in a month in an array format
 285   * @param object $date_time - the date time object for the current month
 286   * @return array $result - the array containing current months days information
 287   */
 288  function getCalendarDaysInMonth($date_time){
 289      global $current_user;
 290      $month_array = array();
 291      $slices = array();
 292      $monthview_days = $date_time->daysinmonth;
 293      
 294      $firstday_of_month = $date_time->getThisMonthsDayByIndex(0);
 295      $fdom = $firstday_of_month;
 296      
 297      $num_of_prev_days = ($fdom->dayofweek+7)%7-1;
 298      for($i=-$num_of_prev_days;$i<42;$i++){
 299          $pd = $date_time->getThisMonthsDayByIndex($i);
 300          
 301          $layout = new Layout('day', $pd);
 302          $date = $layout->start_time->get_formatted_date();
 303          $month_array[$date] = $layout;
 304          array_push($slices,  $date);
 305      }
 306      
 307      $result = array("month_array"=>$month_array, "slices"=>$slices, "date_time"=>$date_time);
 308      return $result;
 309  }
 310  ?>


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