public function adjustperiodAction()
 {
     $objfacultyadjustment = new Acad_Model_DbTable_FacultyAdjustment();
     $request = $this->getRequest();
     $period_id = $request->getParam('period_id');
     $staff_id = $request->getParam('staff_id');
     $target_subject = $request->getParam('target_subject');
     $target_staff_id = $request->getParam('target_staff_id');
     $adjustment_dateobj = new Zend_Date($request->getParam('adjustment_date'), 'dd-MM-YYYY');
     $adjustment_date = $adjustment_dateobj->toString('YYYY-MM-dd');
     $resultSet = Acad_Model_DbTable_TimeTable::getPeriodIdTimetable($period_id, $adjustment_date, $staff_id);
     $insertData = NULL;
     $cnt = 0;
     foreach ($resultSet as $key => $value) {
         $adj_resultSet = Acad_Model_DbTable_TimeTable::getSubjectTimetableids($value['department_id'], $value['degree_id'], $value['semester_id'], $target_subject, $value['subject_mode_id'], $value['group_id']);
         if (count($adj_resultSet) > 0) {
             $insertData[$cnt++] = array('source_timetable_id' => $value['timetable_id'], 'start_date' => $adjustment_date, 'source_staff_id' => $staff_id, 'target_timetable_id' => $adj_resultSet[0], 'target_staff_id' => $target_staff_id);
         } else {
             $this->getResponse()->setHttpResponseCode(400);
             echo 'Timetable Entry does not exists for ' . implode(',', array($target_subject, $value['subject_mode_id'], $value['group_id']));
             return;
         }
     }
     $result = $objfacultyadjustment->adjustperiod($insertData);
     if ($result) {
         echo "Period successfully adjusted ";
     } else {
         $this->getResponse()->setHttpResponseCode(400);
         echo 'Error occured while adjustment';
     }
 }
 /**
  * @return json response
  */
 public function fillperiodgridAction()
 {
     $request = $this->getRequest();
     $period_dateobj = null;
     $weekday_number = null;
     //Getting Request Parameters
     $reqDate = $request->getParam('period_date');
     if ($reqDate) {
         $period_dateobj = new Zend_Date($reqDate);
         $weekday_number = $period_dateobj->toString('e');
     } else {
         $period_dateobj = new Zend_Date();
     }
     $staff_id = $request->getParam('staff_id');
     if (!$staff_id) {
         if (Zend_Auth::getInstance()->hasIdentity()) {
             $authInfo = Zend_Auth::getInstance()->getStorage()->read();
             $staff_id = $authInfo['identity'];
         } else {
             throw new Zend_Exception('You need to login first.', Zend_Log::ERR);
         }
     }
     $period_date = $period_dateobj->get(Zend_Date::ISO_8601);
     if (isset($staff_id)) {
         $dayPeriods = Acad_Model_DbTable_TimeTable::getFacultyDayPeriods($staff_id, $period_date, $weekday_number);
         if (isset($period_date) and isset($weekday_number)) {
             $adjustedPeriods = Acad_Model_DbTable_FacultyAdjustment::getAdjusted($staff_id, $period_date);
             foreach ($dayPeriods as $key => $value) {
                 $dayPeriods[$key]['adjusted'] = 0;
                 $dayPeriods[$key]['nonattendance'] = 0;
                 foreach ($adjustedPeriods as $akey => $avalue) {
                     if ($value['timetable_id'] == $avalue['source_timetable_id']) {
                         $dayPeriods[$key]['adjusted'] = 1;
                     }
                 }
                 $noattendance = Acad_Model_DbTable_NoAttendanceDay::isnoattendanceday($period_date, $dayPeriods[$key]['department_id'], $dayPeriods[$key]['degree_id'], $dayPeriods[$key]['semester_id']);
                 if ($noattendance) {
                     $dayPeriods[$key]['nonattendance'] = 1;
                 }
             }
         }
         $response = new stdClass();
         $response->page = 1;
         $response->total = 1;
         $response->records = count($dayPeriods);
         foreach ($dayPeriods as $key => $period) {
             $response->rows[$key]['id'] = $period['timetable_id'];
             $response->rows[$key]['cell'] = $period;
         }
         echo $this->_helper->json($response, false);
     } else {
         throw new Zend_Exception('Unidentified access', Zend_Log::ALERT);
     }
 }