- If the sender of a message is an admin: show all the vorlage with
mimetype = text/html
 - If the sender of a message is NOT an admin: show all the
vorlage that belongs to the organisation units of the user
and the parents of those organisation units until the root
of the organisation unit tree

Changes:
 - Added method isAdminByPersonId to model Benutzerrolle_model
 - Added method _getAllHTMLVorlage to Vorlage_widget
 - Added method _getUserVorlage to Vorlage_widget
This commit is contained in:
Paolo
2017-06-06 15:21:22 +02:00
parent 02320f9388
commit 45b4c84764
5 changed files with 160 additions and 30 deletions
+21 -10
View File
@@ -40,14 +40,13 @@ class Messages extends VileSci_Controller
}
// Get variables
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
$prestudent = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
if ($prestudent->error)
$this->load->model('system/Message_model', 'MessageModel');
$msgVarsDataByPrestudentId = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
if ($msgVarsDataByPrestudentId->error)
{
show_error($prestudent->retval);
show_error($msgVarsDataByPrestudentId->retval);
}
$this->load->model('system/Message_model', 'MessageModel');
if (!hasData($variables = $this->MessageModel->getMessageVars()))
{
unset($variables);
@@ -65,21 +64,33 @@ class Messages extends VileSci_Controller
array_shift($variables->retval); // Remove person_id
array_shift($variables->retval); // Remove prestudent_id
//
$oe_kurzbz = null;
// Organisation units
$oe_kurzbz = array(); // A person can have more organisation units
$this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
$benutzerResult = $this->BenutzerfunktionModel->getByPersonId($sender_id);
if (hasData($benutzerResult))
{
$oe_kurzbz = $benutzerResult->retval[0]->oe_kurzbz;
foreach($benutzerResult->retval as $val)
{
$oe_kurzbz[] = $val->oe_kurzbz;
}
}
// Admin or commoner?
$this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel');
$isAdmin = $this->BenutzerrolleModel->isAdminByPersonId($sender_id);
if (isError($isAdmin))
{
show_error($isAdmin->retval);
}
$data = array (
'sender_id' => $sender_id,
'receivers' => $prestudent->retval,
'receivers' => $msgVarsDataByPrestudentId->retval,
'message' => $msg,
'variables' => $variablesArray,
'oe_kurzbz' => $oe_kurzbz
'oe_kurzbz' => $oe_kurzbz,
'isAdmin' => $isAdmin->retval
);
$v = $this->load->view('system/messageWrite', $data);
@@ -13,7 +13,7 @@ class Benutzerfunktion_model extends DB_Model
}
/**
*
* Get the Benutzerfunktion using the person_id
*/
public function getByPersonId($person_id)
{
@@ -1,7 +1,7 @@
<?php
class Benutzerrolle_model extends DB_Model
{
/**
* Constructor
*/
@@ -11,4 +11,29 @@ class Benutzerrolle_model extends DB_Model
$this->dbTable = 'system.tbl_benutzerrolle';
$this->pk = 'benutzerberechtigung_id';
}
}
/**
* Checks if the given user is an admin
*/
public function isAdminByPersonId($person_id)
{
// Join with the table tbl_benutzer
$this->addJoin('public.tbl_benutzer', 'uid');
$result = $this->loadWhere(array('person_id' => $person_id, 'rolle_kurzbz' => 'admin'));
if (!isError($result))
{
if (hasData($result))
{
$result = success(true);
}
else if (!hasData($result))
{
$result = success(false);
}
}
return $result;
}
}
+1 -1
View File
@@ -93,7 +93,7 @@
<?php
echo $this->widgetlib->widget(
'Vorlage_widget',
array('oe_kurzbz' => $oe_kurzbz),
array('oe_kurzbz' => $oe_kurzbz, 'isAdmin' => $isAdmin),
array('name' => 'vorlage', 'id' => 'vorlageDnD')
);
?>
+110 -16
View File
@@ -4,23 +4,25 @@ class Vorlage_widget extends DropdownWidget
{
public function display($widgetData)
{
// Loads
$this->load->library('OrganisationseinheitLib');
// All organization units to which the user belongs
$oe_kurzbz = $widgetData['oe_kurzbz'];
$idAdmin = $widgetData['isAdmin'];
$vorlage = $this->organisationseinheitlib->treeSearchEntire(
'(
SELECT v.vorlage_kurzbz, v.bezeichnung, vs.version, vs.oe_kurzbz, vs.aktiv, vs.subject, vs.text, v.mimetype
FROM tbl_vorlagestudiengang vs INNER JOIN tbl_vorlage v USING(vorlage_kurzbz)
) templates',
'templates',
array("templates.vorlage_kurzbz AS id", "UPPER(templates.oe_kurzbz) || ' - ' || templates.bezeichnung || ' - V' || templates.version AS description"),
'templates.aktiv = TRUE
AND templates.subject IS NOT NULL
AND templates.text IS NOT NULL
AND templates.mimetype = \'text/html\'',
"description ASC",
$widgetData['oe_kurzbz']
);
$vorlage = null;
// If the user is an admin
if ($idAdmin === true)
{
// Get all the vorlage with mimetype = text/html
$vorlage = $this->_getAllHTMLVorlage();
}
else
{
// Get all the vorlage that belongs to the organisation units of the user
// and the parents of those organisation units until the root of the
// organisation unit tree
$vorlage = $this->_getUserVorlage($oe_kurzbz);
}
$this->setElementsArray(
$vorlage,
@@ -31,4 +33,96 @@ class Vorlage_widget extends DropdownWidget
$this->loadDropDownView($widgetData);
}
/**
* Get all the vorlage with mimetype = text/html
*/
private function _getAllHTMLVorlage()
{
$this->load->model('system/Vorlage_model', 'VorlageModel');
$this->VorlageModel->addOrder('vorlage_kurzbz');
$this->addSelectToModel($this->VorlageModel, 'vorlage_kurzbz', 'bezeichnung');
return $this->VorlageModel->loadWhere(array('mimetype' => 'text/html'));
}
/**
* Get all the vorlage that belongs to the organisation units of the user
* and the parents of those organisation units until the root of the
* organisation unit tree
*/
private function _getUserVorlage($oe_kurzbz)
{
// Loads library OrganisationseinheitLib
$this->load->library('OrganisationseinheitLib');
$vorlage = success(array()); // Default value
$table = '(
SELECT v.vorlage_kurzbz, v.bezeichnung, vs.version, vs.oe_kurzbz, vs.aktiv, vs.subject, vs.text, v.mimetype
FROM tbl_vorlagestudiengang vs INNER JOIN tbl_vorlage v USING(vorlage_kurzbz)
) templates';
$alias = 'templates';
$fields = array("templates.vorlage_kurzbz AS id", "UPPER(templates.oe_kurzbz) || ' - ' || templates.bezeichnung || ' - V' || templates.version AS description");
$where = 'templates.aktiv = TRUE
AND templates.subject IS NOT NULL
AND templates.text IS NOT NULL
AND templates.mimetype = \'text/html\'';
$order_by = 'description ASC';
if (!is_array($oe_kurzbz))
{
$vorlage = $this->organisationseinheitlib->treeSearchEntire(
$table,
$alias,
$fields,
$where,
$order_by,
$oe_kurzbz
);
}
else // is an array
{
// Get the vorlage for each organisation unit
foreach($oe_kurzbz as $val)
{
$tmpVorlage = $this->organisationseinheitlib->treeSearchEntire(
$table,
$alias,
$fields,
$where,
$order_by,
$val
);
// Everything is ok and data are inside
if (hasData($tmpVorlage))
{
// If it's the first vorlage copy it
if (count($vorlage->retval) == 0)
{
$vorlage->retval = $tmpVorlage->retval;
}
else // checks for duplicates, if it's not already present push it into the array $vorlage->retval
{
for ($i = 0; $i < count($vorlage->retval); $i++)
{
for ($j = 0; $j < count($tmpVorlage->retval); $j++)
{
if ($vorlage->retval[$i]->_pk != $tmpVorlage->retval[$j]->_pk
&& $vorlage->retval[$i]->_ppk != $tmpVorlage->retval[$j]->_ppk
&& $vorlage->retval[$i]->_jtpk != $tmpVorlage->retval[$j]->_jtpk)
{
array_push($vorlage->retval, $tmpVorlage->retval[$j]);
}
}
}
}
}
}
}
return $vorlage;
}
}