source: branches/1.2/workflow/inc/log/Log/mcal.php @ 1349

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

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

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * $Header: /repository/pear/Log/Log/mcal.php,v 1.18 2005/02/26 14:48:58 chagenbu Exp $
4 * $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $
5 *
6 * @version $Revision: 1.18 $
7 * @package Log
8 */
9
10/**
11 * The Log_mcal class is a concrete implementation of the Log::
12 * abstract class which sends messages to a local or remote calendar
13 * store accessed through MCAL.
14 *
15 * @author  Chuck Hagenbuch <chuck@horde.org>
16 * @since Horde 1.3
17 * @since Log 1.0
18 * @package Log
19 */
20class Log_mcal extends Log
21{
22    /**
23     * holding the calendar specification to connect to.
24     * @var string
25     * @access private
26     */
27    var $_calendar = '{localhost/mstore}';
28
29    /**
30     * holding the username to use.
31     * @var string
32     * @access private
33     */
34    var $_username = '';
35
36    /**
37     * holding the password to use.
38     * @var string
39     * @access private
40     */
41    var $_password = '';
42
43    /**
44     * holding the options to pass to the calendar stream.
45     * @var integer
46     * @access private
47     */
48    var $_options = 0;
49
50    /**
51     * ResourceID of the MCAL stream.
52     * @var string
53     * @access private
54     */
55    var $_stream = '';
56
57    /**
58     * Integer holding the log facility to use.
59     * @var string
60     * @access private
61     */
62    var $_name = LOG_SYSLOG;
63
64
65    /**
66     * Constructs a new Log_mcal object.
67     *
68     * @param string $name     The category to use for our events.
69     * @param string $ident    The identity string.
70     * @param array  $conf     The configuration array.
71     * @param int    $level    Log messages up to and including this level.
72     * @access public
73     */
74    function Log_mcal($name, $ident = '', $conf = array(),
75                      $level = PEAR_LOG_DEBUG)
76    {
77        $this->_id = md5(microtime());
78        $this->_name = $name;
79        $this->_ident = $ident;
80        $this->_mask = Log::UPTO($level);
81        $this->_calendar = $conf['calendar'];
82        $this->_username = $conf['username'];
83        $this->_password = $conf['password'];
84        $this->_options = $conf['options'];
85    }
86
87    /**
88     * Opens a calendar stream, if it has not already been
89     * opened. This is implicitly called by log(), if necessary.
90     * @access public
91     */
92    function open()
93    {
94        if (!$this->_opened) {
95            $this->_stream = mcal_open($this->_calendar, $this->_username,
96                $this->_password, $this->_options);
97            $this->_opened = true;
98        }
99
100        return $this->_opened;
101    }
102
103    /**
104     * Closes the calendar stream, if it is open.
105     * @access public
106     */
107    function close()
108    {
109        if ($this->_opened) {
110            mcal_close($this->_stream);
111            $this->_opened = false;
112        }
113
114        return ($this->_opened === false);
115    }
116
117    /**
118     * Logs $message and associated information to the currently open
119     * calendar stream. Calls open() if necessary. Also passes the
120     * message along to any Log_observer instances that are observing
121     * this Log.
122     *
123     * @param mixed  $message  String or object containing the message to log.
124     * @param string $priority The priority of the message. Valid
125     *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
126     *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
127     *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
128     * @return boolean  True on success or false on failure.
129     * @access public
130     */
131    function log($message, $priority = null)
132    {
133        /* If a priority hasn't been specified, use the default value. */
134        if ($priority === null) {
135            $priority = $this->_priority;
136        }
137
138        /* Abort early if the priority is above the maximum logging level. */
139        if (!$this->_isMasked($priority)) {
140            return false;
141        }
142
143        /* If the connection isn't open and can't be opened, return failure. */
144        if (!$this->_opened && !$this->open()) {
145            return false;
146        }
147
148        /* Extract the string representation of the message. */
149        $message = $this->_extractMessage($message);
150
151        $date_str = date('Y:n:j:G:i:s');
152        $dates = explode(':', $date_str);
153
154        mcal_event_init($this->_stream);
155        mcal_event_set_title($this->_stream, $this->_ident);
156        mcal_event_set_category($this->_stream, $this->_name);
157        mcal_event_set_description($this->_stream, $message);
158        mcal_event_add_attribute($this->_stream, 'priority', $priority);
159        mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2],
160            $dates[3], $dates[4], $dates[5]);
161        mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2],
162            $dates[3], $dates[4], $dates[5]);
163        mcal_append_event($this->_stream);
164
165        $this->_announce(array('priority' => $priority, 'message' => $message));
166
167        return true;
168    }
169
170}
Note: See TracBrowser for help on using the repository browser.