Ejemplo n.º 1
0
 protected function create()
 {
     if (isset($_POST["name"])) {
         $pack = PackQuery::create()->filterByOwner($this->data["loggedUser"])->filterByName($_POST["name"])->findOne();
         if ($pack) {
             $this->sendFlashMessage("Your pack has not been created. You already have pack with this name.", "error");
             $this->redirect("/pack/new");
         }
         $pack = new Pack();
         $pack->setName($_POST["name"]);
         $pack->setOwner($this->data["loggedUser"]);
         $pack->setPrivate(isset($_POST["private"]));
         $pack->setDescription(isset($_POST["description"]) ? $_POST["description"] : null);
         if ($pack->save() <= 0) {
             $failures = $pack->getValidationFailures();
             if (count($failures) > 0) {
                 foreach ($failures as $failure) {
                     $this->sendFlashMessage("Your pack has not been created. " . $failure->getMessage(), "error");
                 }
                 $this->redirect($this->data["referersURI"]);
             }
         }
         $this->sendFlashMessage("You have successfuly created new pack.", "success");
         $this->redirect("/pack/" . $pack->getId());
     } else {
         setHTTPStatusCode("400");
     }
 }
Ejemplo n.º 2
0
 /**
  * @param ChildPack $pack The ChildPack object to add.
  */
 protected function doAddPack(ChildPack $pack)
 {
     $this->collPacks[] = $pack;
     $pack->setOwner($this);
 }