mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-20 05:29:29 +00:00
Merge branch 'ci' of https://github.com/FH-Complete/FHC-Core into ci
Conflicts: application/core/FHC_Controller.php
This commit is contained in:
@@ -16,5 +16,86 @@ class Message_model extends DB_Model
|
||||
$this->pk = 'message_id';
|
||||
}
|
||||
|
||||
public function getMessagesByUID($uid, $all)
|
||||
{
|
||||
// Check wrights
|
||||
// @ToDo: Define the special wright for reading own messages "basis/message:own"
|
||||
// if same user
|
||||
if ($uid === $this->getUID())
|
||||
{
|
||||
if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message', FHC_MODEL_ERROR);
|
||||
}
|
||||
// if different user, for reading messages from other users
|
||||
else
|
||||
{
|
||||
if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message:all', FHC_MODEL_ERROR);
|
||||
}
|
||||
|
||||
// get Data
|
||||
$sql = 'SELECT uid, person_id, message_id, subject, priority, relationmessage_id, oe_kurzbz, m.insertamum, anrede, titelpost, titelpre, nachname, vorname, vornamen,
|
||||
status, statusinfo, s.insertamum AS statusamum
|
||||
FROM public.tbl_msg_message m
|
||||
JOIN public.tbl_person USING (person_id)
|
||||
JOIN public.tbl_benutzer USING (person_id)
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum
|
||||
FROM public.tbl_msg_status
|
||||
INNER JOIN
|
||||
(
|
||||
SELECT message_id, person_id, max(insertamum) AS insertamum
|
||||
FROM public.tbl_msg_status
|
||||
GROUP BY message_id, person_id
|
||||
) status
|
||||
USING (message_id, person_id)
|
||||
WHERE tbl_msg_status.insertamum=status.insertamum
|
||||
) s
|
||||
USING (message_id, person_id)
|
||||
WHERE uid = ?';
|
||||
if (! $all)
|
||||
$sql .= ' AND status<2';
|
||||
$result = $this->db->query($sql, array($uid));
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
public function getMessagesByPerson($person_id, $all)
|
||||
{
|
||||
// Check wrights
|
||||
if (! $this->fhc_db_acl->isBerechtigt('basis/message', 's'))
|
||||
return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> system/message', FHC_MODEL_ERROR);
|
||||
|
||||
// get Data
|
||||
$sql = 'SELECT person_id, message_id, subject, priority, relationmessage_id, oe_kurzbz, m.insertamum, anrede, titelpost, titelpre, nachname, vorname, vornamen,
|
||||
status, statusinfo, s.insertamum AS statusamum
|
||||
FROM public.tbl_msg_message m
|
||||
JOIN public.tbl_person USING (person_id)
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT message_id, person_id, status, statusinfo, tbl_msg_status.insertamum
|
||||
FROM public.tbl_msg_status
|
||||
INNER JOIN
|
||||
(
|
||||
SELECT message_id, person_id, max(insertamum) AS insertamum
|
||||
FROM public.tbl_msg_status
|
||||
GROUP BY message_id, person_id
|
||||
) status
|
||||
USING (message_id, person_id)
|
||||
WHERE tbl_msg_status.insertamum=status.insertamum
|
||||
) s
|
||||
USING (message_id, person_id)
|
||||
WHERE person_id = ?';
|
||||
if (! $all)
|
||||
$sql .= ' AND status<2';
|
||||
$result = $this->db->query($sql, array($person_id));
|
||||
//var_dump($result);
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
}
|
||||
/* end of file Message_model.php */
|
||||
|
||||
Reference in New Issue
Block a user