Func_AbsencesAgent::getCollections()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 17
rs 9.4285
1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia is free software; you can redistribute it and/or modify    *
10
 * it under the terms of the GNU General Public License as published by *
11
 * the Free Software Foundation; either version 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  GNU General Public License for more details.				*
18
 *																		*
19
 * You should have received a copy of the GNU General Public License	*
20
 * along with this program; if not, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
26
27
require_once dirname(__FILE__).'/../functions.php';
28
require_once dirname(__FILE__).'/agent.class.php';
29
30
class Func_AbsencesAgent extends bab_functionality 
31
{
32
	public function getDescription()
33
	{
34
		return absences_translate('Agent API from the absences addon');
35
	}
36
	
37
	/**
38
	 * Get agent by id_user
39
	 * @throws Exception if agent does not exists
40
	 * @return absences_Agent
41
	 */
42
	public function getAgent($id_user)
43
	{
44
		$agent = absences_Agent::getFromIdUser($id_user);
45
		$agent->getRow();
46
		
47
		return $agent;
48
	}
49
	
50
	
51
	/**
52
	 * Set parameters for agent
53
	 * associate rights to agent according to collection
54
	 * if the agent does not exists, il will be created
55
	 * 
56
	 * @param	int		$id_user
57
	 * @param	int		$id_collection
58
	 * @param	int		$id_sa				Approval scheme
59
	 * @param	int		$id_sa_cet			Optionnal approval scheme for time saving account 
60
	 * @param	int		$id_sa_recover		Optionnal approval scheme for work period recovery
61
	 * 
62
	 * @throws Exception
63
	 * 
64
	 */
65
	public function setAgent($id_user, $id_collection, $id_sa, $id_sa_cet = 0, $id_sa_recover = 0)
66
	{
67
		require_once dirname(__FILE__).'/vacincl.php';
68
		
69
		absences_setAgentInfos($id_user,  $id_collection, $id_sa, $id_sa_cet, $id_sa_recover);
70
		absences_setCollectionRights($id_user, $id_collection);
71
	}
72
	
73
	
74
75
	
76
	
77
	
78
	/**
79
	 * Remove agent and requests associted with it
80
	 */
81
	public function deleteAgent($id_user)
82
	{
83
		$agent = absences_Agent::getFromIdUser($id_user);
84
		$agent->delete();
85
	}
86
	
87
	
88
	/**
89
	 * get the list of available collections as array
90
	 * @return array[absences_Collection]
0 ignored issues
show
Documentation introduced by
The doc-type array[absences_Collection] could not be parsed: Expected "]" at position 2, but found "absences_Collection". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
91
	 */
92
	public function getCollections()
93
	{
94
		global $babDB;
95
		$return = array();
96
		
97
		$res = $babDB->db_query("select * from absences_collections order by name asc");
98
		while ($arr = $babDB->db_fetch_assoc($res))
99
		{
100
			$id = (int) $arr['id'];
101
			$collection = new absences_Collection();
102
			$collection->setRow($arr);
103
			
104
			$return[$id] = $collection;
105
		}
106
		
107
		return $return;
108
	}
109
	
110
	/**
111
	 * Get the list of rights
112
	 * @return absences_Right[]
113
	 */
114
	public function getRightIterator()
115
	{
116
		require_once dirname(__FILE__).'/right.class.php';
117
		return new absences_RightIterator();
118
	}
119
	
120
}