~quam-plures-gatekeepers/quam-plures/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
 * This file implements the Cronjob class
 *
 * Manages a single cron job as registered in the DB.
 *
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 * @package cron
 */
if(!defined('QP_MAIN_INIT')) die('fail');

/**
 * Cronjob class
 *
 * @package cron
 */
class Cronjob extends DataObject
{
	/**
	 * Start date/time for the task
	 * @todo needs useful description
	 * @var string
	 */
	var $start_datetime;
	/**
	 * Frequency of the task (seconds?)
	 * @var integer
	 */
	var $repeat_after = NULL;
	/**
	 * Task name
	 * @var string
	 */
	var $name;
	/**
	 * Controller
	 * @var string
	 */
	var $controller;
	/**
	 * Params
	 * @var array
	 */
	var $params;

	/**
	 * Constructor
	 *
	 * @param table Database row
	 */
	function Cronjob( $db_row = NULL )
	{
		// Call parent constructor
		parent::DataObject( 'T_cron_task', 'ctsk_', 'ctsk_ID', '', '', '', '' );

		if( $db_row != NULL )
		{
			// Loading an object from DB
			$this->ID = $db_row->ctsk_ID;
			$this->start_datetime = $db_row->ctsk_start_datetime;
			$this->repeat_after = $db_row->ctsk_repeat_after;
			$this->name = $db_row->ctsk_name;
			$this->controller = $db_row->ctsk_controller;
			$this->params = $db_row->ctsk_params;
		}
		else
		{
			// New object
		}
	}


	/**
	 * Set param value
	 *
	 * By default, all values will be considered strings
	 *
	 * @param string parameter name
	 * @param mixed parameter value
	 * @param boolean true to set to NULL if empty value
	 * @return boolean true, if a value has been set; false if it has not changed
	 */
	function set( $parname, $parvalue, $make_null = false )
	{
		switch( $parname )
		{
			case 'params':
			return $this->set_param( 'params', 'string', serialize( $parvalue ), false );

			case 'name':
			return $this->set_param( $parname, 'string', substr( $parvalue, 0, 50 ), false );
		}

		return $this->set_param( $parname, 'string', $parvalue, $make_null );
	}


	/**
	 * Get a member param by its name
	 *
	 * @param mixed Name of parameter
	 * @return mixed Value of parameter
	 */
	function get( $parname )
	{
		switch( $parname )
		{
			case 'params':
			return unserialize( $this->params );
		}

		return parent::get( $parname );
	}

}

?>