opensupports/server/models/Department.php

74 lines
2.0 KiB
PHP
Raw Normal View History

<?php
use RedBeanPHP\Facade as RedBean;
2017-04-21 05:34:20 +02:00
/**
* @api {OBJECT} Department Department
2022-01-04 17:24:06 +01:00
* @apiVersion 4.11.0
2017-04-21 05:34:20 +02:00
* @apiGroup Data Structures
2017-05-11 21:37:03 +02:00
* @apiParam {Number} id Id of the department.
* @apiParam {String} name Name of the department.
* @apiParam {[Staff](#api-Data_Structures-ObjectStaff)[]} owners List of owners of the department.
2018-11-16 00:51:44 +01:00
* @apiParam {Boolean} private Indicates if the departmetn is not shown to users.
2017-04-21 05:34:20 +02:00
*/
class Department extends DataStore {
const TABLE = 'department';
2018-11-16 00:51:44 +01:00
public static function getProps() {
return [
'name',
'sharedTicketList',
2018-11-16 00:51:44 +01:00
'owners',
'private'
];
}
2018-11-16 00:51:44 +01:00
public function getDefaultProps() {
return [
2018-11-16 00:51:44 +01:00
'owners' => 0
];
}
2018-11-16 00:51:44 +01:00
public static function getAllDepartmentNames() {
$departmentsList = RedBean::findAll(Department::TABLE);
$departmentsNameList = [];
foreach($departmentsList as $department) {
2016-11-21 03:01:38 +01:00
$departmentsNameList[] = [
'id' => $department->id,
'name' => $department->name,
2018-11-16 00:51:44 +01:00
'owners' => $department->owners,
'private' => $department->private
2016-11-21 03:01:38 +01:00
];
}
2018-11-16 00:51:44 +01:00
return $departmentsNameList;
}
2018-11-16 00:51:44 +01:00
public static function getPublicDepartmentNames() {
$departmentsList = RedBean::findAll(Department::TABLE);
$departmentsNameList = [];
foreach($departmentsList as $department) {
if(!$department->private) {
$departmentsNameList[] = [
'id' => $department->id,
'name' => $department->name,
'owners' => $department->owners,
'private' => $department->private
];
}
}
return $departmentsNameList;
}
2016-12-08 07:21:37 +01:00
public function toArray() {
return [
'id' => $this->id,
'name' => $this->name,
'owners' => $this->owners
2016-12-08 07:21:37 +01:00
];
}
2018-11-16 00:51:44 +01:00
}