Example #1
0
 public function addKillAction()
 {
     $form = new \Application\Form\AddKillForm(null, ['em' => $this->getServiceLocator()->get('doctrine_em')]);
     $form->setHydrator(new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($this->getServiceLocator()->get('doctrine_em')));
     $form->bind(new \DB\Entity\Kill());
     $prg = $this->prg($this->url()->fromRoute(null, [], true), true);
     if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
         // returned a response to redirect us
         return $prg;
     } elseif ($prg === false) {
         // this wasn't a POST request, but there were no params in the flash messenger
         // probably this is the first time the form was loaded
         return array('form' => $form);
     }
     $form->setData($prg);
     if (!$form->isValid()) {
         return array('form' => $form);
     }
     $mapper = $this->getServiceLocator()->get('DB\\Mapper\\Kill');
     $kill = $form->getData();
     $npc = $kill->getNPC();
     $mapper->cleanNPC($npc);
     $npc->setKill($kill);
     $spawnTime = clone $kill->getCrDate();
     $spawnTime->add(new \DateInterval("PT" . $npc->getSpawnInterval() . "M"));
     $kill->setSpawnTime($spawnTime);
     $kill->setSpawnInterval($npc->getSpawnWindow());
     $mapper->insert($kill);
     // Add to Kill Log
     $killLog = new \DB\Entity\KillLog();
     $killLog->setCrDate($kill->getCrDate());
     $killLog->setNpc($npc);
     $mapper->insert($killLog);
     return $this->redirect()->toRoute("home");
 }
Example #2
0
 public function addkillAction()
 {
     $npc = $this->params()->fromPost('npc');
     $killtime = $this->params()->fromPost("killtime");
     if ($npc && $killtime) {
         $date = date_create_from_format("D M d H:i:s Y", $killtime);
         $npcName = rtrim($npc, "'\r");
         $npcMapper = $this->getServiceLocator()->get("DB\\Mapper\\NPC");
         $killMapper = $this->getServiceLocator()->get("DB\\Mapper\\Kill");
         $npc = $npcMapper->findByName($npcName);
         if ($npc) {
             if ($npc->getKill() && $npc->getKill()->getCrDate() >= $date) {
                 return new JsonModel(['statusMessage' => sprintf("Old Kill from NPC '%s'", $npcName), 'statusCode' => 1]);
             }
             $killMapper->cleanNPC($npc);
             $kill = new \DB\Entity\Kill();
             $kill->setCrDate($date);
             $spawnTime = clone $date;
             $spawnTime->add(new \DateInterval("PT" . $npc->getSpawnInterval() . "M"));
             $kill->setSpawnTime($spawnTime);
             $kill->setNpc($npc);
             $kill->setSpawnInterval($npc->getSpawnWindow());
             $npc->setKill($kill);
             $npcMapper->update($kill);
             // Add to Kill Log
             $killLog = new \DB\Entity\KillLog();
             $killLog->setCrDate($date);
             $killLog->setNpc($npc);
             $npcMapper->insert($killLog);
             return new JsonModel(['statusMessage' => sprintf("Kill of '%s' successful added", $npcName), 'statusCode' => 0]);
         }
         return new JsonModel(['statusMessage' => sprintf("NPC with name '%s' not found", $npcName), 'statusCode' => 2]);
     }
     return new JsonModel(['statusMessage' => 'Error', 'statusCode' => 3]);
 }