mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
- Added FiltersLib to contain all the shared logic of a FilterWidget
- Adapted Filters controller and FilterWidget to use this new lib - Better memory usage in FilterWidget - PhrasesLib now checks if categories is an empty array, it it is then avoid to call the method to load phrases (avoids an ugly error) - Renamed the class FHC_PhraseLib to FHC_PhrasesLib (like the filename)
This commit is contained in:
@@ -16,7 +16,7 @@ class FiltersLib
|
||||
const SESSION_ADDITIONAL_COLUMNS = 'additionalColumns';
|
||||
const SESSION_CHECKBOXES = 'checkboxes';
|
||||
const SESSION_FILTERS = 'filters';
|
||||
const SESSION_DATASET_METADATA = 'datasetMetadata';
|
||||
const SESSION_METADATA = 'datasetMetadata';
|
||||
const SESSION_DATASET = 'dataset';
|
||||
const SESSION_ROW_NUMBER = 'rowNumber';
|
||||
const SESSION_RELOAD_DATASET = 'reloadDataset';
|
||||
|
||||
@@ -257,7 +257,8 @@ class PhrasesLib
|
||||
$language = $this->_ci->PersonModel->getLanguage(getAuthUID());
|
||||
}
|
||||
|
||||
$this->_setPhrases($categories, $language);
|
||||
// If only categories is not an empty array then loads phrases
|
||||
if (count($categories) > 0) $this->_setPhrases($categories, $language);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,8 +286,7 @@ class PhrasesLib
|
||||
{
|
||||
// is assoc array -> Loads specific phrasentexte by category and phrases
|
||||
$isIndexArray = false;
|
||||
$phrases = $this->_ci->PhraseModel
|
||||
->getPhrasesByCategoryAndPhrasesAndLanguage($categories, $language);
|
||||
$phrases = $this->_ci->PhraseModel->getPhrasesByCategoryAndPhrasesAndLanguage($categories, $language);
|
||||
}
|
||||
|
||||
// If language is not default language and phrasentext is null -> fallback to default language
|
||||
@@ -296,13 +296,11 @@ class PhrasesLib
|
||||
$defaultPhrases = null;
|
||||
if ($isIndexArray)
|
||||
{
|
||||
$defaultPhrases = $this->_ci->PhraseModel
|
||||
->getPhrasesByCategoryAndLanguage($categories, DEFAULT_LANGUAGE);
|
||||
$defaultPhrases = $this->_ci->PhraseModel->getPhrasesByCategoryAndLanguage($categories, DEFAULT_LANGUAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
$defaultPhrases = $this->_ci->PhraseModel
|
||||
->getPhrasesByCategoryAndPhrasesAndLanguage($categories, DEFAULT_LANGUAGE);
|
||||
$defaultPhrases = $this->_ci->PhraseModel->getPhrasesByCategoryAndPhrasesAndLanguage($categories, DEFAULT_LANGUAGE);
|
||||
}
|
||||
|
||||
// combine array with phrasentexte in users language and in default language
|
||||
|
||||
@@ -96,7 +96,7 @@ function _generateJSPhrasesStorageObject($phrases)
|
||||
$toPrint = "\n";
|
||||
$toPrint .= '<script type="text/javascript">';
|
||||
$toPrint .= "\n";
|
||||
$toPrint .= 'var FHC_JS_PHRASES_STORAGE_OBJECT = '.$ci->pj->getJSON();
|
||||
$toPrint .= ' var FHC_JS_PHRASES_STORAGE_OBJECT = '.$ci->pj->getJSON().';';
|
||||
$toPrint .= "\n";
|
||||
$toPrint .= '</script>';
|
||||
$toPrint .= "\n\n";
|
||||
|
||||
@@ -283,15 +283,12 @@ class FilterWidget extends Widget
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$formattedDataset = $this->_formatDataset($dataset); // format the dataset using markRow and formatRow
|
||||
$this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow
|
||||
|
||||
// Set the new dataset and it's attributes in the session
|
||||
$this->filterslib->setElementSession(
|
||||
FiltersLib::SESSION_DATASET_METADATA,
|
||||
$this->FiltersModel->getExecutedQueryMetaData()
|
||||
);
|
||||
// Set the new dataset and its attributes in the session
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_METADATA, $this->FiltersModel->getExecutedQueryMetaData());
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_ROW_NUMBER, count($dataset->retval));
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_DATASET, $formattedDataset);
|
||||
$this->filterslib->setElementSession(FiltersLib::SESSION_DATASET, $dataset->retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,7 +321,7 @@ class FilterWidget extends Widget
|
||||
// Save changes into session if data are valid
|
||||
if (!isError($dataset))
|
||||
{
|
||||
$formattedDataset = $this->_formatDataset($dataset); // format the dataset using markRow and formatRow
|
||||
$this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow
|
||||
|
||||
// Stores an array that contains all the data useful for
|
||||
$this->filterslib->setSession(
|
||||
@@ -341,90 +338,86 @@ class FilterWidget extends Widget
|
||||
FiltersLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns, //
|
||||
FiltersLib::SESSION_CHECKBOXES => $this->_checkboxes, //
|
||||
FiltersLib::SESSION_FILTERS => $parsedFilterJson->filters, //
|
||||
FiltersLib::SESSION_DATASET_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), //
|
||||
FiltersLib::SESSION_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), //
|
||||
FiltersLib::SESSION_ROW_NUMBER => count($dataset->retval), //
|
||||
FiltersLib::SESSION_DATASET => $formattedDataset, //
|
||||
FiltersLib::SESSION_DATASET => $dataset->retval, //
|
||||
FiltersLib::SESSION_RELOAD_DATASET => false //
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// var_dump($this->filterslib->getSession());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Calls the method _markRow and _formatRow to marks rows using markRow and format rowns using formatRow
|
||||
* NOTE: this method operates directly on the retrived dataset: parameter passed by reference
|
||||
*/
|
||||
private function _formatDataset($rawDataset)
|
||||
private function _formatDataset(&$rawDataset)
|
||||
{
|
||||
$formattedDataset = null;
|
||||
|
||||
if (hasData($rawDataset) && is_array($rawDataset->retval))
|
||||
{
|
||||
$formattedDataset = array();
|
||||
|
||||
// For each row of the data set
|
||||
for ($rowCounter = 0; $rowCounter < count($rawDataset->retval); $rowCounter++)
|
||||
{
|
||||
$row = $rawDataset->retval[$rowCounter];
|
||||
|
||||
$formattedRow = $this->_formatRow($row);
|
||||
$formattedRow->MARK_ROW_CLASS = $this->_markRow($row);
|
||||
$formattedDataset[] = $formattedRow;
|
||||
// Calls the methods to mark and to format a row
|
||||
// NOTE: keep this order! the markRow function given as parameter is supposing to work
|
||||
// on a raw dataset, NOT on a formatted one
|
||||
$rawDataset->retval[$rowCounter]->MARK_ROW_CLASS = $this->_markRow($rawDataset->retval[$rowCounter]);
|
||||
$this->_formatRow($rawDataset->retval[$rowCounter]);
|
||||
}
|
||||
}
|
||||
|
||||
return $formattedDataset;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Formats the columns of all the rows of the entire dataset
|
||||
* - converts booleans into strings "true" and "false"
|
||||
* - format dates using the format string defined in DEFAULT_DATE_FORMAT
|
||||
* Calls the parameter formatRow if it was given and if it is a valid funtion
|
||||
* NOTE: this method operates directly on the retrived dataset: parameter passed by reference
|
||||
*/
|
||||
private function _formatRow($datasetRaw)
|
||||
private function _formatRow(&$rawDatasetRow)
|
||||
{
|
||||
$tmpDatasetRaw = clone $datasetRaw;
|
||||
|
||||
foreach ($tmpDatasetRaw as $columnName => $columnValue)
|
||||
// For each column of the row
|
||||
foreach ($rawDatasetRow as $columnName => $columnValue)
|
||||
{
|
||||
// Basic conversions
|
||||
if (is_bool($columnValue))
|
||||
{
|
||||
$tmpDatasetRaw->{$columnValue} = $columnValue === true ? 'true' : 'false';
|
||||
$rawDatasetRow->{$columnValue} = $columnValue === true ? 'true' : 'false';
|
||||
}
|
||||
elseif (DateTime::createFromFormat('Y-m-d G:i:s', $columnValue) !== false)
|
||||
{
|
||||
$tmpDatasetRaw->{$columnValue} = date(self::DEFAULT_DATE_FORMAT, strtotime($columnValue));
|
||||
$rawDatasetRow->{$columnValue} = date(self::DEFAULT_DATE_FORMAT, strtotime($columnValue));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_formatRow != null)
|
||||
// If a valid function call the given formatRow
|
||||
if ($this->_formatRow != null && is_callable($this->_formatRow))
|
||||
{
|
||||
$formatRow = $this->_formatRow;
|
||||
$tmpDatasetRaw = $formatRow($tmpDatasetRaw);
|
||||
$formatRowFunction = $this->_formatRow;
|
||||
$rawDatasetRow = $formatRowFunction($rawDatasetRow);
|
||||
}
|
||||
|
||||
return $tmpDatasetRaw;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns a string that contains a class name used to mark rows in the dataset table
|
||||
* Calls the parameter markRow if it was given and if it is a valid funtion
|
||||
*/
|
||||
private function _markRow($datasetRaw)
|
||||
private function _markRow($rawDatasetRow)
|
||||
{
|
||||
if (is_object($datasetRaw))
|
||||
// If a valid function call the given markRow
|
||||
if ($this->_markRow != null && is_callable($this->_markRow))
|
||||
{
|
||||
if ($this->_markRow != null)
|
||||
{
|
||||
$markRow = $this->_markRow;
|
||||
$class = $markRow($datasetRaw);
|
||||
}
|
||||
$markRowFunction = $this->_markRow;
|
||||
$class = $markRowFunction($rawDatasetRow);
|
||||
}
|
||||
|
||||
return !isset($class) ? '' : $class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Utility method that retrives the name of the columns present in a filter JSON definition
|
||||
*/
|
||||
private function _getColumnsNames($columns)
|
||||
{
|
||||
|
||||
@@ -60,11 +60,10 @@ var FHC_FilterWidget = {
|
||||
},
|
||||
|
||||
/**
|
||||
* To refresh the whole FilterWidget GUI
|
||||
* Alias call to method display only to inprove the readability of the code
|
||||
*/
|
||||
refresh: function() {
|
||||
|
||||
FHC_FilterWidget._resetFilterOptions();
|
||||
FHC_FilterWidget.display();
|
||||
},
|
||||
|
||||
@@ -114,19 +113,12 @@ var FHC_FilterWidget = {
|
||||
/**
|
||||
* To reset the Filter Options GUI
|
||||
*/
|
||||
_resetFilterOptions: function() {
|
||||
_resetGUI: function() {
|
||||
|
||||
$("#dragAndDropFieldsArea").html("");
|
||||
$("#addField").html("<option value=''>" + FHC_PhraseLib.t("ui", "bitteEintragWaehlen") + "</option>");
|
||||
$("#addField").html("<option value=''>" + FHC_PhrasesLib.t("ui", "bitteEintragWaehlen") + "</option>");
|
||||
$("#appliedFilters").html("");
|
||||
$("#addFilter").html("<option value=''>" + FHC_PhraseLib.t("ui", "bitteEintragWaehlen") + "</option>");
|
||||
},
|
||||
|
||||
/**
|
||||
* To reset the Filter Table GUI
|
||||
*/
|
||||
_resetTableDataset: function() {
|
||||
|
||||
$("#addFilter").html("<option value=''>" + FHC_PhrasesLib.t("ui", "bitteEintragWaehlen") + "</option>");
|
||||
$("#filterTableDataset > thead > tr").html("");
|
||||
$("#filterTableDataset > tbody").html("");
|
||||
},
|
||||
@@ -157,15 +149,13 @@ var FHC_FilterWidget = {
|
||||
* This method calls all the other methods needed to rendere the GUI for a FilterWidget
|
||||
* The parameter data contains all the data about the FilterWidget and it is given as parameter
|
||||
* to all the methods that here are called
|
||||
* NOTE: think very carefully before changing the order of the calls
|
||||
*/
|
||||
_renderFilterWidget: function(data) {
|
||||
|
||||
FHC_FilterWidget._initSessionStorage(); // initialize the session storage
|
||||
FHC_FilterWidget._turnOffEvents(); // turns all the events off
|
||||
|
||||
// Reset the entire GUI
|
||||
FHC_FilterWidget._resetFilterOptions();
|
||||
FHC_FilterWidget._resetTableDataset();
|
||||
FHC_FilterWidget._resetGUI(); // Reset the entire GUI
|
||||
|
||||
// Render the GUI for this FilterWidget
|
||||
FHC_FilterWidget._setFilterName(data); // set the name in the GUI
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Definition and initialization of object FHC_PhraseLib
|
||||
* Definition and initialization of object FHC_PhrasesLib
|
||||
*/
|
||||
var FHC_PhraseLib = {
|
||||
var FHC_PhrasesLib = {
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
@@ -46,7 +46,7 @@ var FHC_PhraseLib = {
|
||||
params = [];
|
||||
}
|
||||
|
||||
return FHC_PhraseLib._replacePhraseVariable(phraseObj.text, params); // parsing
|
||||
return FHC_PhrasesLib._replacePhraseVariable(phraseObj.text, params); // parsing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ $(document).ready(function ()
|
||||
var notizTitle = $(this).find("td:eq(1)").text();
|
||||
var notizContent = this.title;
|
||||
|
||||
$("#notizform label:first").text(FHC_PhraseLib.t('infocenter', 'notizAendern')).css("color", "red");
|
||||
$("#notizform label:first").text(FHC_PhrasesLib.t('infocenter', 'notizAendern')).css("color", "red");
|
||||
$("#notizform :input[type='reset']").css("display", "inline-block");
|
||||
|
||||
$("#notizform :input[name='hiddenNotizId']").val(notizId);
|
||||
@@ -241,7 +241,7 @@ var InfocenterDetails = {
|
||||
saveZgv: function(data)
|
||||
{
|
||||
var zgvError = function(){
|
||||
$("#zgvSpeichern_" + prestudentid).before("<span id='zgvSpeichernNotice' class='text-danger'>" + FHC_PhraseLib.t('ui', 'fehlerBeimSpeichern') + "</span> ");
|
||||
$("#zgvSpeichern_" + prestudentid).before("<span id='zgvSpeichernNotice' class='text-danger'>" + FHC_PhrasesLib.t('ui', 'fehlerBeimSpeichern') + "</span> ");
|
||||
};
|
||||
|
||||
var prestudentid = data.prestudentid;
|
||||
@@ -256,7 +256,7 @@ var InfocenterDetails = {
|
||||
if (FHC_AjaxClient.hasData(data))
|
||||
{
|
||||
InfocenterDetails._refreshLog();
|
||||
$("#zgvSpeichern_" + prestudentid).before("<span id='zgvSpeichernNotice' class='text-success'>" + FHC_PhraseLib.t('ui', 'gespeichert') + "</span> ");
|
||||
$("#zgvSpeichern_" + prestudentid).before("<span id='zgvSpeichernNotice' class='text-success'>" + FHC_PhrasesLib.t('ui', 'gespeichert') + "</span> ");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -387,11 +387,11 @@ var InfocenterDetails = {
|
||||
if (data.length > 0)
|
||||
InfocenterDetails.getParkedDate(personid);
|
||||
else
|
||||
$("#unparkmsg").removeClass().addClass("text-warning").text(FHC_PhraseLib.t('infocenter', 'nichtsZumAusparken'));
|
||||
$("#unparkmsg").removeClass().addClass("text-warning").text(FHC_PhrasesLib.t('infocenter', 'nichtsZumAusparken'));
|
||||
}
|
||||
},
|
||||
errorCallback: function(){
|
||||
$("#unparkmsg").removeClass().addClass("text-danger").text(FHC_PhraseLib.t('infocenter', 'fehlerBeimAusparken'));
|
||||
$("#unparkmsg").removeClass().addClass("text-danger").text(FHC_PhrasesLib.t('infocenter', 'fehlerBeimAusparken'));
|
||||
},
|
||||
veilTimeout: 0
|
||||
}
|
||||
@@ -435,8 +435,8 @@ var InfocenterDetails = {
|
||||
{
|
||||
$("#parking").html(
|
||||
'<div class="form-group form-inline">'+
|
||||
'<button class="btn btn-default" id="parklink" type="button""><i class="fa fa-clock-o"></i> ' + FHC_PhraseLib.t('infocenter', 'bewerberParken') + '</button> '+
|
||||
FHC_PhraseLib.t('global', 'bis') + ' '+
|
||||
'<button class="btn btn-default" id="parklink" type="button""><i class="fa fa-clock-o"></i> ' + FHC_PhrasesLib.t('infocenter', 'bewerberParken') + '</button> '+
|
||||
FHC_PhrasesLib.t('global', 'bis') + ' '+
|
||||
'<input id="parkdate" type="text" class="form-control" placeholder="Parkdatum" style="height: 25px; width: 99px"> '+
|
||||
'<span class="text-danger" id="parkmsg"></span>'+
|
||||
'</div>');
|
||||
@@ -462,8 +462,8 @@ var InfocenterDetails = {
|
||||
var parkdate = $.datepicker.parseDate("yy-mm-dd", date);
|
||||
var gerparkdate = $.datepicker.formatDate("dd.mm.yy", parkdate);
|
||||
$("#parking").html(
|
||||
FHC_PhraseLib.t('infocenter', 'bewerberGeparktBis')+' '+gerparkdate+' '+
|
||||
'<button class="btn btn-default" id="unparklink"><i class="fa fa-sign-out"></i> '+FHC_PhraseLib.t('infocenter', 'bewerberAusparken')+'</button> '+
|
||||
FHC_PhrasesLib.t('infocenter', 'bewerberGeparktBis')+' '+gerparkdate+' '+
|
||||
'<button class="btn btn-default" id="unparklink"><i class="fa fa-sign-out"></i> '+FHC_PhrasesLib.t('infocenter', 'bewerberAusparken')+'</button> '+
|
||||
'<span id="unparkmsg"></span>'
|
||||
);
|
||||
|
||||
@@ -486,11 +486,11 @@ var InfocenterDetails = {
|
||||
{
|
||||
$("#notizmsg").empty();
|
||||
$("#notizform :input[name='hiddenNotizId']").val("");
|
||||
$("#notizform label:first").text(FHC_PhraseLib.t('infocenter', 'notizHinzufuegen')).css("color", "black");
|
||||
$("#notizform label:first").text(FHC_PhrasesLib.t('infocenter', 'notizHinzufuegen')).css("color", "black");
|
||||
$("#notizform :input[type='reset']").css("display", "none");
|
||||
},
|
||||
_errorSaveNotiz: function()
|
||||
{
|
||||
$("#notizmsg").text(FHC_PhraseLib.t('ui', 'fehlerBeimSpeichern'));
|
||||
$("#notizmsg").text(FHC_PhrasesLib.t('ui', 'fehlerBeimSpeichern'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ var Tablesort = {
|
||||
size: size,
|
||||
cssDisabled: 'disabled',
|
||||
savePages: false,
|
||||
output: '{startRow} – {endRow} / {totalRows} ' + FHC_PhraseLib.t('global', 'zeilen')
|
||||
output: '{startRow} – {endRow} / {totalRows} ' + FHC_PhrasesLib.t('global', 'zeilen')
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user