コード例 #1
0
ファイル: GoalController.php プロジェクト: freesaga/getit
 public function createAction()
 {
     $this->initialize();
     //read form submition
     if ($this->request->isPost()) {
         //get session info
         $auth = $this->session->get('auth');
         $userID = $auth['userID'];
         //get other user information from db
         $user = Users::findFirstByUserID($userID);
         if ($user) {
             //user found
             //get goal info
             $g_title = $this->request->getPost('g_title');
             $g_subject = $this->request->getPost('g_subject');
             $g_description = $this->request->getPost('g_description');
             //create new goal
             $goal = new Goals();
             $goal->seekerID = $userID;
             $goal->isComplete = "0";
             $goal->title = $g_title;
             $goal->description = $g_description;
             $goal->subject = $g_subject;
             if ($goal->create()) {
                 $numMilestones = $this->request->getPost('numMilestones');
                 $this->flashSession->success("Goal created with " . $numMilestones);
                 for ($i = 1; $i <= $numMilestones; $i++) {
                     //get info for current milestone
                     $ms_title_key = "ms" . "{$i}" . "_title";
                     $ms_title = $this->request->getPost($ms_title_key);
                     $ms_description = $this->request->getPost("ms" . "{$i}" . "_description");
                     $ms = new Milestones();
                     $ms->title = $ms_title;
                     $ms->description = $ms_description;
                     $ms->goalID = $goal->goalID;
                     $ms->number = $i;
                     $ms->isComplete = 0;
                     if ($ms->create()) {
                         $this->flashSession->success("ms {$i} ms created");
                     } else {
                         foreach ($ms->getMessages() as $message) {
                             $this->flashSession->error("ms {$i} {$message} {$ms_title_key} [ {$ms_title} ]");
                         }
                         $this->response->redirect("index");
                         $this->view->disable();
                     }
                 }
             } else {
                 foreach ($goal->getMessages() as $message) {
                     $this->flashSession->error($message);
                 }
                 $this->response->redirect("index");
                 $this->view->disable();
             }
             $this->flashSession->success("Created");
             $this->response->redirect("index");
             $this->view->disable();
         } else {
             //error, go to login
             $this->flashSession->error("Error: Unable to access user information");
             $this->response->redirect("index");
             $this->view->disable();
         }
     }
 }