4include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnit.php";
 
    5include_once 
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnitCategory.php";
 
   67    public function isCRUDAllowed($a_category_id)
 
   76            'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
 
   81        return isset($row[
'question_fi']) && $row[
'question_fi'] == $this->
getConsumerId();
 
   90    public function copyCategory($a_category_id, $a_question_fi, $a_category_name = 
null)
 
   99            'SELECT category FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
 
  101            array($a_category_id)
 
  105        if (
null === $a_category_name) {
 
  106            $a_category_name = $row[
'category'];
 
  109        $next_id = 
$ilDB->nextId(
'il_qpl_qst_fq_ucat');
 
  111            'il_qpl_qst_fq_ucat',
 
  113                'category_id' => array(
'integer', $next_id),
 
  114                'category' => array(
'text', $a_category_name),
 
  115                'question_fi' => array(
'integer', (
int) $a_question_fi)
 
  118        self::$result_buffer = 
null;
 
  127    public function copyUnitsByCategories($a_from_category_id, $a_to_category_id, $a_question_fi)
 
  136            'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
 
  138            array($a_from_category_id)
 
  143            $next_id = 
$ilDB->nextId(
'il_qpl_qst_fq_unit');
 
  145            $units[
$i][
'old_unit_id'] = $row[
'unit_id'];
 
  146            $units[
$i][
'new_unit_id'] = $next_id;
 
  149                'il_qpl_qst_fq_unit',
 
  151                    'unit_id' => array(
'integer', $next_id),
 
  152                    'unit' => array(
'text', $row[
'unit']),
 
  153                    'factor' => array(
'float', $row[
'factor']),
 
  154                    'baseunit_fi' => array(
'integer', (
int) $row[
'baseunit_fi']),
 
  155                    'category_fi' => array(
'integer', (
int) $a_to_category_id),
 
  156                    'sequence' => array(
'integer', (
int) $row[
'sequence']),
 
  157                    'question_fi' => array(
'integer', (
int) $a_question_fi)
 
  163        foreach (
$units as $unit) {
 
  166                'il_qpl_qst_fq_unit',
 
  167                array(
'baseunit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  169                    'baseunit_fi' => array(
'integer', $unit[
'old_unit_id']),
 
  170                    'category_fi' => array(
'integer', $a_to_category_id)
 
  177                array(
'unit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  179                    'unit_fi' => array(
'integer', $unit[
'old_unit_id']),
 
  180                    'question_fi' => array(
'integer', $a_question_fi)
 
  187                array(
'unit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  189                    'unit_fi' => array(
'integer', $unit[
'old_unit_id']),
 
  190                    'question_fi' => array(
'integer', $a_question_fi)
 
  196                'il_qpl_qst_fq_res_unit',
 
  197                array(
'unit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  199                    'unit_fi' => array(
'integer', $unit[
'old_unit_id']),
 
  200                    'question_fi' => array(
'integer', $a_question_fi)
 
  204        self::$result_buffer = 
null;
 
  213            "SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
 
  225        $result_1 = 
$ilDB->queryF(
 
  226            "SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
 
  231        $result_2 = 
$ilDB->queryF(
 
  232            "SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
 
  236        $result_3 = 
$ilDB->queryF(
 
  237            "SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
 
  242        $cnt_1 = 
$ilDB->numRows($result_1);
 
  243        $cnt_2 = 
$ilDB->numRows($result_2);
 
  244        $cnt_3 = 
$ilDB->numRows($result_3);
 
  246        if ($cnt_1 || $cnt_2 || $cnt_3) {
 
  257    public function checkDeleteCategory($id)
 
  266            'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
 
  273                if (!is_null($unit_res)) {
 
  287        if (!is_null(
$res)) {
 
  290        $affectedRows = 
$ilDB->manipulateF(
 
  291            "DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
 
  295        if ($affectedRows > 0) {
 
  298        self::$result_buffer = 
null;
 
  309        if (self::$result_buffer == 
null) {
 
  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" 
  323                    $unit->initFormArray($row);
 
  337        if (count($this->categorizedUnits) == 0) {
 
  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",
 
  354                    $unit->initFormArray($row);
 
  355                    if (strcmp($category, $unit->getCategory()) != 0) {
 
  357                        $cat->initFormArray(array(
 
  358                            'category_id' => $row[
'category_fi'],
 
  359                            'category' => $row[
'category'],
 
  360                            'question_fi' => $row[
'question_fi'],
 
  362                        array_push($this->categorizedUnits, $cat);
 
  363                        $category = $unit->getCategory();
 
  365                    array_push($this->categorizedUnits, $unit);
 
  375        $this->units = array();
 
  376        self::$result_buffer = 
null;
 
  381        $this->units[$unit->getId()] = $unit;
 
  386        if (count($this->units) == 0) {
 
  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",
 
  412                $unit->initFormArray($row);
 
  413                array_push(
$units, $unit);
 
  425        if (count($this->units) == 0) {
 
  428        if (array_key_exists($id, $this->units)) {
 
  429            return $this->units[$id];
 
  435            if (array_key_exists($id, $this->units)) {
 
  436                return $this->units[$id];
 
  448        $categories = array();
 
  450            "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi > %s ORDER BY category",
 
  456                $value = (strcmp(
"-qpl_qst_formulaquestion_" . $row[
"category"] . 
"-", $this->lng->txt($row[
"category"])) == 0) ? $row[
"category"] : $this->lng->txt($row[
"category"]);
 
  458                if (strlen(trim($row[
"category"]))) {
 
  460                        "value" => $row[
"category_id"],
 
  462                        "qst_id" => $row[
'question_fi']
 
  464                    $categories[$row[
"category_id"]] = $cat;
 
  476        $categories = array();
 
  478            "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s  ORDER BY category",
 
  484                $value = (strcmp(
"-qpl_qst_formulaquestion_" . $row[
"category"] . 
"-", $this->lng->txt($row[
"category"])) == 0) ? $row[
"category"] : $this->lng->txt($row[
"category"]);
 
  486                if (strlen(trim($row[
"category"]))) {
 
  488                        "value" => $row[
"category_id"],
 
  490                        "qst_id" => $row[
'question_fi']
 
  492                    $categories[$row[
"category_id"]] = $cat;
 
  504    public function saveUnitOrder($unit_id, $sequence)
 
  514                        UPDATE il_qpl_qst_fq_unit 
  516                        WHERE unit_id = %s AND question_fi = %s 
  518            array(
'integer', 
'integer', 
'integer'),
 
  521        self::$result_buffer = 
null;
 
  530            "SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
 
  535            return $this->lng->txt(
"err_unit_in_variables");
 
  538            "SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
 
  543            return $this->lng->txt(
"err_unit_in_results");
 
  545        if (!is_null($category_id)) {
 
  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)
 
  553                "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
 
  554                array(
'integer', 
'integer'),
 
  559            return $this->lng->txt(
"err_unit_is_baseunit");
 
  569    public function getUnitCategoryById($id)
 
  577        $query = 
'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = ' . 
$ilDB->quote($id, 
'integer');
 
  585        $category->initFormArray($row);
 
  602            'SELECT * FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s AND category_id != %s',
 
  603            array(
'text', 
'integer', 
'integer'),
 
  611            'UPDATE il_qpl_qst_fq_ucat SET category = %s WHERE question_fi = %s AND category_id = %s',
 
  612            array(
'text', 
'integer', 
'integer'),
 
  615        self::$result_buffer = 
null;
 
  631            'SELECT category FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s',
 
  632            array(
'text', 
'integer'),
 
  633            array($category->
getCategory(), $this->getConsumerId())
 
  639        $next_id = 
$ilDB->nextId(
'il_qpl_qst_fq_ucat');
 
  641            "INSERT INTO il_qpl_qst_fq_ucat (category_id, category, question_fi) VALUES (%s, %s, %s)",
 
  642            array(
'integer', 
'text', 
'integer'),
 
  646                (
int) $this->getConsumerId()
 
  649        $category->
setId($next_id);
 
  650        self::$result_buffer = 
null;
 
  656    public function getAllUnitCategories()
 
  664        $categories = array();
 
  666            "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s OR question_fi = %s ORDER BY category",
 
  667            array(
'integer', 
'integer'),
 
  674                $categories[] = $category;
 
  684    public function deleteCategory($id)
 
  692        $res = $this->checkDeleteCategory($id);
 
  693        if (!is_null(
$res)) {
 
  694            return $this->lng->txt(
'err_category_in_use');
 
  698            'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
 
  705        $ar = 
$ilDB->manipulateF(
 
  706            'DELETE FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
 
  713        self::$result_buffer = 
null;
 
  728        $next_id = 
$ilDB->nextId(
'il_qpl_qst_fq_unit');
 
  730            'INSERT INTO il_qpl_qst_fq_unit (unit_id, unit, factor, baseunit_fi, category_fi, sequence, question_fi) VALUES (%s, %s, %s, %s, %s, %s, %s)',
 
  731            array(
'integer', 
'text', 
'float', 
'integer', 
'integer', 
'integer', 
'integer'),
 
  739                (
int) $this->getConsumerId()
 
  742        $unit->
setId($next_id);
 
  748        self::$result_buffer = 
null;
 
  763            'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE unit_id = %s',
 
  765            array($unit->
getId())
 
  769            $sequence = $row[
'sequence'];
 
  773            $ar = 
$ilDB->manipulateF(
 
  774                'UPDATE il_qpl_qst_fq_unit SET unit = %s, factor = %s, baseunit_fi = %s, category_fi = %s, sequence = %s WHERE unit_id = %s AND question_fi = %s',
 
  775                array(
'text', 
'float', 
'integer', 
'integer', 
'integer', 
'integer', 
'integer'),
 
  782        self::$result_buffer = 
null;
 
  789    public function cloneUnits($a_from_consumer_id, $a_to_consumer_id)
 
  797        $category_mapping = array();
 
  799        $res = 
$ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s", array(
'integer'), array($a_from_consumer_id));
 
  801            $new_category_id = $this->copyCategory($row[
'category_id'], $a_to_consumer_id);
 
  802            $category_mapping[$row[
'category_id']] = $new_category_id;
 
  805        foreach ($category_mapping as $old_category_id => $new_category_id) {
 
  807                'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
 
  809                array($old_category_id)
 
  815                $next_id = 
$ilDB->nextId(
'il_qpl_qst_fq_unit');
 
  817                $units[
$i][
'old_unit_id'] = $row[
'unit_id'];
 
  818                $units[
$i][
'new_unit_id'] = $next_id;
 
  821                    'il_qpl_qst_fq_unit',
 
  823                        'unit_id' => array(
'integer', $next_id),
 
  824                        'unit' => array(
'text', $row[
'unit']),
 
  825                        'factor' => array(
'float', $row[
'factor']),
 
  826                        'baseunit_fi' => array(
'integer', (
int) $row[
'baseunit_fi']),
 
  827                        'category_fi' => array(
'integer', (
int) $new_category_id),
 
  828                        'sequence' => array(
'integer', (
int) $row[
'sequence']),
 
  829                        'question_fi' => array(
'integer', (
int) $a_to_consumer_id)
 
  835            foreach (
$units as $unit) {
 
  838                    'il_qpl_qst_fq_unit',
 
  839                    array(
'baseunit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  841                        'baseunit_fi' => array(
'integer', (
int) $unit[
'old_unit_id']),
 
  842                        'question_fi' => array(
'integer', (
int) $a_to_consumer_id)
 
  849                    array(
'unit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  851                        'unit_fi' => array(
'integer', (
int) $unit[
'old_unit_id']),
 
  852                        'question_fi' => array(
'integer', (
int) $a_to_consumer_id)
 
  859                    array(
'unit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  861                        'unit_fi' => array(
'integer', (
int) $unit[
'old_unit_id']),
 
  862                        'question_fi' => array(
'integer', (
int) $a_to_consumer_id)
 
  868                    'il_qpl_qst_fq_res_unit',
 
  869                    array(
'unit_fi' => array(
'integer', (
int) $unit[
'new_unit_id'])),
 
  871                        'unit_fi' => array(
'integer', (
int) $unit[
'old_unit_id']),
 
  872                        'question_fi' => array(
'integer', (
int) $a_to_consumer_id)
 
  877        self::$result_buffer = 
null;
 
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
Class ilUnitConfigurationRepository.
loadUnitsForCategory($category)
getCategoryUnitCount($id)
checkDeleteUnit($id, $category_id=null)
setConsumerId($consumer_id)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
foreach($_POST as $key=> $value) $res