source: branches/1.2/workflow/inc/jobs/class.WeekDate.inc.php @ 1349

Revision 1349, 3.5 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

Line 
1<?php
2/**************************************************************************\
3* eGroupWare                                                               *
4* http://www.egroupware.org                                                *
5* --------------------------------------------                             *
6*  This program is free software; you can redistribute it and/or modify it *
7*  under the terms of the GNU General Public License as published by the   *
8*  Free Software Foundation; either version 2 of the License, or (at your  *
9*  option) any later version.                                              *
10\**************************************************************************/
11
12require_once 'class.JobDate.inc.php';
13
14/**
15 * Classe para dias da semana
16 * @author Sidnei Augusto Drovetto Junior - drovetto@gmail.com
17 * @version 1.0
18 * @license http://www.gnu.org/copyleft/gpl.html GPL
19 * @package Workflow
20 * @subpackage Job
21 */
22class WeekDate extends JobDate
23{
24        /**
25         * @var int $weekDays Inteiro que representa os dias da semana quando o Job será executado
26         * @access private
27         */
28        private $weekDays;
29
30        /**
31         * Construtor da classe WeekDate
32         * @param object $startDate A data a partir da qual o Job é válido
33         * @param array $interval O intervalo de execução do Job
34         * @param int $weekDays Inteiro que representa os dias da semana
35         * @return object Objeto da classe WeekDate
36         * @access public
37         */
38        public function WeekDate($startDate, $interval, $weekDays = null)
39        {
40                parent::JobDate($startDate, $interval);
41                if (!is_null($weekDays))
42                        $this->setWeekDays($weekDays);
43        }
44
45        public function checkMatchesInterval($checkDate)
46        {
47                if (($checkDate->format('G:i') == $this->startDate->format('G:i')) && ($this->weekDays & $this->getWeekDay($checkDate)))
48                {
49                        $startSunday = new DateTime(date($this->startDate->format('Y-n-j') . ' 00:00:00'));
50                        if ($this->getWeekDay($startSunday) != WeekDays::SUNDAY)
51                                $startSunday->modify('-' . $startSunday->format('N') . ' day');
52
53                        $checkSunday = new DateTime(date($checkDate->format('Y-n-j') . ' 00:00:00'));
54                        if ($this->getWeekDay($checkSunday) != WeekDays::SUNDAY)
55                                $checkSunday->modify('-' . $checkSunday->format('N') . ' day');
56
57                        $weeksBetween = round(($checkSunday->format('U') - $startSunday->format('U')) / 604800);
58
59                        if ($this->interval['unity'] == DateUnity::NONE)
60                                return ($weeksBetween == 0);
61
62                        return ((($weeksBetween % $this->interval['value']) === 0) && ($checkDate->format('U') >= $this->startDate->format('U')));
63                }
64
65                return false;
66        }
67
68        /**
69         * Pega o inteiro que representa os dias da semana quando o Job será executado
70         * @return int $weekDays Inteiro que representa os dias da semana
71         * @access public
72         */
73        public function getWeekDays($weekDays)
74        {
75                return $this->weekDays;
76        }
77
78        /**
79         * Define o inteiro que representa os dias da semana quando o Job será executado
80         * @param int $weekDays Inteiro que representa os dias da semana
81         * @return void
82         * @access public
83         */
84        public function setWeekDays($weekDays)
85        {
86                $this->weekDays = $weekDays;
87        }
88
89        /**
90         * Pega o dia da semana de uma data
91         * @param object $date A data
92         * @return int O inteiro que representa o dia da semana da data
93         * @access public
94         */
95        static public function getWeekDay($date)
96        {
97                switch ($date->format('N'))
98                {
99                        case 1:
100                                return WeekDays::MONDAY;
101
102                        case 2:
103                                return WeekDays::TUESDAY;
104
105                        case 3:
106                                return WeekDays::WEDNESDAY;
107
108                        case 4:
109                                return WeekDays::THURSDAY;
110
111                        case 5:
112                                return WeekDays::FRIDAY;
113
114                        case 6:
115                                return WeekDays::SATURDAY;
116
117                        case 7:
118                                return WeekDays::SUNDAY;
119                }
120        }
121}
122?>
Note: See TracBrowser for help on using the repository browser.