/** * Дублировать сыновей * * \param [in] value количество раз для дублирования сыновей */ public function duplicate_child($value) { $toDup = array(); for ($i = 0; $i < count($this->childrens); $i++) { if (get_class($this->childrens[$i]) == 'qtype_correctwriting_operand') { if ($this->childrens[$i]->number === null || is_double($this->childrens[$i]->number)) { array_push($toDup, $this->childrens[$i]); } } if (get_class($this->childrens[$i]) != 'qtype_correctwriting_operand') { array_push($toDup, $this->childrens[$i]); } } // создать сын для добавления $childToAdd; if (count($toDup) == 1) { $childToAdd = $toDup[0]; } else { $childToAdd = new qtype_correctwriting_multi_operator(); $childToAdd->childrens = $toDup; $childToAdd->calculate_tree_in_string(); } // преобразовать в qtype_correctwriting_plus_operator $tmp = new qtype_correctwriting_plus_operator(); for ($i = 0; $i < abs($value); $i++) { array_push($tmp->childrens, clone $childToAdd); } $tmp->calculate_tree_in_string(); // добавление знак if ($value < 0) { $t = new qtype_correctwriting_unary_minus_operator(); $t->children = $tmp; $t->calculate_tree_in_string(); $this->ptonewchild = $t; } else { $this->ptonewchild = $tmp; } }
public function convert($parent) { $this->convert_each_childrens(); $tmp = new qtype_correctwriting_plus_operator(); array_push($tmp->childrens, clone $this->left); array_push($tmp->childrens, $this->right); $tmp->calculate_tree_in_string(); $newass = new qtype_correctwriting_assign_operator(); $newass->left = $this->left; $newass->right = $tmp; $newass->calculate_tree_in_string(); $this->ptonewchild = $newass; }