ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilUnitConfigurationRepository Class Reference

Class ilUnitConfigurationRepository. More...

+ Collaboration diagram for ilUnitConfigurationRepository:

Public Member Functions

 setConsumerId ($consumer_id)
 
 getConsumerId ()
 
 getCategoryUnitCount ($id)
 
 isUnitInUse ($id)
 
 deleteUnit ($id)
 
 getCategorizedUnits ()
 
 getUnits ()
 
 loadUnitsForCategory ($category)
 
 getUnit ($id)
 
 getUnitCategories ()
 
 getAdminUnitCategories ()
 
 checkDeleteUnit ($id, $category_id=null)
 

Protected Member Functions

 loadUnits ()
 
 clearUnits ()
 
 addUnit ($unit)
 

Protected Attributes

 $consumer_id = 0
 
 $lng
 

Private Attributes

 $units = array()
 
 $categorizedUnits = array()
 

Detailed Description

Member Function Documentation

◆ addUnit()

ilUnitConfigurationRepository::addUnit (   $unit)
protected

Definition at line 359 of file class.ilUnitConfigurationRepository.php.

Referenced by loadUnits().

360  {
361  $this->units[$unit->getId()] = $unit;
362  }
+ Here is the caller graph for this function:

◆ checkDeleteUnit()

ilUnitConfigurationRepository::checkDeleteUnit (   $id,
  $category_id = null 
)

Definition at line 499 of file class.ilUnitConfigurationRepository.php.

References $i, $id, $ilDB, $query, $res, $result, $row, $units, array, clearUnits(), deleteUnit(), assFormulaQuestionUnit\getBaseUnit(), assFormulaQuestionUnitCategory\getCategory(), assFormulaQuestionUnit\getCategory(), getConsumerId(), assFormulaQuestionUnit\getFactor(), assFormulaQuestionUnitCategory\getId(), assFormulaQuestionUnit\getId(), assFormulaQuestionUnit\getSequence(), assFormulaQuestionUnit\getUnit(), assFormulaQuestionUnitCategory\initFormArray(), assFormulaQuestionUnit\setBaseUnit(), assFormulaQuestionUnit\setFactor(), assFormulaQuestionUnitCategory\setId(), assFormulaQuestionUnit\setId(), and assFormulaQuestionUnit\setSequence().

Referenced by deleteUnit(), and isUnitInUse().

500  {
501  global $ilDB;
502 
503  $result = $ilDB->queryF(
504  "SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
505  array('integer'),
506  array($id)
507  );
508  if ($result->numRows() > 0) {
509  return $this->lng->txt("err_unit_in_variables");
510  }
511  $result = $ilDB->queryF(
512  "SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
513  array('integer'),
514  array($id)
515  );
516  if ($result->numRows() > 0) {
517  return $this->lng->txt("err_unit_in_results");
518  }
519  if (!is_null($category_id)) {
520  $result = $ilDB->queryF(
521  "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND category_fi != %s",
522  array('integer', 'integer', 'integer'),
523  array($id, $id, $category_id)
524  );
525  } else {
526  $result = $ilDB->queryF(
527  "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
528  array('integer', 'integer'),
529  array($id, $id)
530  );
531  }
532  if ($result->numRows() > 0) {
533  return $this->lng->txt("err_unit_is_baseunit");
534  }
535  return null;
536  }
$result
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearUnits()

ilUnitConfigurationRepository::clearUnits ( )
protected

Definition at line 354 of file class.ilUnitConfigurationRepository.php.

References array.

Referenced by checkDeleteUnit(), and deleteUnit().

