mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
- Added method existsUDF
- Added comments
This commit is contained in:
+81
-33
@@ -15,12 +15,15 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Authors: Bison Paolo <bison@technikum-wien.at>
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__).'/basis_db.class.php');
|
||||
require_once(dirname(__FILE__).'/../config/global.config.inc.php');
|
||||
|
||||
/**
|
||||
* Used to export UDF in MS Excel format
|
||||
*/
|
||||
class UDF extends basis_db
|
||||
{
|
||||
/**
|
||||
@@ -32,7 +35,7 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the titles (short description) of the UDF related to the table tbl_person
|
||||
*/
|
||||
public function getTitlesPerson()
|
||||
{
|
||||
@@ -40,7 +43,7 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the titles (short description) of the UDF related to the table tbl_prestudent
|
||||
*/
|
||||
public function getTitlesPrestudent()
|
||||
{
|
||||
@@ -48,23 +51,67 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads the UDF definitions related to the table tbl_person
|
||||
*/
|
||||
public function loadPersonJsons()
|
||||
{
|
||||
return $this->_loadJsons('public', 'tbl_person');
|
||||
$jsons = null;
|
||||
|
||||
if ($this->existsUDF() && $this->prestudentHasUDF())
|
||||
{
|
||||
$jsons = $this->_loadJsons('public', 'tbl_person');
|
||||
}
|
||||
|
||||
return $jsons;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads the UDF definitions related to the table tbl_prestudent
|
||||
*/
|
||||
public function loadPrestudentJsons()
|
||||
{
|
||||
return $this->_loadJsons('public', 'tbl_prestudent');
|
||||
$jsons = null;
|
||||
|
||||
if ($this->existsUDF() && $this->prestudentHasUDF())
|
||||
{
|
||||
$jsons = $this->_loadJsons('public', 'tbl_prestudent');
|
||||
}
|
||||
|
||||
return $jsons;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Checks if the table system.tbl_udf exists
|
||||
*/
|
||||
public function existsUDF()
|
||||
{
|
||||
$existsUDF = false;
|
||||
|
||||
$query = 'SELECT COUNT(*) AS count
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = \'system\'
|
||||
AND table_name = \'tbl_udf\'';
|
||||
|
||||
if (!$this->db_query($query))
|
||||
{
|
||||
$this->errormsg = 'Error!!!';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($row = $this->db_fetch_object())
|
||||
{
|
||||
if (isset($row->count) && $row->count > 0)
|
||||
{
|
||||
$existsUDF = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $existsUDF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the column udf_values exists in table tbl_person
|
||||
*/
|
||||
public function personHasUDF()
|
||||
{
|
||||
@@ -95,7 +142,7 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Checks if the column udf_values exists in table tbl_prestudent
|
||||
*/
|
||||
public function prestudentHasUDF()
|
||||
{
|
||||
@@ -126,7 +173,7 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads the UDF definitions related to the given schema and table
|
||||
*/
|
||||
private function _loadJsons($schema, $table)
|
||||
{
|
||||
@@ -149,11 +196,10 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Sorts the UDF definitions using the proprierty "sort"
|
||||
*/
|
||||
private function _sortJsonSchemas(&$jsonSchemasArray)
|
||||
{
|
||||
//
|
||||
usort($jsonSchemasArray, function ($a, $b) {
|
||||
//
|
||||
if (!isset($a->sort))
|
||||
@@ -175,24 +221,23 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns an array of associative arrays that contains the couple name and title related to an UDF
|
||||
* These data are retrived from the UDF definitions given as parameter
|
||||
*/
|
||||
private function _getUDFDefinition($jsons)
|
||||
{
|
||||
$names = array();
|
||||
|
||||
//
|
||||
if ($jsons != null && ($jsonsDecoded = json_decode($jsons)) != null)
|
||||
{
|
||||
if (is_object($jsonsDecoded) || is_array($jsonsDecoded))
|
||||
{
|
||||
//
|
||||
if (is_object($jsonsDecoded))
|
||||
{
|
||||
$jsonsDecoded = array($jsonsDecoded);
|
||||
}
|
||||
|
||||
$this->_sortJsonSchemas($jsonsDecoded); //
|
||||
$this->_sortJsonSchemas($jsonsDecoded);
|
||||
|
||||
foreach($jsonsDecoded as $udfJsonShema)
|
||||
{
|
||||
@@ -208,7 +253,7 @@ class UDF extends basis_db
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads UDf titles from phrases
|
||||
*/
|
||||
private function _loadTitles($udfDefinitions)
|
||||
{
|
||||
@@ -223,26 +268,29 @@ class UDF extends basis_db
|
||||
if ($i < count($udfDefinitions) - 1) $in .= ', ';
|
||||
}
|
||||
|
||||
$query = 'SELECT pt.text AS title, p.phrase AS phrase
|
||||
FROM system.tbl_phrase p INNER JOIN system.tbl_phrasentext pt USING(phrase_id)
|
||||
WHERE pt.sprache = \''.DEFAULT_LEHREINHEIT_SPRACHE.'\'
|
||||
AND p.phrase IN ('.$in.')';
|
||||
|
||||
if (!$this->db_query($query))
|
||||
if ($in != '')
|
||||
{
|
||||
$this->errormsg = 'Error occurred while loading jsons';
|
||||
}
|
||||
else
|
||||
{
|
||||
while ($row = $this->db_fetch_assoc())
|
||||
$query = 'SELECT pt.text AS title, p.phrase AS phrase
|
||||
FROM system.tbl_phrase p INNER JOIN system.tbl_phrasentext pt USING(phrase_id)
|
||||
WHERE pt.sprache = \''.DEFAULT_LEHREINHEIT_SPRACHE.'\'
|
||||
AND p.phrase IN ('.$in.')';
|
||||
|
||||
if (!$this->db_query($query))
|
||||
{
|
||||
for($i = 0; $i < count($udfDefinitions); $i++)
|
||||
$this->errormsg = 'Error occurred while loading jsons';
|
||||
}
|
||||
else
|
||||
{
|
||||
while ($row = $this->db_fetch_assoc())
|
||||
{
|
||||
$udfDefinition = $udfDefinitions[$i];
|
||||
if ($udfDefinition['title'] == $row['phrase'])
|
||||
for($i = 0; $i < count($udfDefinitions); $i++)
|
||||
{
|
||||
$udfDefinition['description'] = $row['title'];
|
||||
$titles[] = $udfDefinition;
|
||||
$udfDefinition = $udfDefinitions[$i];
|
||||
if ($udfDefinition['title'] == $row['phrase'])
|
||||
{
|
||||
$udfDefinition['description'] = $row['title'];
|
||||
$titles[] = $udfDefinition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user