forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdmin.php
61 lines (51 loc) · 1.36 KB
/
Admin.php
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
<?php
namespace Intern;
use \Intern\UI\NotifyUI;
/**
* Admin
*
* Encapsulates the manaing of granular access by department.
*
* @author Robert Bost <bostrt at tux dot appstate dot edu>
*/
class Admin extends Model
{
public $username;
public $department_id;
// For DBPager join
public $department_name; // Department name, when joined to intern_department table
/**
* @Override Model::getDb
*/
public static function getDb()
{
return new \PHPWS_DB('intern_admin');
}
/**
* @Override Model::getCSV
*/
public function getCSV(){}
public static function currentAllowed($dept)
{
\PHPWS_Core::initModClass('users', 'Current_User.php');
return self::allowed(\Current_User::getUsername(), $dept);
}
public static function allowed($username, $dept)
{
if($dept instanceof Department){
// User passed Department Obj.
$dept = $dept->id;
}
$db = new PHPWS_DB('intern_admin');
$db->addWhere('username', $username);
$db->addWhere('department_id', $dept);
$db->addColumn('id', $count=true);
$count = $db->select();
// If 1+ row exists in table then they're allowed.
if(sizeof($count) >= 1){
return true;
}else{
return false;
}
}
}