/** * The save action of the Team. * @return bool The state if the Team was successfully saved. * @since 0.0.1-dev */ public function save() { //get the session. $this->needSession(); //get the information from post. $team = new Team(); $team->loadFromPOST('team_'); //check if the name is valid. if ((new IsValidName())->isSatisfiedBy($team) === false) { $this->jsonOutput('The name is not valid!', 'team_name', LogLevel::ERROR); return false; } //check if the tag is valid. if ((new IsValidTag())->isSatisfiedBy($team) === false) { $this->jsonOutput('The tag is not valid!', 'team_tag', LogLevel::ERROR); return false; } //check if the website is valid. if ((new IsValidWebsite())->isSatisfiedBy($team) === false) { $this->jsonOutput('The website is not valid!', 'team_website', LogLevel::ERROR); return false; } //check if the Team already exists. if ((new IsUnique(TeamRepository::build()))->isSatisfiedBy($team) === false) { $this->jsonOutput('The Team already exists!', '', LogLevel::ERROR); return false; } //save the Team on the database. if (TeamMapper::build()->save($team)) { $this->jsonOutput('The Team was saved successfully!', '', LogLevel::INFO, URL . 'team'); return true; } else { $this->jsonOutput('The Team could not be saved!', '', LogLevel::ERROR); return false; } }
/** * Method to build a new object of TeamRepository. * @return TeamRepository The created object of TeamRepository. * @since 1.0.0 * @uses TeamMapper::build() to get the connection to the database. */ public static function build() { return new self(TeamMapper::build()); }