summaryrefslogtreecommitdiff
path: root/includes/model/Shifts_model.php
blob: 224bfc0b70ba2f5c06750462146c9ad690528265 (plain)
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
<?php

/**
 * Returns Shift id array
 */
function mShiftList() {
	global $_REQUEST;
	$filter = "";
	
	// filterRoom (Array of integer) - Array of Room IDs (optional, for list request)
	if (isset($_REQUEST['filterRoom']) && is_array($_REQUEST['filterRoom']) ) {
		foreach ( $_REQUEST['filterRoom'] as $key => $value ) {
			$filter .= ", `RID`=" . sql_escape($value) . " ";
		}
	}
	
	//filterTask (Array of integer) - Array if Task (optional, for list request)
	if (isset($_REQUEST['filterTask']) && is_array($_REQUEST['filterTask']) ) {
		foreach ( $_REQUEST['filterTask'] as $key => $value ) {
// TODO			$filter .= ", `RID`=" . sql_escape($value) . " ";
		}
	}
	
	// filterOccupancy (integer) - Occupancy state: (optional, for list request)
	//   1 occupied, 	2 free, 3 occupied and free
	if (isset($_REQUEST['filterOccupancy']) && is_array($_REQUEST['filterOccupancy']) ) {
		foreach ( $_REQUEST['filterOccupancy'] as $key => $value ) {
// TODO			$filter .= ", `RID`=" . sql_escape($value) . " ";
		}
	}

	// format filter
	if( $filter != "" ) {
		$filter = ' WHERE '. substr($filter, 1); 
	}

	// real request
	$shifts_source = sql_select("SELECT `SID` FROM `Shifts`". $filter);
	if ($shifts_source === false)
		return false;
	if (count($shifts_source) > 0) {
		return $shifts_source;
	}
return null;
}

/**
 * Returns Shift by id.
 *
 * @param $id Shift ID
 */
function mShift($id) {
	$shifts_source = sql_select("SELECT * FROM `Shifts` WHERE `SID`=" . sql_escape($id) . " LIMIT 1");
	if ($shifts_source === false)
		return false;
	if (count($shifts_source) > 0)
		return $shifts_source[0];
	return null;
}

/**
 * Returns all shifts with needed angeltypes and count of subscribed jobs.
 */
function Shifts() {
  $shifts_source = sql_select("
    SELECT `Shifts`.*, `Room`.`RID`, `Room`.`Name` as `room_name` 
    FROM `Shifts`
    JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
    ");
  if ($shifts_source === false)
    return false;
  
  foreach ($shifts_source as &$shift) {
    $needed_angeltypes = NeededAngelTypes_by_shift($shift);
    if ($needed_angeltypes === false)
      return false;

    $shift['angeltypes'] = $needed_angeltypes;
  }
  
  return $shifts_source;
}

?>