public function saveEventAction(){
        $translator = $this->getServiceLocator()->get('translator');
        
        $request = $this->getRequest();
        // Default Values
        $status  = 0;
        $textMessage = '';
        $errors  = array();
        $textTitle = '';
         
        $responseData = array();
         
        $melisMelisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
         
        $appConfigForm = $melisMelisCoreConfig->getFormMergedAndOrdered('meliscalendar/forms/melicalendar_event_form','melicalendar_event_form');
         
        $factory = new \Zend\Form\Factory();
        $formElements = $this->serviceLocator->get('FormElementManager');
        $factory->setFormElementManager($formElements);
        $propertyForm = $factory->createForm($appConfigForm);
        $melisTool = $this->getServiceLocator()->get('MelisCoreTool');
        if($request->isPost()) {
             
            $postValues = get_object_vars($request->getPost());
            $postValues = $melisTool->sanitizePost($postValues);
            $propertyForm->setData($postValues);
            
            
            if (empty($postValues['cal_id']))
            {
                $logTypeCode = 'CALENDAR_EVENT_ADD';
            }
            else
            {
                $logTypeCode = 'CALENDAR_EVENT_UPDATE';
            }
             
            if($propertyForm->isValid()) {
                $calendarService = $this->getServiceLocator()->get('MelisCalendarService');
                $responseData = $calendarService->addCalendarEvent($postValues);
                
                if (!empty($responseData)){
                    $textMessage = 'tr_melistoolcalendar_save_event_success';
                    $status = 1;
                }
            }else{
                $errors = $propertyForm->getMessages();
                $textMessage = 'tr_melistoolcalendar_form_event_error_msg';
            }
             
            $appConfigForm = $appConfigForm['elements'];
             
            foreach ($errors as $keyError => $valueError)
            {
                foreach ($appConfigForm as $keyForm => $valueForm)
                {
                    if ($valueForm['spec']['name'] == $keyError &&
                        !empty($valueForm['spec']['options']['label']))
                        $errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
                }
            }
        }
         
        $response = array(
            'success' => $status,
            'textTitle' => 'tr_melistoolcalendar_save_event_title',
            'textMessage' => $textMessage,
            'errors' => $errors,
            'event' => $responseData
        );
        
        $calId = null;
        if (!empty($responseData['id']))
        {
            $calId = $responseData['id'];
        }
         
        if ($status){
            $this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => $logTypeCode, 'itemId' => $calId)));
        }
        
        return new JsonModel($response);
    }
public function saveEventAction(){
        $translator = $this->getServiceLocator()->get('translator');
        
        $request = $this->getRequest();
        // Default Values
        $status  = 0;
        $textMessage = '';
        $errors  = array();
        $textTitle = '';
         
        $responseData = array();
         
        $melisMelisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
         
        $appConfigForm = $melisMelisCoreConfig->getFormMergedAndOrdered('meliscalendar/forms/melicalendar_event_form','melicalendar_event_form');
         
        $factory = new \Zend\Form\Factory();
        $formElements = $this->serviceLocator->get('FormElementManager');
        $factory->setFormElementManager($formElements);
        $propertyForm = $factory->createForm($appConfigForm);
        $melisTool = $this->getServiceLocator()->get('MelisCoreTool');
        if($request->isPost()) {
             
            $postValues = get_object_vars($request->getPost());
            $postValues = $melisTool->sanitizePost($postValues);
            $propertyForm->setData($postValues);
            
            
            if (empty($postValues['cal_id']))
            {
                $logTypeCode = 'CALENDAR_EVENT_ADD';
            }
            else
            {
                $logTypeCode = 'CALENDAR_EVENT_UPDATE';
            }
             
            if($propertyForm->isValid()) {
                $calendarService = $this->getServiceLocator()->get('MelisCalendarService');
                $responseData = $calendarService->addCalendarEvent($postValues);
                
                if (!empty($responseData)){
                    $textMessage = 'tr_melistoolcalendar_save_event_success';
                    $status = 1;
                }
            }else{
                $errors = $propertyForm->getMessages();
                $textMessage = 'tr_melistoolcalendar_form_event_error_msg';
            }
             
            $appConfigForm = $appConfigForm['elements'];
             
            foreach ($errors as $keyError => $valueError)
            {
                foreach ($appConfigForm as $keyForm => $valueForm)
                {
                    if ($valueForm['spec']['name'] == $keyError &&
                        !empty($valueForm['spec']['options']['label']))
                        $errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
                }
            }
        }
         
        $response = array(
            'success' => $status,
            'textTitle' => 'tr_melistoolcalendar_save_event_title',
            'textMessage' => $textMessage,
            'errors' => $errors,
            'event' => $responseData
        );
        
        $calId = null;
        if (!empty($responseData['id']))
        {
            $calId = $responseData['id'];
        }
         
        if ($status){
            $this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => $logTypeCode, 'itemId' => $calId)));
        }
        
        return new JsonModel($response);
    }
