/** Update an existing category. Taxes must be set, if they have no id * they are added to the category, otherwise updated (no way to delete). */ static function updateCat($cat) { if ($cat->getId() == null || count($cat->taxes) == 0) { return false; } $pdo = PDOBuilder::getPDO(); $newTransaction = !$pdo->inTransaction(); if ($newTransaction) { $pdo->beginTransaction(); } $stmt = $pdo->prepare('UPDATE TAXCATEGORIES SET NAME = :name ' . 'WHERE ID = :id'); if (!$stmt->execute(array(':name' => $cat->label, ':id' => $cat->id))) { if ($newTransaction) { $pdo->rollback(); } return false; } foreach ($cat->taxes as $tax) { if ($tax->id !== null) { if (TaxesService::updateTax($tax) === false) { if ($newTransaction) { $pdo->rollback(); } return false; } } else { $taxId = TaxesService::createTax($tax) === false; if ($taxId === false) { if ($newTransaction) { $pdo->rollback(); } return false; } $tax->id = $taxId; } } if ($newTransaction) { $pdo->commit(); } return $id; }