public function editAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam('id');
     if ($id !== NULL) {
         $form = new Application_Form_Goal();
         $goalMapper = new Application_Model_GoalMapper();
         $auth = Zend_Auth::getInstance();
         $identity = $auth->getIdentity();
         $goal = new Application_Model_Goal();
         $goalMapper->find($id, $goal);
         $data = array('goal' => $goal->getGoal(), 'notes' => $goal->getNotes(), 'goal_date' => date_format(new DateTime($goal->getGoalDate()), 'Y-m-d'), 'done' => $goal->getDone());
         $form->populate($data);
         if ($request->isPost()) {
             if ($form->isValid($request->getPost())) {
                 $goalMapper = new Application_Model_GoalMapper();
                 $goal = new Application_Model_Goal($form->getValues());
                 $auth = Zend_Auth::getInstance();
                 $identity = $auth->getIdentity();
                 $goal->setId($id);
                 $goal->setUserId($identity->id);
                 $goalMapper->save($goal);
                 $goalNamespace = new Zend_Session_Namespace('goal');
                 $data = array('id' => $goal->getId(), 'goal' => $goal->getGoal(), 'notes' => $goal->getNotes(), 'goal_date' => $goal->getGoalDate(), 'done' => $goal->getDone(), 'user_id' => $goal->getUserId());
                 $goalNamespace->data = $data;
                 $this->_redirect('/goal/view/');
             }
         }
         $this->view->form = $form;
     } else {
         $this->_redirect('/dashboard');
     }
 }
 public function save(Application_Model_Goal $goal)
 {
     $data = array('id' => $goal->getId(), 'goal' => $goal->getGoal(), 'notes' => $goal->getNotes(), 'goal_date' => $goal->getGoalDate(), 'done' => $goal->getDone(), 'user_id' => $goal->getUserId(), 'created' => $goal->getCreated());
     if (null === ($id = $goal->getId())) {
         unset($data['id']);
         return $this->getDbTable()->insert($data);
     } else {
         $this->getDbTable()->update($data, array('id = ?' => $id));
     }
 }