public function saveEventAction ( ) { $ translator = $ this -> getServiceLocator ( ) -> get ( 'translator' ) ; $ request = $ this -> getRequest ( ) ; // Default Values $ status = 0 ; $ textMessage = '' ; $ errors = array ( ) ; $ textTitle = '' ; $ responseData = array ( ) ; $ melisMelisCoreConfig = $ this -> serviceLocator -> get ( 'MelisCoreConfig' ) ; $ appConfigForm = $ melisMelisCoreConfig -> getFormMergedAndOrdered ( 'meliscalendar/forms/melicalendar_event_form' , 'melicalendar_event_form' ) ; $ factory = new \ Zend \ Form \ Factory ( ) ; $ formElements = $ this -> serviceLocator -> get ( 'FormElementManager' ) ; $ factory -> setFormElementManager ( $ formElements ) ; $ propertyForm = $ factory -> createForm ( $ appConfigForm ) ; $ melisTool = $ this -> getServiceLocator ( ) -> get ( 'MelisCoreTool' ) ; if ( $ request -> isPost ( ) ) { $ postValues = get_object_vars ( $ request -> getPost ( ) ) ; $ postValues = $ melisTool -> sanitizePost ( $ postValues ) ; $ propertyForm -> setData ( $ postValues ) ; if ( empty ( $ postValues [ 'cal_id' ] ) ) { $ logTypeCode = 'CALENDAR_EVENT_ADD' ; } else { $ logTypeCode = 'CALENDAR_EVENT_UPDATE' ; } if ( $ propertyForm -> isValid ( ) ) { $ calendarService = $ this -> getServiceLocator ( ) -> get ( 'MelisCalendarService' ) ; $ responseData = $ calendarService -> addCalendarEvent ( $ postValues ) ; if ( ! empty ( $ responseData ) ) { $ textMessage = 'tr_melistoolcalendar_save_event_success' ; $ status = 1 ; } } else { $ errors = $ propertyForm -> getMessages ( ) ; $ textMessage = 'tr_melistoolcalendar_form_event_error_msg' ; } $ appConfigForm = $ appConfigForm [ 'elements' ] ; foreach ( $ errors as $ keyError => $ valueError ) { foreach ( $ appConfigForm as $ keyForm => $ valueForm ) { if ( $ valueForm [ 'spec' ] [ 'name' ] == $ keyError && ! empty ( $ valueForm [ 'spec' ] [ 'options' ] [ 'label' ] ) ) $ errors [ $ keyError ] [ 'label' ] = $ valueForm [ 'spec' ] [ 'options' ] [ 'label' ] ; } } } $ response = array ( 'success' => $ status , 'textTitle' => 'tr_melistoolcalendar_save_event_title' , 'textMessage' => $ textMessage , 'errors' => $ errors , 'event' => $ responseData ) ; $ calId = null ; if ( ! empty ( $ responseData [ 'id' ] ) ) { $ calId = $ responseData [ 'id' ] ; } if ( $ status ) { $ this -> getEventManager ( ) -> trigger ( 'meliscalendar_save_event_end' , $ this , array_merge ( $ response , array ( 'typeCode' => $ logTypeCode , 'itemId' => $ calId ) ) ) ; } return new JsonModel ( $ response ) ; }
This action will save an event to the calendar

@return \Zend\View\Model\JsonModel
This action will save an event to the calendar