355  {
356  $this->units = array();
357  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ deleteUnit()

ilUnitConfigurationRepository::deleteUnit (   $id)

Definition at line 273 of file class.ilUnitConfigurationRepository.php.

References $id, $ilDB, $res, array, checkDeleteUnit(), and clearUnits().

Referenced by checkDeleteUnit().

274  {
275  global $ilDB;
276 
277  $res = $this->checkDeleteUnit($id);
278  if (!is_null($res)) {
279  return $res;
280  }
281  $affectedRows = $ilDB->manipulateF(
282  "DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
283  array('integer'),
284  array($id)
285  );
286  if ($affectedRows > 0) {
287  $this->clearUnits();
288  }
289  return null;
290  }
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAdminUnitCategories()

ilUnitConfigurationRepository::getAdminUnitCategories ( )

Definition at line 449 of file class.ilUnitConfigurationRepository.php.

References $ilDB, $result, $row, array, and getConsumerId().

450  {
451  global $ilDB;
452 
453  $categories = array();
454  $result = $ilDB->queryF(
455  "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s ORDER BY category",
456  array('integer'),
457  array(0)
458  );
459  if ($result->numRows()) {
460  while ($row = $ilDB->fetchAssoc($result)) {
461  $value = (strcmp("-qpl_qst_formulaquestion_" . $row["category"] . "-", $this->lng->txt($row["category"])) == 0) ? $row["category"] : $this->lng->txt($row["category"]);
462 
463  if (strlen(trim($row["category"]))) {
464  $cat = array(
465  "value" => $row["category_id"],
466  "text" => $value,
467  "qst_id" => $row['question_fi']
468  );
469  $categories[$row["category_id"]] = $cat;
470  }
471  }
472  }
473 
474  return $categories;
475  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ getCategorizedUnits()

ilUnitConfigurationRepository::getCategorizedUnits ( )

Definition at line 314 of file class.ilUnitConfigurationRepository.php.

References $categorizedUnits, $ilDB, $result, $row, array, and getConsumerId().

315  {
316  global $ilDB;
317 
318  if (count($this->categorizedUnits) == 0) {
319  $result = $ilDB->queryF(
320  "
321  SELECT units.*, il_qpl_qst_fq_ucat.category, il_qpl_qst_fq_ucat.question_fi, baseunits.unit baseunit_title
322  FROM il_qpl_qst_fq_unit units
323  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
324  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
325  WHERE units.question_fi = %s
326  ORDER BY il_qpl_qst_fq_ucat.category, units.sequence",
327  array('integer'),
328  array($this->getConsumerId())
329  );
330 
331  if ($result->numRows()) {
332  $category = '';
333  while ($row = $ilDB->fetchAssoc($result)) {
334  $unit = new assFormulaQuestionUnit();
335  $unit->initFormArray($row);
336  if (strcmp($category, $unit->getCategory()) != 0) {
337  $cat = new assFormulaQuestionUnitCategory();
338  $cat->initFormArray(array(
339  'category_id' => $row['category_fi'],
340  'category' => $row['category'],
341  'question_fi' => $row['question_fi'],
342  ));
343  array_push($this->categorizedUnits, $cat);
344  $category = $unit->getCategory();
345  }
346  array_push($this->categorizedUnits, $unit);
347  }
348  }
349  }
350 
352  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ getCategoryUnitCount()

ilUnitConfigurationRepository::getCategoryUnitCount (   $id)

Definition at line 202 of file class.ilUnitConfigurationRepository.php.

References $id, $ilDB, $result, and array.

203  {
204  global $ilDB;
205 
206  $result = $ilDB->queryF(
207  "SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
208  array('integer'),
209  array($id)
210  );
211  return $result->numRows();
212  }
$result
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
global $ilDB

◆ getConsumerId()

ilUnitConfigurationRepository::getConsumerId ( )
Returns
int

Definition at line 57 of file class.ilUnitConfigurationRepository.php.

References $consumer_id, $i, $ilDB, $res, $row, $units, and array.

Referenced by checkDeleteUnit(), getAdminUnitCategories(), and getCategorizedUnits().

+ Here is the caller graph for this function:

◆ getUnit()

ilUnitConfigurationRepository::getUnit (   $id)
Parameters
int$id
Returns
assFormulaQuestionUnit

Definition at line 402 of file class.ilUnitConfigurationRepository.php.

References $id, and loadUnits().

403  {
404  if (count($this->units) == 0) {
405  $this->loadUnits();
406  }
407  if (array_key_exists($id, $this->units)) {
408  return $this->units[$id];
409  } else {
410  //maybee this is a new unit ...
411  // reload $this->units
412 
413  $this->loadUnits();
414  if (array_key_exists($id, $this->units)) {
415  return $this->units[$id];
416  }
417  }
418  return null;
419  }
if(!array_key_exists('StateId', $_REQUEST)) $id
+ Here is the call graph for this function:

◆ getUnitCategories()

ilUnitConfigurationRepository::getUnitCategories ( )

Definition at line 422 of file class.ilUnitConfigurationRepository.php.

References $ilDB, $result, $row, and array.

423  {
424  global $ilDB;
425 
426  $categories = array();
427  $result = $ilDB->queryF(
428  "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi > %s ORDER BY category",
429  array('integer'),
430  array(0)
431  );
432  if ($result->numRows()) {
433  while ($row = $ilDB->fetchAssoc($result)) {
434  $value = (strcmp("-qpl_qst_formulaquestion_" . $row["category"] . "-", $this->lng->txt($row["category"])) == 0) ? $row["category"] : $this->lng->txt($row["category"]);
435 
436  if (strlen(trim($row["category"]))) {
437  $cat = array(
438  "value" => $row["category_id"],
439  "text" => $value,
440  "qst_id" => $row['question_fi']
441  );
442  $categories[$row["category_id"]] = $cat;
443  }
444  }
445  }
446  return $categories;
447  }
$result
Create styles array
The data for the language used.
global $ilDB

◆ getUnits()

ilUnitConfigurationRepository::getUnits ( )

Definition at line 364 of file class.ilUnitConfigurationRepository.php.

References $units, and loadUnits().

365  {
366  if (count($this->units) == 0) {
367  $this->loadUnits();
368  }
369  return $this->units;
370  }
+ Here is the call graph for this function:

◆ isUnitInUse()

ilUnitConfigurationRepository::isUnitInUse (   $id)

Definition at line 214 of file class.ilUnitConfigurationRepository.php.

References $id, $ilDB, $res, $row, array, and checkDeleteUnit().

215  {
216  global $ilDB;
217 
218  $result_1 = $ilDB->queryF(
219  "SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
220  array('integer'),
221  array($id)
222  );
223 
224  $result_2 = $ilDB->queryF(
225  "SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
226  array('integer'),
227  array($id)
228  );
229  $result_3 = $ilDB->queryF(
230  "SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
231  array('integer'),
232  array($id)
233  );
234 
235  $cnt_1 = $ilDB->numRows($result_1);
236  $cnt_2 = $ilDB->numRows($result_2);
237  $cnt_3 = $ilDB->numRows($result_3);
238 
239  if ($cnt_1 || $cnt_2 || $cnt_3) {
240  return true;
241  } else {
242  return false;
243  }
244  }
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ loadUnits()

ilUnitConfigurationRepository::loadUnits ( )
protected

Definition at line 292 of file class.ilUnitConfigurationRepository.php.

References $ilDB, $result, $row, and addUnit().

Referenced by getUnit(), and getUnits().

293  {
294  global $ilDB;
295 
296  $result = $ilDB->query(
297  "
298  SELECT units.*, il_qpl_qst_fq_ucat.category, baseunits.unit baseunit_title
299  FROM il_qpl_qst_fq_unit units
300  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
301  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
302  ORDER BY il_qpl_qst_fq_ucat.category, units.sequence"
303  );
304 
305  if ($result->numRows()) {
306  while ($row = $ilDB->fetchAssoc($result)) {
307  $unit = new assFormulaQuestionUnit();
308  $unit->initFormArray($row);
309  $this->addUnit($unit);
310  }
311  }
312  }
$result
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadUnitsForCategory()

ilUnitConfigurationRepository::loadUnitsForCategory (   $category)

Definition at line 372 of file class.ilUnitConfigurationRepository.php.

References $ilDB, $result, $row, $units, and array.

373  {
374  global $ilDB;
375 
376  $units = array();
377  $result = $ilDB->queryF(
378  "
379  SELECT units.*, baseunits.unit baseunit_title
380  FROM il_qpl_qst_fq_unit units
381  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
382  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
383  WHERE il_qpl_qst_fq_ucat.category_id = %s
384  ORDER BY units.sequence",
385  array('integer'),
386  array($category)
387  );
388  if ($result->numRows()) {
389  while ($row = $ilDB->fetchAssoc($result)) {
390  $unit = new assFormulaQuestionUnit();
391  $unit->initFormArray($row);
392  array_push($units, $unit);
393  }
394  }
395  return $units;
396  }
$result
Create styles array
The data for the language used.
global $ilDB

◆ setConsumerId()

ilUnitConfigurationRepository::setConsumerId (   $consumer_id)
Parameters
int$context_id

Definition at line 49 of file class.ilUnitConfigurationRepository.php.

References $consumer_id.

50  {
51  $this->consumer_id = $consumer_id;
52  }

Field Documentation

◆ $categorizedUnits

ilUnitConfigurationRepository::$categorizedUnits = array()
private

Definition at line 30 of file class.ilUnitConfigurationRepository.php.

Referenced by getCategorizedUnits().

◆ $consumer_id

ilUnitConfigurationRepository::$consumer_id = 0
protected

Definition at line 15 of file class.ilUnitConfigurationRepository.php.

Referenced by getConsumerId(), and setConsumerId().

◆ $lng

ilUnitConfigurationRepository::$lng
protected

Definition at line 20 of file class.ilUnitConfigurationRepository.php.

◆ $units

ilUnitConfigurationRepository::$units = array()
private

The documentation for this class was generated from the following file: