diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php
index 61128d7ed..ed45712ef 100644
--- a/application/libraries/WidgetLib.php
+++ b/application/libraries/WidgetLib.php
@@ -179,6 +179,7 @@ class WidgetLib
* Can be usefull to use straight from the template file
* @param string $name
* @param array $data
+ * @param array $htmlArgs
* @return Widget
*/
public function widget($name, $data = array(), $htmlArgs = array())
@@ -334,8 +335,6 @@ class WidgetLib
class Partial
{
- const HTML_DEFAULT_VALUE = ''; // Default value of the html element
-
protected $_ci, $_content, $_name, $_cache_ttl = 0, $_cached = false, $_identifier, $_trigger;
protected $_args = array();
@@ -343,17 +342,11 @@ class Partial
* Construct with optional parameters
* @param array $args
*/
- public function __construct($name, $args = array(), $htmlArgs = array())
+ public function __construct($name, $args = array())
{
$this->_ci = &get_instance();
$this->_args = $args;
$this->_name = $name;
-
- // Initialising properties
- $this->_setHtmlProperties($htmlArgs);
-
- // Loads helper message to manage returning messages
- $this->load->helper('message');
}
/**
@@ -607,42 +600,38 @@ class Partial
$this->_trigger = FALSE;
}
}
-
- /**
- * Initialising properties
- */
- private function _setHtmlProperties($htmlArgs)
- {
- if (isset($htmlArgs) && is_array($htmlArgs))
- {
- $this->_args['html'] = array();
-
- if (!isset($htmlArgs['id']) || (isset($htmlArgs['id']) && $htmlArgs['id'] == ''))
- {
- $this->_args['html']['id'] = '';
- }
- else
- {
- $this->_args['html']['id'] = $htmlArgs['id'];
- }
-
- if (!isset($htmlArgs['name']) || (isset($htmlArgs['name']) && $htmlArgs['name'] == ''))
- {
- $this->_args['html']['name'] = '';
- }
- else
- {
- $this->_args['html']['name'] = $htmlArgs['name'];
- }
- }
- }
}
+/**
+ * The mother of all widgets
+ * it represent a generic HTML element
+ */
class Widget extends Partial
{
- /* (non-PHPdoc)
- * @see Partial::content()
- */
+ // The name of the array present in the data array given to the view that will render this widget
+ const HTML_ARG_NAME = 'HTML';
+ const HTML_DEFAULT_VALUE = ''; // Default value of the html element
+ const HTML_NAME = 'name'; // HTML name attribute
+ const HTML_ID = 'id'; // HTML id attribute
+
+ /**
+ * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
+ */
+ public function __construct($name, $args, $htmlArgs = array())
+ {
+ parent::__construct($name, $args);
+
+ // Initialising HTML properties
+ $this->_setHtmlProperties($htmlArgs);
+
+ // Loads helper message to manage returning messages
+ $this->load->helper('message');
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Partial::content()
+ */
public function content()
{
if (!$this->_cached)
@@ -665,4 +654,139 @@ class Widget extends Partial
return parent::content();
}
+
+ /**
+ * Initialising html properties, such as the id and name attributes of the HTML element
+ */
+ private function _setHtmlProperties($htmlArgs)
+ {
+ if (isset($htmlArgs) && is_array($htmlArgs))
+ {
+ $this->_args[Widget::HTML_ARG_NAME] = array();
+
+ // Avoids that the elements of a same HTML page have the same name or id
+ $randomIdentifier = uniqid(rand(0, 1000));
+
+ if (isset($htmlArgs[Widget::HTML_ID]) && trim($htmlArgs[Widget::HTML_ID]) != '')
+ {
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $htmlArgs[Widget::HTML_ID];
+ }
+ else
+ {
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $randomIdentifier;
+ }
+
+ if (isset($htmlArgs[Widget::HTML_NAME]) && trim($htmlArgs[Widget::HTML_NAME]) != '')
+ {
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $htmlArgs[Widget::HTML_NAME];
+ }
+ else
+ {
+ $this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $randomIdentifier;
+ }
+ }
+ }
+}
+
+/**
+ * It exends the Widget class to represent an HTML dropdown
+ */
+class DropdownWidget extends Widget
+{
+ // The name of the element of the data array given to the view
+ // this element is an array of elements to be place inside the dropdown
+ const WIDGET_DATA_ELEMENTS_ARRAY_NAME = 'ELEMENTS_ARRAY';
+ // Name of the property that will be used to store the value attribute of the option tag
+ const ID_FIELD = 'id';
+ // Name of the property that will be used to store the value between the option tags
+ const DESCRIPTION_FIELD = 'description'; //
+ // The name of the element of the data array given to the view
+ // this element is used to tell what element of the dropdown is selected
+ const SELECTED_ELEMENT = 'selectedElement'; //
+
+ private $elementsArray; // Array of elements to be place inside the dropdown
+
+ /**
+ * Loads the dropdown view with all the elements to be displayed
+ */
+ protected function loadDropDownView($widgetData)
+ {
+ $widgetData[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $this->elementsArray->retval;
+
+ $this->view('widgets/dropdown', $widgetData);
+ }
+
+ /**
+ * Add the correct select to the model used to load a list of elemets for this dropdown
+ * @param model $model the model used to load elements
+ * @param string $idName the name of the field that will used to be the value of the option tag
+ * @param string $descriptionName the name of the field that will used to be displayed in the dropdown
+ */
+ protected function addSelectToModel($model, $idName, $descriptionName)
+ {
+ $model->addSelect(
+ sprintf(
+ '%s AS %s, %s AS %s',
+ $idName,
+ DropdownWidget::ID_FIELD,
+ $descriptionName,
+ DropdownWidget::DESCRIPTION_FIELD
+ )
+ );
+ }
+
+ /**
+ * Set the array used to populate the dropdown
+ * @param array $elements list used to populate this dropdown
+ * @param boolean $emptyElement if an empty element must be added at the beginning of the dropdown
+ * @param string $stdDescription description of the empty element
+ * @param string $noDataDescription description if no data are found
+ * @param string $id value of the attribute value of the empty element
+ */
+ protected function setElementsArray(
+ $elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = '' , $id = Widget::HTML_DEFAULT_VALUE
+ )
+ {
+ if (isError($elements))
+ {
+ if (is_object($elements) && isset($elements->retval))
+ {
+ show_error($elements->retval);
+ }
+ else if (is_string($elements))
+ {
+ show_error($elements);
+ }
+ else
+ {
+ show_error('Generic error occurred');
+ }
+ }
+ else
+ {
+ $this->elementsArray = $elements;
+
+ if ($emptyElement === true)
+ {
+ $this->addElementAtBeginning($stdDescription, $noDataDescription, $id);
+ }
+ }
+ }
+
+ /**
+ * Adds an element to the beginning of the array
+ */
+ protected function addElementAtBeginning($stdDescription, $noDataDescription, $id)
+ {
+ $element = new stdClass();
+ $element->id = $id;
+ $element->description = $stdDescription;
+
+ if (!hasData($this->elementsArray))
+ {
+ $element->description = $noDataDescription;
+ }
+
+ array_unshift($this->elementsArray->retval, $element);
+ }
}
\ No newline at end of file
diff --git a/application/views/system/aufnahme/prestudentMultiAssign.php b/application/views/system/aufnahme/prestudentMultiAssign.php
index 769e6f834..f90ea208c 100644
--- a/application/views/system/aufnahme/prestudentMultiAssign.php
+++ b/application/views/system/aufnahme/prestudentMultiAssign.php
@@ -8,7 +8,7 @@
widgetlib->widget(
'Studiengang_widget',
- array('studiengang' => $studiengang),
+ array(DropdownWidget::SELECTED_ELEMENT => $studiengang),
array('name' => 'studiengang', 'id' => 'studiengangFilter')
);
?>
@@ -17,7 +17,7 @@
widgetlib->widget(
'Studiensemester_widget',
- array('studiensemester' => $studiensemester),
+ array(DropdownWidget::SELECTED_ELEMENT => $studiensemester),
array('name' => 'studiensemester', 'id' => 'studiensemesterFilter')
);
?>
@@ -26,7 +26,11 @@
widgetlib->widget(
'Reihungstest_widget',
- array('reihungstest' => $reihungstest, 'studiengang' => $studiengang, 'studiensemester' => $studiensemester),
+ array(
+ DropdownWidget::SELECTED_ELEMENT => $reihungstest,
+ 'studiengang' => $studiengang,
+ 'studiensemester' => $studiensemester
+ ),
array('name' => 'reihungstest', 'id' => 'reihungstestFilter')
);
?>
@@ -35,7 +39,7 @@
widgetlib->widget(
'Aufnahmegruppe_widget',
- array('aufnahmegruppe' => $aufnahmegruppe),
+ array(DropdownWidget::SELECTED_ELEMENT => $aufnahmegruppe),
array('name' => 'aufnahmegruppe', 'id' => 'aufnahmegruppeFilter')
);
?>
@@ -44,7 +48,7 @@
widgetlib->widget(
'Stufe_widget',
- array('stufe' => $stufe),
+ array(DropdownWidget::SELECTED_ELEMENT => $stufe),
array('name' => 'stufe', 'id' => 'stufeFilter')
);
?>
@@ -134,66 +138,52 @@
for ($i = 0; $i < count($users); $i++)
{
$user = $users[$i];
-
- echo "
";
-
- echo "
";
- echo '';
- echo "
";
-
- echo "
";
- echo $user->prestudent_id;
- echo "
";
-
- echo "
";
- echo $user->person_id;
- echo "
";
-
- echo "
";
- echo $user->vorname;
- echo "
";
-
- echo "
";
- echo $user->nachname;
- echo "
";
-
- echo "
";
- echo $user->geschlecht;
- echo "
";
-
- echo "
";
- echo $user->kurzbzlang;
- echo "
";
-
- echo "
";
- echo $user->orgform_kurzbz;
- echo "
";
-
- echo "
";
- echo $user->studienplan;
- echo "
";
-
- echo "
";
- echo $user->gebdatum;
- echo "
";
-
- echo "
";
- echo $user->email;
- echo "
";
-
- echo "
";
- echo $user->rt_stufe;
- echo "
";
-
- echo "
";
- echo $user->aufnahmegruppe_kurzbz;
- echo "
";
-
- echo "
";
- echo $user->punkte;
- echo "
";
-
- echo "
";
+ ?>
+
+
+
+
+
+ prestudent_id; ?>
+
+
+ person_id; ?>
+
+
+ vorname; ?>
+
+
+ nachname; ?>
+
+
+ geschlecht; ?>
+
+
+ kurzbzlang; ?>
+
+
+ orgform_kurzbz; ?>
+
+
+ studienplan; ?>
+
+
+ gebdatum; ?>
+
+
+ email; ?>
+
+
+ rt_stufe; ?>
+
+
+ aufnahmegruppe_kurzbz; ?>
+
+
+ punkte; ?>
+
+
+
diff --git a/application/views/widgets/aufnahmegruppe.php b/application/views/widgets/aufnahmegruppe.php
deleted file mode 100644
index ade8c6ce2..000000000
--- a/application/views/widgets/aufnahmegruppe.php
+++ /dev/null
@@ -1,14 +0,0 @@
-
\ No newline at end of file
diff --git a/application/views/widgets/dropdown.php b/application/views/widgets/dropdown.php
new file mode 100644
index 000000000..d511ece11
--- /dev/null
+++ b/application/views/widgets/dropdown.php
@@ -0,0 +1,14 @@
+
\ No newline at end of file
diff --git a/application/views/widgets/reihungstest.php b/application/views/widgets/reihungstest.php
deleted file mode 100644
index e6bb66570..000000000
--- a/application/views/widgets/reihungstest.php
+++ /dev/null
@@ -1,14 +0,0 @@
-
\ No newline at end of file
diff --git a/application/views/widgets/studiengang.php b/application/views/widgets/studiengang.php
deleted file mode 100644
index d9286e19a..000000000
--- a/application/views/widgets/studiengang.php
+++ /dev/null
@@ -1,23 +0,0 @@
-
\ No newline at end of file
diff --git a/application/views/widgets/studiensemester.php b/application/views/widgets/studiensemester.php
deleted file mode 100644
index 2e5945b62..000000000
--- a/application/views/widgets/studiensemester.php
+++ /dev/null
@@ -1,14 +0,0 @@
-
\ No newline at end of file
diff --git a/application/views/widgets/stufe.php b/application/views/widgets/stufe.php
deleted file mode 100644
index cf77770e5..000000000
--- a/application/views/widgets/stufe.php
+++ /dev/null
@@ -1,14 +0,0 @@
-
\ No newline at end of file
diff --git a/application/widgets/Aufnahmegruppe_widget.php b/application/widgets/Aufnahmegruppe_widget.php
index 964719954..5d0d09125 100644
--- a/application/widgets/Aufnahmegruppe_widget.php
+++ b/application/widgets/Aufnahmegruppe_widget.php
@@ -1,44 +1,22 @@
load->model('organisation/Gruppe_model', 'GruppeModel');
$this->GruppeModel->addOrder('beschreibung');
- $gruppen = $this->GruppeModel->loadWhere(array('aktiv' => true, 'aufnahmegruppe' => true));
- if (hasData($gruppen))
- {
- // Adding an empty element at the beginning
- $emptyElement = new stdClass();
- $emptyElement->gruppe_kurzbz = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'Select a group...';
- array_unshift($gruppen->retval, $emptyElement);
- }
- else if (isError($gruppen))
- {
- show_error($gruppen);
- }
- else
- {
- // Adding an element to the array
- $emptyElement = new stdClass();
- $emptyElement->gruppe_kurzbz = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'No aufnahmegruppe found';
- array_unshift($gruppen->retval, $emptyElement);
- }
- // Data to be used in the widget view
- $widgetData['aufnahmegruppen'] = $gruppen->retval;
+ $this->addSelectToModel($this->GruppeModel, 'gruppe_kurzbz', 'beschreibung');
- // Loads widget view
- $this->view('widgets/aufnahmegruppe', $widgetData);
+ $this->setElementsArray(
+ $this->GruppeModel->loadWhere(array('aktiv' => true, 'aufnahmegruppe' => true)),
+ true,
+ 'Select a group...',
+ 'No aufnahmegruppe found'
+ );
+
+ $this->loadDropDownView($widgetData);
}
}
\ No newline at end of file
diff --git a/application/widgets/Reihungstest_widget.php b/application/widgets/Reihungstest_widget.php
index fef74fce3..023b501d3 100644
--- a/application/widgets/Reihungstest_widget.php
+++ b/application/widgets/Reihungstest_widget.php
@@ -1,27 +1,20 @@
load->model('crm/Reihungstest_model', 'ReihungstestModel');
+ $this->ReihungstestModel->addOrder('datum', 'DESC');
+
+ $this->addSelectToModel($this->ReihungstestModel, 'reihungstest_id', 'CONCAT(datum, \' \', uhrzeit, \' \', anmerkung)');
+
+ $parametersArray = array();
// If the parameters studiengang or studiensemester are given and are not empty
if (isset($widgetData) && is_array($widgetData)
&& ((isset($widgetData['studiengang']) && !empty($widgetData['studiengang']))
|| (isset($widgetData['studiensemester']) && !empty($widgetData['studiensemester']))))
{
- $this->load->model('crm/Reihungstest_model', 'ReihungstestModel');
- $this->ReihungstestModel->addSelect('reihungstest_id, concat(datum, \' \', uhrzeit, \' \', anmerkung) AS beschreibung');
- $this->ReihungstestModel->addOrder('datum', 'DESC');
-
- $parametersArray = array();
if ($widgetData['studiengang'] != null)
{
$parametersArray['studiengang_kz'] = $widgetData['studiengang'];
@@ -30,38 +23,21 @@ class Reihungstest_widget extends Widget
{
$parametersArray['studiensemester_kurzbz'] = $widgetData['studiensemester'];
}
-
- $reihungstest = $this->ReihungstestModel->loadWhere($parametersArray);
- if (isError($reihungstest))
- {
- show_error($reihungstest);
- }
}
-
- if (!isError($reihungstest))
+ else
{
- if (hasData($reihungstest))
- {
- // Adding an empty element at the beginning
- $emptyElement = new stdClass();
- $emptyElement->reihungstest_id = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'Select a reihungstest...';
- array_unshift($reihungstest->retval, $emptyElement);
- }
- else
- {
- // Adding an element to the array
- $emptyElement = new stdClass();
- $emptyElement->reihungstest_id = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'No reihungstest found';
- array_unshift($reihungstest->retval, $emptyElement);
- }
+ // To NOT select anything
+ // Set 0 = 1 in the where clause of the query
+ $parametersArray['0'] = '1';
}
- // Data to be used in the widget view
- $widgetData['reihungstests'] = $reihungstest->retval;
+ $this->setElementsArray(
+ $this->ReihungstestModel->loadWhere($parametersArray),
+ true,
+ 'Select a reihungstest...',
+ 'No reihungstest found'
+ );
- // Loads widget view
- $this->view('widgets/reihungstest', $widgetData);
+ $this->loadDropDownView($widgetData);
}
}
\ No newline at end of file
diff --git a/application/widgets/Studiengang_widget.php b/application/widgets/Studiengang_widget.php
index f3c3025ca..e87fa9cd1 100644
--- a/application/widgets/Studiengang_widget.php
+++ b/application/widgets/Studiengang_widget.php
@@ -1,46 +1,22 @@
load->model('organisation/Studiengang_model', 'StudiengangModel');
$this->StudiengangModel->addOrder('kurzbzlang');
- $studiengaenge = $this->StudiengangModel->loadWhere(array('aktiv' => true));
- if (hasData($studiengaenge))
- {
- // Adding an empty element at the beginning
- $emptyElement = new stdClass();
- $emptyElement->studiengang_kz = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->kurzbzlang = 'Select a studiengang...';
- $emptyElement->bezeichnung = '';
- array_unshift($studiengaenge->retval, $emptyElement);
- }
- else if (isError($studiengaenge))
- {
- show_error($studiengaenge);
- }
- else
- {
- // Adding an element to the array
- $emptyElement = new stdClass();
- $emptyElement->studiengang_kz = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->kurzbzlang = 'No studiengaenge found';
- $emptyElement->bezeichnung = '';
- array_unshift($studiengaenge->retval, $emptyElement);
- }
- // Data to be used in the widget view
- $widgetData['studiengaenge'] = $studiengaenge->retval;
+ $this->addSelectToModel($this->StudiengangModel, 'studiengang_kz', '\'(\' || kurzbzlang || \') \' || bezeichnung');
- // Loads widget view
- $this->view('widgets/studiengang', $widgetData);
+ $this->setElementsArray(
+ $this->StudiengangModel->loadWhere(array('aktiv' => true)),
+ true,
+ 'Select a studiengang...',
+ 'No studiengaenge found'
+ );
+
+ $this->loadDropDownView($widgetData);
}
}
\ No newline at end of file
diff --git a/application/widgets/Studiensemester_widget.php b/application/widgets/Studiensemester_widget.php
index e9d507cdf..bc1c0a201 100644
--- a/application/widgets/Studiensemester_widget.php
+++ b/application/widgets/Studiensemester_widget.php
@@ -1,45 +1,22 @@
load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
- $this->StudiengangModel->addSelect('studiensemester_kurzbz, studiensemester_kurzbz AS beschreibung');
- $this->StudiengangModel->addOrder('studiensemester_kurzbz', 'DESC');
- $studiensemester = $this->StudiensemesterModel->load();
- if (hasData($studiensemester))
- {
- // Adding an empty element at the beginning
- $emptyElement = new stdClass();
- $emptyElement->studiensemester_kurzbz = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'Select a studiensemester...';
- array_unshift($studiensemester->retval, $emptyElement);
- }
- else if (isError($studiensemester))
- {
- show_error($studiensemester);
- }
- else
- {
- // Adding an element to the array
- $emptyElement = new stdClass();
- $emptyElement->studiensemester_kurzbz = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'No studiensemester found';
- array_unshift($studiensemester->retval, $emptyElement);
- }
+ $this->StudiensemesterModel->addOrder('studiensemester_kurzbz', 'DESC');
- // Data to be used in the widget view
- $widgetData['studiensemesters'] = $studiensemester->retval;
+ $this->addSelectToModel($this->StudiensemesterModel, 'studiensemester_kurzbz', 'studiensemester_kurzbz');
- // Loads widget view
- $this->view('widgets/studiensemester', $widgetData);
+ $this->setElementsArray(
+ $this->StudiensemesterModel->load(),
+ true,
+ 'Select a studiensemester...',
+ 'No studiensemester found'
+ );
+
+ $this->loadDropDownView($widgetData);
}
}
\ No newline at end of file
diff --git a/application/widgets/Stufe_widget.php b/application/widgets/Stufe_widget.php
index 5a188a636..18e720754 100644
--- a/application/widgets/Stufe_widget.php
+++ b/application/widgets/Stufe_widget.php
@@ -1,45 +1,23 @@
load->model('crm/Reihungstest_model', 'ReihungstestModel');
- $this->ReihungstestModel->addSelect('DISTINCT ON(stufe) stufe, stufe AS beschreibung');
+ $this->ReihungstestModel->addSelect('DISTINCT ON(stufe) stufe');
$this->ReihungstestModel->addOrder('stufe');
- $stufen = $this->ReihungstestModel->loadWhere('stufe IS NOT NULL');
- if (hasData($stufen))
- {
- // Adding an empty element at the beginning
- $emptyElement = new stdClass();
- $emptyElement->stufe = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'Select a stufe...';
- array_unshift($stufen->retval, $emptyElement);
- }
- else if (isError($stufen))
- {
- show_error($stufen);
- }
- else
- {
- // Adding an element to the array
- $emptyElement = new stdClass();
- $emptyElement->stufe = Partial::HTML_DEFAULT_VALUE;
- $emptyElement->beschreibung = 'No stufen found';
- array_unshift($stufen->retval, $emptyElement);
- }
- // Data to be used in the widget view
- $widgetData['stufen'] = $stufen->retval;
+ $this->addSelectToModel($this->ReihungstestModel, 'stufe', 'stufe');
- // Loads widget view
- $this->view('widgets/stufe', $widgetData);
+ $this->setElementsArray(
+ $this->ReihungstestModel->loadWhere('stufe IS NOT NULL'),
+ true,
+ 'Select a stufe...',
+ 'No stufen found'
+ );
+
+ $this->loadDropDownView($widgetData);
}
}
\ No newline at end of file