ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 

Static Public Attributes

static $result_buffer
 

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 379 of file class.ilUnitConfigurationRepository.php.

Referenced by loadUnits().

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

◆ checkDeleteUnit()

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

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

References $DIC, $i, $id, $ilDB, $query, $res, $result, $row, $units, 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().

525  {
526  global $DIC;
527  $ilDB = $DIC['ilDB'];
528 
529  $result = $ilDB->queryF(
530  "SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
531  array('integer'),
532  array($id)
533  );
534  if ($result->numRows() > 0) {
535  return $this->lng->txt("err_unit_in_variables");
536  }
537  $result = $ilDB->queryF(
538  "SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
539  array('integer'),
540  array($id)
541  );
542  if ($result->numRows() > 0) {
543  return $this->lng->txt("err_unit_in_results");
544  }
545  if (!is_null($category_id)) {
546  $result = $ilDB->queryF(
547  "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND category_fi != %s",
548  array('integer', 'integer', 'integer'),
549  array($id, $id, $category_id)
550  );
551  } else {
552  $result = $ilDB->queryF(
553  "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
554  array('integer', 'integer'),
555  array($id, $id)
556  );
557  }
558  if ($result->numRows() > 0) {
559  return $this->lng->txt("err_unit_is_baseunit");
560  }
561  return null;
562  }
$result
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
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 373 of file class.ilUnitConfigurationRepository.php.

Referenced by checkDeleteUnit(), and deleteUnit().

374  {
375  $this->units = array();
376  self::$result_buffer = null;
377  }
+ Here is the caller graph for this function:

◆ deleteUnit()

ilUnitConfigurationRepository::deleteUnit (   $id)

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

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

Referenced by checkDeleteUnit().

282  {
283  global $DIC;
284  $ilDB = $DIC['ilDB'];
285 
286  $res = $this->checkDeleteUnit($id);
287  if (!is_null($res)) {
288  return $res;
289  }
290  $affectedRows = $ilDB->manipulateF(
291  "DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
292  array('integer'),
293  array($id)
294  );
295  if ($affectedRows > 0) {
296  $this->clearUnits();
297  }
298  self::$result_buffer = null;
299  return null;
300  }
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAdminUnitCategories()

ilUnitConfigurationRepository::getAdminUnitCategories ( )

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

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

472  {
473  global $DIC;
474  $ilDB = $DIC['ilDB'];
475 
476  $categories = array();
477  $result = $ilDB->queryF(
478  "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s ORDER BY category",
479  array('integer'),
480  array(0)
481  );
482  if ($result->numRows()) {
483  while ($row = $ilDB->fetchAssoc($result)) {
484  $value = (strcmp("-qpl_qst_formulaquestion_" . $row["category"] . "-", $this->lng->txt($row["category"])) == 0) ? $row["category"] : $this->lng->txt($row["category"]);
485 
486  if (strlen(trim($row["category"]))) {
487  $cat = array(
488  "value" => $row["category_id"],
489  "text" => $value,
490  "qst_id" => $row['question_fi']
491  );
492  $categories[$row["category_id"]] = $cat;
493  }
494  }
495  }
496 
497  return $categories;
498  }
$result
global $DIC
Definition: saml.php:7
$row
global $ilDB
+ Here is the call graph for this function:

◆ getCategorizedUnits()

ilUnitConfigurationRepository::getCategorizedUnits ( )

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

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

333  {
334  global $DIC;
335  $ilDB = $DIC['ilDB'];
336 
337  if (count($this->categorizedUnits) == 0) {
338  $result = $ilDB->queryF(
339  "
340  SELECT units.*, il_qpl_qst_fq_ucat.category, il_qpl_qst_fq_ucat.question_fi, baseunits.unit baseunit_title
341  FROM il_qpl_qst_fq_unit units
342  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
343  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
344  WHERE units.question_fi = %s
345  ORDER BY il_qpl_qst_fq_ucat.category, units.sequence",
346  array('integer'),
347  array($this->getConsumerId())
348  );
349 
350  if ($result->numRows()) {
351  $category = '';
352  while ($row = $ilDB->fetchAssoc($result)) {
353  $unit = new assFormulaQuestionUnit();
354  $unit->initFormArray($row);
355  if (strcmp($category, $unit->getCategory()) != 0) {
356  $cat = new assFormulaQuestionUnitCategory();
357  $cat->initFormArray(array(
358  'category_id' => $row['category_fi'],
359  'category' => $row['category'],
360  'question_fi' => $row['question_fi'],
361  ));
362  array_push($this->categorizedUnits, $cat);
363  $category = $unit->getCategory();
364  }
365  array_push($this->categorizedUnits, $unit);
366  }
367  }
368  }
369 
371  }
$result
global $DIC
Definition: saml.php:7
$row
global $ilDB
+ Here is the call graph for this function:

◆ getCategoryUnitCount()

ilUnitConfigurationRepository::getCategoryUnitCount (   $id)

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

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

208  {
209  global $DIC;
210  $ilDB = $DIC['ilDB'];
211 
212  $result = $ilDB->queryF(
213  "SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
214  array('integer'),
215  array($id)
216  );
217  return $result->numRows();
218  }
$result
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilDB

