/** * Update ths class in database * @throws Claro_Class_Exception if class does not exists (i.e. no id given) * @throws Database_Connection_Exception in case of database error */ public function update() { if (!$this->id) { throw new Exception("Cannot update class information : no id given"); } $fields = array(); if ($this->name_changed) { $fields[] = "name = " . $this->database->quote($this->name); } if ($this->parentId_changed) { if ($this->parentId) { $parentClass = new self($this->database); $parentClass->load($this->parentId); $this->level = $parentClass->getLevel() + 1; } else { $this->level = 1; } $fields[] = "class_parent_id = " . $this->database->escape($this->parentId); $fields[] = "class_level = " . $this->database->escape($this->level); } if (count($fields) == 0) { return $this; } $tbl = claro_sql_get_main_tbl(); $this->database->exec("\n UPDATE \n `" . $tbl['class'] . "`\n SET\n " . implode(",\n", $fields) . "\n WHERE\n id = " . $this->database->escape($this->id) . "\n "); return $this; }