Ejemplo n.º 1
0
 public function __construct($name = 'vacationdays-form')
 {
     parent::__construct($name);
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'form-horizontal');
     $this->setAttribute('id', 'vacationdays-form');
     $this->add(array('name' => 'interval', 'attributes' => array('type' => 'text', 'class' => 'form-control pull-right', 'id' => 'interval')));
     $this->add(array('name' => 'from', 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'from')));
     $this->add(array('name' => 'to', 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'to')));
     $this->add(array('name' => 'total_number', 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'total_number', 'max' => 365, 'min' => 0, 'maxlength' => 5)));
     $this->add(array('name' => 'vacation_type', 'options' => array('value_options' => Objects::getVacationType()), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'vacation_type', 'class' => 'form-control')));
     $this->add(array('name' => 'comment', 'attributes' => array('type' => 'textarea', 'class' => 'form-control', 'rows' => '4', 'id' => 'comment', 'maxlength' => 255)));
     $this->add(array('name' => 'save_button', 'options' => array('label' => 'Submit Request'), 'attributes' => array('type' => 'button', 'class' => 'btn btn-primary state', 'data-loading-text' => 'Saving...', 'id' => 'save_button', 'value' => 'Save')));
 }
    public function getVacationRequestsAction()
    {
        /**
         * @var TimeOffRequestsService $timeOffRequestsWidgetService
         * @var BackofficeAuthenticationService $authenticationService
         */
        $timeOffRequestsWidgetService = $this->getServiceLocator()->get('service_universal_dashboard_widget_time_off_requests');
        $authenticationService = $this->getServiceLocator()->get('library_backoffice_auth');
        $vacationDao = $this->getServiceLocator()->get('dao_user_vacation_days');
        $loggedInUserID = $authenticationService->getIdentity()->id;
        $dataSet = $timeOffRequestsWidgetService->getTimeOffRequests($loggedInUserID);
        $preparedData = [];
        if ($dataSet && count($dataSet)) {
            foreach ($dataSet as $row) {
                $remainColumn = $row->getVacation_days();
                $purposeColumn = '<span class="glyphicon glyphicon-comment" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="' . $row->getComment() . '"></span>';
                $actionsColumn = '
					<a href="javascript:void(0)" class="btn btn-xs btn-success" onclick="vacationRequest(' . $row->getId() . ',1)" id="vac_accept_' . $row->getId() . '">Approve</a>
					<a href="javascript:void(0)" class="btn btn-xs btn-danger" onclick="vacationRequest(' . $row->getId() . ',3)" id="vac_reject_' . $row->getId() . '">Reject</a>
				';
                if ($row->getType() == VacationService::VACATION_TYPE_SICK) {
                    $takenSickDays = 0;
                    $sickDays = $vacationDao->getSickDays($row->getUser_id());
                    if ($sickDays) {
                        foreach ($sickDays as $sickDay) {
                            $takenSickDays += abs($sickDay['total_number']);
                        }
                    }
                    if ($row->getSickDays() != -1) {
                        $remainColumn = $row->getSickDays() - $takenSickDays;
                    } else {
                        $remainColumn = '';
                    }
                }
                array_push($preparedData, ['<a href="/profile/index/' . $row->getUser_id() . '" target="_blank">' . $row->getFirstName() . ' ' . $row->getLastName() . '</a>', isset(Objects::getVacationType()[$row->getType()]) ? Objects::getVacationType()[$row->getType()] : 'None', date(Constants::GLOBAL_DATE_FORMAT, strtotime($row->getFrom())) . ' - ' . date(Constants::GLOBAL_DATE_FORMAT, strtotime($row->getTo())), $row->getTotal_number(), round($remainColumn, 2), $purposeColumn, $actionsColumn]);
            }
            return new JsonModel(["aaData" => $preparedData]);
        } else {
            return new JsonModel(["aaData" => []]);
        }
    }