Files
FHC-Core/application/models/organisation/Studiensemester_model.php
T
bison-paolo 8e0ca12deb - All permission functionalities now are in the library PermissionLib
- All return messages functions are in the message helper and it is loaded by the core classes
- Added the missing constant FHC_NOPK
- Updated all the interested classes with the new permission method
- Updated all the interested classes with the new return message functions
2016-10-13 17:53:12 +02:00

103 lines
2.4 KiB
PHP

<?php
class Studiensemester_model extends DB_Model
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->dbTable = 'public.tbl_studiensemester';
$this->pk = 'studiensemester_kurzbz';
}
public function getLastOrAktSemester($days = 60)
{
// Checks if the operation is permitted by the API caller
if (($chkRights = $this->isEntitled('public.tbl_studiensemester', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
if (!is_numeric($days))
{
$days = 60;
}
$query = 'SELECT studiensemester_kurzbz
FROM public.tbl_studiensemester
WHERE start < NOW() - \'' . $days . ' DAYS\'::INTERVAL
ORDER BY start DESC
LIMIT 1';
$result = $this->db->query($query);
if (is_object($result))
return success($result->result());
else
return error($this->db->error(), FHC_DB_ERROR);
}
public function getNextFrom($studiensemester_kurzbz)
{
// Checks if the operation is permitted by the API caller
if (($chkRights = $this->isEntitled('public.tbl_studiensemester', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
$query = 'SELECT studiensemester_kurzbz,
start,
ende
FROM public.tbl_studiensemester
WHERE start > (
SELECT ende
FROM public.tbl_studiensemester
WHERE studiensemester_kurzbz = ?
)
ORDER BY start
LIMIT 1';
$result = $this->db->query($query, array($studiensemester_kurzbz));
if (is_object($result))
return success($result->result());
else
return error($this->db->error(), FHC_DB_ERROR);
}
/**
* @return void
*/
public function getNearest($semester = '')
{
// Checks if the operation is permitted by the API caller
if (($chkRights = $this->isEntitled('public.vw_studiensemester', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
$query = 'SELECT studiensemester_kurzbz,
start,
ende
FROM public.vw_studiensemester';
if (is_numeric($semester))
{
if ($semester % 2 == 0)
{
$ss = 'SS';
}
else
{
$ss = 'WS';
}
$query .= ' WHERE SUBSTRING(studiensemester_kurzbz FROM 1 FOR 2) = '' . $ss . ''';
}
$query .= ' ORDER BY delta LIMIT 1';
$result = $this->db->query($query);
if (is_object($result))
return success($result->result());
else
return error($this->db->error(), FHC_DB_ERROR);
}
}