tactics = $tactics; } /** * creates a new empty tactic, with given name * @param string $name * @param int $ownerId * @param CourtType $type * @return TacticInfo */ public function makeNew(string $name, int $ownerId, CourtType $type): TacticInfo { $id = $this->tactics->insert($name, $ownerId, $type); return $this->tactics->get($id); } /** * creates a new empty tactic, with a default name * @param int $ownerId * @param CourtType $type * @return TacticInfo|null */ public function makeNewDefault(int $ownerId, CourtType $type): ?TacticInfo { return $this->makeNew(self::TACTIC_DEFAULT_NAME, $ownerId, $type); } /** * Tries to retrieve information about a tactic * @param int $id tactic identifier * @return TacticInfo|null or null if the identifier did not match a tactic */ public function get(int $id): ?TacticInfo { return $this->tactics->get($id); } /** * Return the nb last tactics created * * @param integer $nb * @return array> */ /** * Return the nb last tactics */ public function getLast(int $nb, int $ownerId): array { return $this->tactics->getLast($nb, $ownerId); } /** * Get all the tactics of the owner * * @param integer $ownerId * @return array|null */ public function getAll(int $ownerId): ?array { return $this->tactics->getAll($ownerId); } /** * Update the name of a tactic * @param int $id the tactic identifier * @param string $name the new name to set * @return ValidationFail[] failures, if any */ public function updateName(int $id, string $name, int $authId): array { $tactic = $this->tactics->get($id); if ($tactic == null) { return [ValidationFail::notFound("Could not find tactic")]; } if ($tactic->getOwnerId() != $authId) { return [ValidationFail::unauthorized()]; } if (!$this->tactics->updateName($id, $name)) { return [ValidationFail::error("Could not update name")]; } return []; } public function updateContent(int $id, string $json): ?ValidationFail { if (!$this->tactics->updateContent($id, $json)) { return ValidationFail::error("Could not update content"); } return null; } }