/** * The save action of the Clan. * @return bool The state if the Clan could be successfully saved. * @since 0.0.1-dev */ public function save() { //get the session. $this->needSession(); //get the information from POST. $clan = new Clan(); $clan->loadFromPOST('clan_'); //get the DataMapper. $clanMapper = ClanMapper::build(); //check if the name is valid. if ((new IsValidName())->isSatisfiedBy($clan) === false) { $this->jsonOutput('The name is not valid!', 'clan_name', LogLevel::ERROR); return false; } //check if the tag is valid. if ((new IsValidTag())->isSatisfiedBy($clan) === false) { $this->jsonOutput('The tag is not valid!', 'clan_tag', LogLevel::ERROR); return false; } //check if the website is valid. if ((new IsValidWebsite())->isSatisfiedBy($clan) === false) { $this->jsonOutput('The website is not valid!', 'clan_website', LogLevel::ERROR); return false; } //check if the Clan already exists. if ((new IsUnique(ClanRepository::build()))->isSatisfiedBy($clan) === false) { $this->jsonOutput('The Clan already exists!', '', LogLevel::ERROR); return false; } //save the Clan on the database. if ($clanMapper->save($clan)) { $this->jsonOutput('The Clan was saved successfully!', '', LogLevel::INFO, URL . 'clan'); return true; } else { $this->jsonOutput('The Clan could not be saved!', '', LogLevel::ERROR); return false; } }
/** * Method to build a new object of ClanRepository. * @return ClanRepository The created object of ClanRepository. * @since 1.0.0 * @uses ClanMapper::build() to get the connetion to the database. */ public static function build() { return new self(ClanMapper::build()); }