◆ getConsumerId()

ilUnitConfigurationRepository::getConsumerId ( )
Returns
int

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

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

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 423 of file class.ilUnitConfigurationRepository.php.

References $id, and loadUnits().

424  {
425  if (count($this->units) == 0) {
426  $this->loadUnits();
427  }
428  if (array_key_exists($id, $this->units)) {
429  return $this->units[$id];
430  } else {
431  //maybee this is a new unit ...
432  // reload $this->units
433 
434  $this->loadUnits();
435  if (array_key_exists($id, $this->units)) {
436  return $this->units[$id];
437  }
438  }
439  return null;
440  }
if(!array_key_exists('StateId', $_REQUEST)) $id
+ Here is the call graph for this function:

◆ getUnitCategories()

ilUnitConfigurationRepository::getUnitCategories ( )

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

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

444  {
445  global $DIC;
446  $ilDB = $DIC['ilDB'];
447 
448  $categories = array();
449  $result = $ilDB->queryF(
450  "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi > %s ORDER BY category",
451  array('integer'),
452  array(0)
453  );
454  if ($result->numRows()) {
455  while ($row = $ilDB->fetchAssoc($result)) {
456  $value = (strcmp("-qpl_qst_formulaquestion_" . $row["category"] . "-", $this->lng->txt($row["category"])) == 0) ? $row["category"] : $this->lng->txt($row["category"]);
457 
458  if (strlen(trim($row["category"]))) {
459  $cat = array(
460  "value" => $row["category_id"],
461  "text" => $value,
462  "qst_id" => $row['question_fi']
463  );
464  $categories[$row["category_id"]] = $cat;
465  }
466  }
467  }
468  return $categories;
469  }
$result
global $DIC
Definition: saml.php:7
$row
global $ilDB

◆ getUnits()

ilUnitConfigurationRepository::getUnits ( )

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

References $units, and loadUnits().

385  {
386  if (count($this->units) == 0) {
387  $this->loadUnits();
388  }
389  return $this->units;
390  }
+ Here is the call graph for this function:

◆ isUnitInUse()

ilUnitConfigurationRepository::isUnitInUse (   $id)

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

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

221  {
222  global $DIC;
223  $ilDB = $DIC['ilDB'];
224 
225  $result_1 = $ilDB->queryF(
226  "SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
227  array('integer'),
228  array($id)
229  );
230 
231  $result_2 = $ilDB->queryF(
232  "SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
233  array('integer'),
234  array($id)
235  );
236  $result_3 = $ilDB->queryF(
237  "SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
238  array('integer'),
239  array($id)
240  );
241 
242  $cnt_1 = $ilDB->numRows($result_1);
243  $cnt_2 = $ilDB->numRows($result_2);
244  $cnt_3 = $ilDB->numRows($result_3);
245 
246  if ($cnt_1 || $cnt_2 || $cnt_3) {
247  return true;
248  } else {
249  return false;
250  }
251  }
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilDB
+ Here is the call graph for this function:

◆ loadUnits()

ilUnitConfigurationRepository::loadUnits ( )
protected

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

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

Referenced by getUnit(), and getUnits().

305  {
306  global $DIC;
307  $ilDB = $DIC['ilDB'];
308 
309  if (self::$result_buffer == null) {
310  $result = $ilDB->query(
311  "
312  SELECT units.*, il_qpl_qst_fq_ucat.category, baseunits.unit baseunit_title
313  FROM il_qpl_qst_fq_unit units
314  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
315  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
316  ORDER BY il_qpl_qst_fq_ucat.category, units.sequence"
317  );
318 
319 
320  if ($result->numRows()) {
321  while ($row = $ilDB->fetchAssoc($result)) {
322  $unit = new assFormulaQuestionUnit();
323  $unit->initFormArray($row);
324  $this->addUnit($unit);
325  }
326  }
327  self::$result_buffer = $this->units;
328  }
329  $this->units = self::$result_buffer;
330  }
$result
global $DIC
Definition: saml.php:7
$row
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 392 of file class.ilUnitConfigurationRepository.php.

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

393  {
394  global $DIC;
395  $ilDB = $DIC['ilDB'];
396 
397  $units = array();
398  $result = $ilDB->queryF(
399  "
400  SELECT units.*, baseunits.unit baseunit_title
401  FROM il_qpl_qst_fq_unit units
402  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
403  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
404  WHERE il_qpl_qst_fq_ucat.category_id = %s
405  ORDER BY units.sequence",
406  array('integer'),
407  array($category)
408  );
409  if ($result->numRows()) {
410  while ($row = $ilDB->fetchAssoc($result)) {
411  $unit = new assFormulaQuestionUnit();
412  $unit->initFormArray($row);
413  array_push($units, $unit);
414  }
415  }
416  return $units;
417  }
$result
global $DIC
Definition: saml.php:7
$row
global $ilDB

◆ setConsumerId()

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

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

References $consumer_id.

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

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.

◆ $result_buffer

ilUnitConfigurationRepository::$result_buffer
static

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

◆ $units

ilUnitConfigurationRepository::$units = array()
private

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