Пример #1
0
 public function setConfig($config)
 {
     $this->config['SchoolClassName'] = $config['className'];
     $this->config['SchoolClassId'] = $config['schoolClasses'];
     foreach ($config['attendanceType'] as $attType) {
         $this->config['AttendanceTypes'][$attType] = AttendanceType::getAttendanceTypeName($attType);
     }
     foreach ($config['dates'] as $value) {
         $dt = new DateTime($value['attendanceDate']);
         $this->config['Dates'][] = 'D-' . $dt->format('d/m/Y');
     }
 }
 /**
  * @todo Criar os métodos setEnrollment, setDate e setAllowanceType
  * @return JsonModel
  */
 public function saveAllowanceAction()
 {
     $this->layout('empty/layout');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $message = "";
         $data = $request->getPost();
         $dbal = $this->getDbalConnection();
         foreach ($data['allowances'] as $all) {
             $date = new \DateTime($all['date']);
             try {
                 AttendanceRepository::insertNewAttendance($dbal, $all['enrollment'], $all['allowanceType'], $date);
                 $message .= "<br>Aluno " . $all['enrollment'] . " recebeu o " . AttendanceType::getAttendanceTypeName($all['allowanceType']) . " na data " . $date->format('d/m/Y');
             } catch (\Exception $ex) {
                 if ($ex instanceof UniqueConstraintViolationException) {
                     $message .= "<br>Aluno " . $all['enrollment'] . " já possui o " . AttendanceType::getAttendanceTypeName($all['allowanceType']) . " na data " . $date->format('d/m/Y');
                     continue;
                 }
                 $message = $ex->getMessage();
                 break;
             }
         }
         return new JsonModel(['message' => $message]);
     }
     return new JsonModel(['message' => 'Esta url só pode ser acessada via post']);
 }