/** * @return int * @param Category $o_category * @desc Save the supplied Category to the database, and return the id */ function Save($o_category) { # check parameters if (!$o_category instanceof Category) { die('Unable to save category'); } # build query # if no id, it's a new category; otherwise update the category if ($o_category->GetId()) { $s_sql = 'UPDATE ' . $this->GetSettings()->GetTable('Category') . ' SET ' . 'parent = ' . Sql::ProtectNumeric($o_category->GetParentId(), true) . ', ' . "name = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetName()) . ", " . "code = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetUrl()) . ", " . 'sort_override = ' . Sql::ProtectNumeric($o_category->GetSortOverride()) . ', ' . 'date_changed = ' . gmdate('U') . ' ' . 'WHERE id = ' . Sql::ProtectNumeric($o_category->GetId()); # run query $this->GetDataConnection()->query($s_sql); } else { $s_sql = 'INSERT INTO ' . $this->GetSettings()->GetTable('Category') . ' SET ' . 'parent = ' . Sql::ProtectNumeric($o_category->GetParentId(), true) . ', ' . "name = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetName()) . ", " . "code = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetUrl()) . ", " . 'sort_override = ' . Sql::ProtectNumeric($o_category->GetSortOverride()) . ', ' . 'date_added = ' . gmdate('U') . ', ' . 'date_changed = ' . gmdate('U'); # run query $o_result = $this->GetDataConnection()->query($s_sql); # get autonumber $o_category->SetId($this->GetDataConnection()->insertID()); } return $o_category->GetId(); }