public function editDescriptionAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     if ($request->isPost()) {
         $id = $request->getPost()->id;
         $course = $this->getCourseTable()->getCourse($id);
         $form = new CourseForm();
         $form->bind($course);
         $form->setInputFilter(new CourseFilter($this->getServiceLocator()));
         //TODO: FORM IS NOT VALID
         if ($form->isValid()) {
             echo "jiu";
             die;
             $this->getCourseTable()->saveCourse($form->getData());
             $response->setContent(\Zend\Json\Json::encode(array('response' => true)));
         }
         die;
         return $response;
     } else {
         $id = $this->params()->fromRoute('id');
         $course = $this->getCourseTable()->getCourse($id);
         $form = new CourseForm();
         $form->bind($course);
         $viewmodel = new ViewModel();
         $viewmodel->setTerminal($request->isXmlHttpRequest());
         $viewmodel->setVariables(array('form' => $form, 'courseId' => $course->id, 'id' => $id));
         return $viewmodel;
     }
 }
 public function editCourseAction()
 {
     $id = $this->params()->fromRoute('id');
     $course = $this->getCourseTable()->getCourse($id);
     $currentTeacherId = $course->teacher_id;
     $allTeachers = $this->getUserTable()->getAllTeachersForSelect();
     $availableTeachers = array();
     foreach ($allTeachers as $key => $teacher) {
         $teacherCourse = $this->getCourseTable()->getCourseByTeacherId($key);
         if (empty($teacherCourse) || $currentTeacherId == $key) {
             $availableTeachers[$key] = $teacher;
         }
     }
     $form = new CourseForm();
     $form->bind($course);
     $form->get('teacher_id')->setValueOptions($availableTeachers);
     $form->get('submit')->setAttribute('value', 'Muuda');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter(new CourseFilter($this->getServiceLocator()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getCourseTable()->saveCourse($form->getData());
         }
     }
     $viewmodel = new ViewModel();
     $sidebarView = new ViewModel();
     $sidebarView->setTemplate('admin/sidebar');
     $sidebarView->setVariables(array('course' => $this->getCourseTable()->getCourse($this->params()->fromRoute('id'))));
     $viewmodel->addChild($sidebarView, 'sidebar');
     $viewmodel->setVariables(array('id' => $id, 'form' => $form, 'course' => $this->getCourseTable()->getCourse($this->params()->fromRoute('id'))));
     return $viewmodel;
 }