ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 345 of file class.ilUnitConfigurationRepository.php.

Referenced by loadUnits().

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

◆ checkDeleteUnit()

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

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

References $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().

494  {
495  global $ilDB;
496 
497  $result = $ilDB->queryF("SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
498  array('integer'),
499  array($id)
500  );
501  if($result->numRows() > 0)
502  {
503  return $this->lng->txt("err_unit_in_variables");
504  }
505  $result = $ilDB->queryF("SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
506  array('integer'),
507  array($id)
508  );
509  if($result->numRows() > 0)
510  {
511  return $this->lng->txt("err_unit_in_results");
512  }
513  if(!is_null($category_id))
514  {
515  $result = $ilDB->queryF("SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND category_fi != %s",
516  array('integer', 'integer', 'integer'),
517  array($id, $id, $category_id)
518  );
519  }
520  else
521  {
522  $result = $ilDB->queryF("SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
523  array('integer', 'integer'),
524  array($id, $id)
525  );
526  }
527  if($result->numRows() > 0)
528  {
529  return $this->lng->txt("err_unit_is_baseunit");
530  }
531  return null;
532  }
$result
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 340 of file class.ilUnitConfigurationRepository.php.

References array.

Referenced by checkDeleteUnit(), and deleteUnit().

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

◆ deleteUnit()

ilUnitConfigurationRepository::deleteUnit (   $id)

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

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

Referenced by checkDeleteUnit().

263  {
264  global $ilDB;
265 
266  $res = $this->checkDeleteUnit($id);
267  if(!is_null($res)) return $res;
268  $affectedRows = $ilDB->manipulateF("DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
269  array('integer'),
270  array($id)
271  );
272  if($affectedRows > 0) $this->clearUnits();
273  return null;
274  }
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 444 of file class.ilUnitConfigurationRepository.php.

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

445  {
446  global $ilDB;
447 
448  $categories = array();
449  $result = $ilDB->queryF("SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s ORDER BY category",
450  array('integer'), array(0));
451  if($result->numRows())
452  {
453  while($row = $ilDB->fetchAssoc($result))
454  {
455  $value = (strcmp("-qpl_qst_formulaquestion_" . $row["category"] . "-", $this->lng->txt($row["category"])) == 0) ? $row["category"] : $this->lng->txt($row["category"]);
456 
457  if(strlen(trim($row["category"])))
458  {
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 
469  return $categories;
470  }
$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 299 of file class.ilUnitConfigurationRepository.php.

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

300  {
301  global $ilDB;
302 
303  if(count($this->categorizedUnits) == 0)
304  {
305  $result = $ilDB->queryF("
306  SELECT units.*, il_qpl_qst_fq_ucat.category, il_qpl_qst_fq_ucat.question_fi, baseunits.unit baseunit_title
307  FROM il_qpl_qst_fq_unit units
308  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
309  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
310  WHERE units.question_fi = %s
311  ORDER BY il_qpl_qst_fq_ucat.category, units.sequence",
312  array('integer'), array($this->getConsumerId()));
313 
314  if($result->numRows())
315  {
316  $category = '';
317  while($row = $ilDB->fetchAssoc($result))
318  {
319  $unit = new assFormulaQuestionUnit();
320  $unit->initFormArray($row);
321  if(strcmp($category, $unit->getCategory()) != 0)
322  {
323  $cat = new assFormulaQuestionUnitCategory();
324  $cat->initFormArray(array(
325  'category_id' => $row['category_fi'],
326  'category' => $row['category'],
327  'question_fi' => $row['question_fi'],
328  ));
329  array_push($this->categorizedUnits, $cat);
330  $category = $unit->getCategory();
331  }
332  array_push($this->categorizedUnits, $unit);
333  }
334  }
335  }
336 
338  }
$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 192 of file class.ilUnitConfigurationRepository.php.

References $ilDB, $result, and array.

193  {
194  global $ilDB;
195 
196  $result = $ilDB->queryF("SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
197  array('integer'),
198  array($id)
199  );
200  return $result->numRows();
201  }
$result
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, $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 390 of file class.ilUnitConfigurationRepository.php.

References loadUnits().

391  {
392 
393  if(count($this->units) == 0)
394  {
395  $this->loadUnits();
396  }
397  if(array_key_exists($id, $this->units))
398  {
399  return $this->units[$id];
400  }
401  else
402  {
403  //maybee this is a new unit ...
404  // reload $this->units
405 
406  $this->loadUnits();
407  if(array_key_exists($id, $this->units))
408  {
409  return $this->units[$id];
410  }
411  }
412  return null;
413  }
+ Here is the call graph for this function:

◆ getUnitCategories()

ilUnitConfigurationRepository::getUnitCategories ( )

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

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

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

◆ getUnits()

ilUnitConfigurationRepository::getUnits ( )

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

References $units, and loadUnits().

351  {
352  if(count($this->units) == 0)
353  {
354  $this->loadUnits();
355  }
356  return $this->units;
357  }
+ Here is the call graph for this function:

◆ isUnitInUse()

ilUnitConfigurationRepository::isUnitInUse (   $id)

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

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

204  {
205  global $ilDB;
206 
207  $result_1 = $ilDB->queryF("SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
208  array('integer'),
209  array($id)
210  );
211 
212  $result_2 = $ilDB->queryF("SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
213  array('integer'),
214  array($id)
215  );
216  $result_3 = $ilDB->queryF("SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
217  array('integer'),
218  array($id)
219  );
220 
221  $cnt_1 = $ilDB->numRows($result_1);
222  $cnt_2 = $ilDB->numRows($result_2);
223  $cnt_3 = $ilDB->numRows($result_3);
224 
225  if($cnt_1 || $cnt_2 || $cnt_3)
226  {
227  return true;
228  }
229  else
230  {
231  return false;
232  }
233  }
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 276 of file class.ilUnitConfigurationRepository.php.

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

Referenced by getUnit(), and getUnits().

277  {
278  global $ilDB;
279 
280  $result = $ilDB->query("
281  SELECT units.*, il_qpl_qst_fq_ucat.category, baseunits.unit baseunit_title
282  FROM il_qpl_qst_fq_unit units
283  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
284  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
285  ORDER BY il_qpl_qst_fq_ucat.category, units.sequence"
286  );
287 
288  if($result->numRows())
289  {
290  while($row = $ilDB->fetchAssoc($result))
291  {
292  $unit = new assFormulaQuestionUnit();
293  $unit->initFormArray($row);
294  $this->addUnit($unit);
295  }
296  }
297  }
$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 359 of file class.ilUnitConfigurationRepository.php.

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

360  {
361  global $ilDB;
362 
363  $units = array();
364  $result = $ilDB->queryF("
365  SELECT units.*, baseunits.unit baseunit_title
366  FROM il_qpl_qst_fq_unit units
367  INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi
368  LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi
369  WHERE il_qpl_qst_fq_ucat.category_id = %s
370  ORDER BY units.sequence",
371  array('integer'),
372  array($category)
373  );
374  if($result->numRows())
375  {
376  while($row = $ilDB->fetchAssoc($result))
377  {
378  $unit = new assFormulaQuestionUnit();
379  $unit->initFormArray($row);
380  array_push($units, $unit);
381  }
382  }
383  return $units;
384  }
$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: