Beispiel #1
0
 /**
  * @return JsonModel
  */
 public function indexAction()
 {
     $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
     if (version_compare(PHP_VERSION, self::PHP_VERSION_MIN, '<') === true) {
         $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
     }
     $data = ['responseType' => $responseType, 'data' => ['required' => self::PHP_VERSION_MIN, 'current' => PHP_VERSION]];
     return $this->jsonModel->setVariables($data);
 }
Beispiel #2
0
 /**
  * @return JsonModel
  */
 public function indexAction()
 {
     $params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
     try {
         $db = new DatabaseCheck($this->prepareDbConfig($params));
         return $this->jsonModel->setVariables(['success' => $db->checkConnection()]);
     } catch (\Exception $e) {
         return $this->jsonModel->setVariables(['success' => false]);
     }
 }
Beispiel #3
0
 /**
  * @return JsonModel
  */
 public function indexAction()
 {
     $required = $this->extensions->getRequired();
     $current = $this->extensions->getCurrent();
     $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
     if (array_diff($required, $current)) {
         $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
     }
     $data = ['responseType' => $responseType, 'data' => ['required' => $required, 'current' => $current]];
     return $this->jsonModel->setVariables($data);
 }
Beispiel #4
0
 /**
  * @return JsonModel
  */
 public function indexAction()
 {
     //@todo I fix it
     $moduleCount = count($this->moduleList->getModules());
     $log = $this->logger->get();
     $progress = 0;
     if (!empty($log)) {
         $progress = round(count($log) / $moduleCount * 90);
     }
     $progress += 5;
     return $this->json->setVariables(array('progress' => $progress, 'success' => !$this->logger->hasError(), 'console' => $log));
 }
 public function suggestAction()
 {
     $q = $this->getRequest()->getPost('q');
     $subject = new Subject();
     $subject->setName($q);
     $jsonModel = new JsonModel();
     if (!$q) {
         $jsonModel->setVariables(['code' => 1, 'data' => []]);
         return $jsonModel;
     }
     /** @var \Subject\Model\SubjectMapper $subjectMapper */
     $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper');
     $jsonModel->setVariables(['code' => 1, 'data' => $subjectMapper->suggest($subject)]);
     return $jsonModel;
 }
 protected function onInvokation(MvcEvent $e, $error = false)
 {
     $viewModel = $e->getResult();
     $isJsonModel = $viewModel instanceof JsonModel;
     $routeMatch = $e->getRouteMatch();
     if ($routeMatch && $routeMatch->getParam('forceJson', false) || $isJsonModel || "json" == $e->getRequest()->getQuery('format') || "json" == $e->getRequest()->getPost('format')) {
         if (!$isJsonModel) {
             $model = new JsonModel();
             if ($error) {
                 $model->status = 'error';
                 $model->message = $viewModel->message;
                 if ($viewModel->display_exceptions) {
                     if (isset($viewModel->exception)) {
                         $model->exception = $viewModel->exception->getMessage();
                     }
                 }
             } else {
                 $model->setVariables($viewModel->getVariables());
             }
             $viewModel = $model;
             $e->setResult($model);
             $e->setViewModel($model);
         }
         $viewModel->setTerminal(true);
         $strategy = new \Zend\View\Strategy\JsonStrategy(new \Zend\View\Renderer\JsonRenderer());
         $view = $e->getApplication()->getServiceManager()->get('ViewManager')->getView();
         $view->addRenderingStrategy(array($strategy, 'selectRenderer'), 10);
         $view->addResponseStrategy(array($strategy, 'injectResponse'), 10);
     }
 }
 /**
  * Set variables
  *
  * Overrides parent to extract variables from JsonSerializable objects.
  *
  * @param  array|Traversable|JsonSerializable|StdlibJsonSerializable $variables
  * @param  bool $overwrite
  * @return self
  */
 public function setVariables($variables, $overwrite = false)
 {
     if ($variables instanceof JsonSerializable || $variables instanceof StdlibJsonSerializable) {
         $variables = $variables->jsonSerialize();
     }
     return parent::setVariables($variables, $overwrite);
 }
Beispiel #8
0
 /**
  * todo lay ra môn học dùng cho tags ở search
  */
 public function fetchallAction()
 {
     /** @var \Subject\Model\SubjectMapper $subjectMapper */
     $subjectMapper = $this->getServiceLocator()->get('Subject\\Model\\SubjectMapper');
     $jsonModel = new JsonModel();
     $jsonModel->setVariables($subjectMapper->suggest(null));
     return $jsonModel;
 }
Beispiel #9
0
 public function onRender(MvcEvent $e)
 {
     if ($e->getResponse()->isOk()) {
         return;
     }
     $httpCode = $e->getResponse()->getStatusCode();
     $sm = $e->getApplication()->getServiceManager();
     $viewModel = $e->getViewModel();
     $exception = $viewModel->getVariable('exception');
     $model = new JsonModel();
     if ($exception) {
         $model->setVariables(['errorCode' => $exception->getCode, 'errorMessage' => $exception->getMessage()]);
     } else {
         $model->setVariables(['errorCode' => $httpCode, 'errorMessage' => 'error has been trigger']);
     }
     $e->setResult($model);
     $e->setViewModel($model);
     $e->getResponse()->setStatusCode($httpCode);
 }
Beispiel #10
0
 /**
  * Home site
  *
  */
 public function indexAction()
 {
     $paginator = $this->paginator('Cv');
     $jsonFormat = 'json' == $this->params()->fromQuery('format');
     if ($jsonFormat) {
         $viewModel = new JsonModel();
         //$items = iterator_to_array($paginator);
         $viewModel->setVariables(array('items' => $this->getServiceLocator()->get('builders')->get('JsonCv')->unbuildCollection($paginator->getCurrentItems()), 'count' => $paginator->getTotalItemCount()));
         return $viewModel;
     }
     return array('resumes' => $paginator, 'sort' => $this->params()->fromQuery('sort', 'none'));
 }
 /**
  * Get the details of a resource
  *
  * @return JsonModel
  */
 public function detailsAction()
 {
     /** @var $options \SwaggerModule\Options\ModuleOptions */
     $options = $this->serviceLocator->get('SwaggerModule\\Options\\ModuleOptions');
     $resourceOptions = $options->getResourceOptions() ?: array();
     $resource = $this->swagger->getResource('/' . $this->params('resource', null), $resourceOptions);
     if ($resource === false) {
         return new JsonModel();
     }
     $jsonModel = new JsonModel();
     return $jsonModel->setVariables($resource);
 }
 /**
  * test ajax
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function testAjaxAction()
 {
     if ($this->zfcUserAuthentication()->hasIdentity()) {
         $name = $this->zfcUserAuthentication()->getIdentity()->getDisplayname();
     } else {
         $name = 'Guest';
     }
     $view = new ViewModel();
     $view->setTemplate('blog/ajax/test.phtml')->setTerminal(true)->setVariables(array('name' => $name));
     $htmlOutput = $this->getServiceLocator()->get('viewrenderer')->render($view);
     $jsonModel = new JsonModel();
     $jsonModel->setVariables(array('html' => $htmlOutput));
     return $jsonModel;
 }
Beispiel #13
0
 public function deleteAction()
 {
     $jsonModel = new JsonModel();
     $id = trim($this->getRequest()->getPost('id'));
     if (!$id) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]);
         return $jsonModel;
     }
     $role = new \System\Model\Role();
     $role->setId($id);
     $roleMapper = $this->getServiceLocator()->get('\\System\\Model\\RoleMapper');
     if (!$roleMapper->get($role)) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Không tìm thấy role']]);
         return $jsonModel;
     }
     if ($roleMapper->isRoleUsed($role)) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Quyền đang được sử dụng, không thể xóa']]);
         return $jsonModel;
     }
     $roleMapper->delete($role);
     $jsonModel->setVariable('code', 1);
     return $jsonModel;
 }
 public function indexAction()
 {
     $organizationId = $this->params()->fromRoute('organizationId', 0);
     try {
         $jobs = $this->jobRepository->findByOrganization($organizationId);
     } catch (\Exception $e) {
         /** @var Response $response */
         $response = $this->getResponse();
         $response->setStatusCode(Response::STATUS_CODE_404);
         return $response;
     }
     $jsonModel = new JsonModel();
     $jsonModel->setVariables($this->apiJobDehydrator->dehydrateList($jobs));
     $jsonModel->setJsonpCallback('yawikParseJobs');
     return $jsonModel;
 }
 /**
  * @uses autocomplete
  */
 public function suggestionAction()
 {
     /* @var $request \Zend\Http\Request */
     $request = $this->getRequest();
     $jsonModel = new JsonModel();
     if (!($q = urldecode(trim($request->getQuery('q'))))) {
         return $jsonModel;
     }
     $p = new \Product\Model\Store();
     $p->setServiceLocator($this->getServiceLocator());
     $data = ['searchOptions' => $p->searchOptions()];
     $limit = trim($request->getQuery('limit'));
     $p->addOption('limit', $limit > 0 ? $limit : 20);
     /* @var $baseStoreMapper \Product\Model\BaseStoreMapper */
     $baseStoreMapper = $this->getServiceLocator()->get('Product\\Model\\BaseStoreMapper');
     $products = $baseStoreMapper->search($p);
     if (is_array($products) && count($products)) {
         $cIds = [];
         foreach ($products as $p) {
             /* @var $p \Product\Model\Store */
             $p->setIsBaseProduct(true);
             $data['products'][] = $p->toStd();
             if ($p->getBaseCategoryId()) {
                 $cIds[$p->getBaseCategoryId()] = $p->getBaseCategoryId();
             }
         }
         if ($request->getQuery('showMore') && $request->getQuery('showMore') == 'category') {
             /* @var $baseCategoryMapper \Product\Model\BaseCategoryMapper */
             $baseCategoryMapper = $this->getServiceLocator()->get('Product\\Model\\BaseCategoryMapper');
             $baseCategory = new \Product\Model\BaseCategory();
             $baseCategory->setChilds($cIds);
             $baseCategory->addOption('limit', 5);
             $categories = $baseCategoryMapper->search($baseCategory);
             if (count($categories)) {
                 foreach ($categories as $c) {
                     /* @var \Product\Model\BaseCategory $c*/
                     $data['categories'][] = $c->toStd();
                 }
             }
         }
     }
     $jsonModel->setVariables($data);
     return $jsonModel;
 }
 public function create($data)
 {
     //echo exec('echo '.serialize($_POST).' > /home/khaled/Desktop/file.txt');
     error_log("You messed up!", 3, BASE_PATH . "/../data/log/my-errors.log");
     $file = $this->params()->fromFiles();
     $filename = $this->uploadImage($file);
     $position = new Position();
     $position->setLatitude($data['latitude']);
     $position->setLongitude($data['longitude']);
     $position->setComment($data['comment']);
     $position->setStatus($data['status']);
     $isAccident = isset($data['isAccident']) ? 1 : 0;
     $position->setIsAccident($isAccident);
     $position->setImage($filename);
     $position->setCreatedDate(time());
     $this->getEntityManager()->persist($position);
     $this->em->flush();
     $model = new JsonModel();
     $model->setVariables($data);
     return $model;
 }
Beispiel #17
0
 public function indexAction()
 {
     $result = ['result' => false, 'message' => ''];
     $viewModel = $this->acceptableviewmodelselector($this->acceptCriteria);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $login = new LoginInputFilter();
         $this->loginForm->setInputFilter($login->getInputFilter());
         $this->loginForm->setData($request->getPost());
         if ($this->loginForm->isValid()) {
             $result = ['result' => true, 'message' => 'Ajax request success'];
         } else {
             $result = ['result' => false, 'message' => $this->loginForm->getMessages()];
         }
     }
     if (!$viewModel instanceof JsonModel && $request->isXmlHttpRequest()) {
         $viewModel = new JsonModel();
     }
     $viewModel->setVariables(['form' => $this->loginForm, 'data' => $result]);
     return $viewModel;
 }
Beispiel #18
0
 public function handleError(MvcEvent $e)
 {
     if ($e->getError() == Application::ERROR_ROUTER_NO_MATCH) {
         return;
     }
     if ($e->getError() == Application::ERROR_EXCEPTION) {
         $translator = $e->getApplication()->getServiceManager()->get('translator');
         $exception = $e->getParam('exception');
         if ($exception instanceof BusinessException) {
             // translate
             $status = intval($exception->getCode());
             $messsage = $translator->translate($exception->getMessage());
         } else {
             $status = 999;
             if (isset($_SERVER['APPLICATION_ENV']) && $_SERVER['APPLICATION_ENV'] == 'development') {
                 $messsage = $exception->getMessage();
             } else {
                 $messsage = '对不起, 系统出错了...';
             }
         }
         /* @var $request \Zend\Http\Request */
         $request = $e->getRequest();
         $response = $e->getResponse();
         if ($request->isXmlHttpRequest()) {
             // change status code from 500 to 200
             $response->setStatusCode(200);
             $response->getHeaders()->addHeaders(array('Content-type' => 'application/json; charset=utf8'));
             $json = new JsonModel();
             $json->setVariables(array('status' => $status, 'message' => $messsage, 'content' => array()));
             $json->setTerminal(false);
             $e->setViewModel($json);
             // mute other default exception handler
             $e->setError(false);
         }
     }
 }
 public function indexAction()
 {
     // we need to init EACH factory to ensure it gets initialized into the statusmanager.
     $factoryList = $this->getServiceLocator()->get('Config')['service_manager']['factories'];
     foreach ($factoryList as $key => $value) {
         $noLoad = false;
         $blacklist = array('ZF', 'AcMailer', 'AssetManager', 'SlmQueue', 'StatusAwareManager', 'doctrine');
         foreach ($blacklist as $blKey => $blacklistItem) {
             if (strpos(strtolower($key), strtolower($blacklistItem)) !== false) {
                 $noLoad = true;
                 break;
             }
         }
         if ($noLoad == false) {
             // echo "Loading " . $key . "\n";
             try {
                 $factory = $this->getServiceLocator()->get($key);
                 if ($factory instanceof StatusInterface) {
                     $status = $factory->getServiceStatusAsArr();
                 }
             } catch (\Exception $e) {
                 //echo $e->getMessage();
                 //die();
             }
         }
     }
     //die();
     /**
      *
      * @var $statusAwareManager StatusManager
      */
     $statusAwareManager = $this->getServiceLocator()->get('StatusAwareManager');
     $viewModel = new JsonModel();
     $viewModel->setVariables($statusAwareManager->getStatus());
     return $viewModel;
 }
 /**
  * Detail view of an application
  * 
  * @return Ambigous <\Zend\View\Model\JsonModel, multitype:boolean unknown >
  */
 public function detailAction()
 {
     if ('refresh-rating' == $this->params()->fromQuery('do')) {
         return $this->refreshRatingAction();
     }
     $nav = $this->getServiceLocator()->get('main_navigation');
     $page = $nav->findByRoute('lang/applications');
     $page->setActive();
     $repository = $this->getServiceLocator()->get('repositories')->get('Applications/Application');
     $application = $repository->find($this->params('id'));
     if (!$application) {
         $this->response->setStatusCode(410);
         $model = new ViewModel(array('content' => 'Invalid apply id'));
         $model->setTemplate('applications/error/not-found');
         return $model;
     }
     $this->acl($application, 'read');
     $applicationIsUnread = false;
     if ($application->isUnreadBy($this->auth('id'))) {
         $application->addReadBy($this->auth('id'));
         $applicationIsUnread = true;
     }
     $format = $this->params()->fromQuery('format');
     if ($application->isDraft()) {
         $list = false;
     } else {
         $list = $this->paginationParams('Applications\\Index', $repository);
         $list->setCurrent($application->id);
     }
     $return = array('application' => $application, 'list' => $list, 'isUnread' => $applicationIsUnread);
     switch ($format) {
         case 'json':
             /*@deprecated - must be refactored */
             $viewModel = new JsonModel();
             $viewModel->setVariables($this->getServiceLocator()->get('builders')->get('JsonApplication')->unbuild($application));
             $viewModel->setVariable('isUnread', $applicationIsUnread);
             $return = $viewModel;
             break;
         case 'pdf':
             $pdf = $this->getServiceLocator()->get('Core/html2pdf');
             break;
         default:
             $contentCollector = $this->getPluginManager()->get('Core/ContentCollector');
             $contentCollector->setTemplate('applications/manage/details/action-buttons');
             $actionButtons = $contentCollector->trigger('application.detail.actionbuttons', $application);
             $return = new ViewModel($return);
             $return->addChild($actionButtons, 'externActionButtons');
             break;
     }
     return $return;
 }
Beispiel #21
0
 public function signupemailAction()
 {
     $viewModels = new ViewModel();
     if (!$this->getRequest()->isPost()) {
         $viewModels->setTemplate('error/404');
         return $viewModels;
     }
     if ($this->getRequest()->isPost()) {
         $email = $this->getRequest()->getPost('email');
         $user = new User();
         $user->setEmail($email);
         $activeKey = md5($user->getEmail() . DateBase::getCurrentDateTime());
         $user->setActiveKey($activeKey);
         $user->setRole(User::ROLE_MEMBER);
         $user->setCreatedDateTime(DateBase::getCurrentDateTime());
         $user->setCreatedDate(DateBase::getCurrentDate());
         /** @var \User\Model\UserMapper $userMapper */
         $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
         $jsonModel = new JsonModel();
         if (!$userMapper->isExistedEmail($user)) {
             $userMapper->save($user);
             Uri::autoLink('/user/user/sendemail', ['email' => $email, 'activeKey' => $user->getActiveKey()]);
             $jsonModel->setVariables(['code' => 2, 'data' => 'Email kích hoạt tài khoản đã được gửi đến địa chỉ email của bạn. Kiểm tra hòm thư và làm theo hướng dẫn đễ kích hoạt tài khoản.']);
         } else {
             $jsonModel->setVariables(['code' => 1, 'data' => 'Email này đã được đăng ký, bạn vui lòng đăng nhập.']);
         }
     }
     return $jsonModel;
 }
Beispiel #22
0
 /**
  * Checks progress of installation
  *
  * @return JsonModel
  */
 public function progressAction()
 {
     $percent = 0;
     $success = false;
     $json = new JsonModel();
     try {
         $progress = $this->progressFactory->createFromLog($this->log);
         $percent = sprintf('%d', $progress->getRatio() * 100);
         $success = true;
         $contents = $this->log->get();
     } catch (\Exception $e) {
         $contents = [(string)$e];
         if ($e instanceof \Magento\Setup\SampleDataException) {
             $json->setVariable('isSampleDataError', true);
         }
     }
     return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
 }
Beispiel #23
0
 private function uploadAnnouncementFile()
 {
     $form = new \Company\Form\AnnouncementFile($this->getServiceLocator());
     $jsonModel = new JsonModel();
     if ($this->getRequest()->isPost()) {
         $dataPopulate = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getQuery()->toArray(), $this->getRequest()->getFiles()->toArray());
         $form->setData($dataPopulate);
         if ($form->isValid()) {
             if ($this->getRequest()->getPost('announcementId') && $this->getRequest()->getPost('companyId')) {
                 $form->addFileUploadRenameFilter($this->getRequest()->getPost('announcementId'), $this->getRequest()->getPost('companyId'));
             } elseif ($this->getRequest()->getQuery('announcementId') && $this->getRequest()->getQuery('companyId')) {
                 $form->addFileUploadRenameFilter($this->getRequest()->getQuery('announcementId'), $this->getRequest()->getQuery('companyId'));
             } else {
                 $form->addFileUploadRenameFilter('temp');
             }
             $announcementFile = new \Company\Model\AnnouncementFile();
             $announcementFile->exchangeArray($form->getData());
             $announcementFileMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementFileMapper');
             if (!$announcementFileMapper->isExisted($announcementFile)) {
                 $announcementFile->setCreatedById($this->user()->getIdentity());
                 $oldname = Uri::getSavePath($announcementFile);
                 $announcementFile->setFilePath(DateBase::toFormat(DateBase::getCurrentDateTime(), 'Ymd'));
                 $announcementFile->setCreatedDateTime(DateBase::getCurrentDateTime());
                 $newname = Uri::getSavePath($announcementFile);
                 if (!file_exists($newname)) {
                     $oldmask = umask(0);
                     mkdir($newname, 0777, true);
                     umask($oldmask);
                 }
                 rename($oldname . '/' . $announcementFile->getFileName(), $newname . '/' . $announcementFile->getFileName());
                 $announcementFileMapper->save($announcementFile);
             }
             $jsonModel->setVariables(['code' => 1, 'data' => ['id' => $announcementFile->getId()]]);
         } else {
             $jsonModel->setVariables(['code' => 0, 'messages' => $form->getMessagesForUpload()]);
         }
     } else {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['phải là request post']]);
     }
     return $jsonModel;
 }
 /**
  * Detail view of an application
  *
  * @return array|JsonModel|ViewModel
  */
 public function detailAction()
 {
     if ('refresh-rating' == $this->params()->fromQuery('do')) {
         return $this->refreshRatingAction();
     }
     $nav = $this->serviceLocator->get('Core/Navigation');
     $page = $nav->findByRoute('lang/applications');
     $page->setActive();
     /* @var \Applications\Repository\Application$repository */
     $repository = $this->serviceLocator->get('repositories')->get('Applications/Application');
     /* @var Application $application */
     $application = $repository->find($this->params('id'));
     if (!$application) {
         $this->response->setStatusCode(410);
         $model = new ViewModel(array('content' => 'Invalid apply id'));
         $model->setTemplate('applications/error/not-found');
         return $model;
     }
     $this->acl($application, 'read');
     $applicationIsUnread = false;
     if ($application->isUnreadBy($this->auth('id')) && $application->getStatus()) {
         $application->addReadBy($this->auth('id'));
         $applicationIsUnread = true;
         $application->changeStatus($application->getStatus(), sprintf('Application was read by %s', $this->auth()->getUser()->getInfo()->getDisplayName()));
     }
     $format = $this->params()->fromQuery('format');
     if ($application->isDraft()) {
         $list = false;
     } else {
         $list = $this->paginationParams('Applications\\Index', $repository);
         $list->setCurrent($application->id);
     }
     $return = array('application' => $application, 'list' => $list, 'isUnread' => $applicationIsUnread, 'format' => 'html');
     switch ($format) {
         case 'json':
             /*@deprecated - must be refactored */
             $viewModel = new JsonModel();
             $viewModel->setVariables($this->serviceLocator->get('builders')->get('JsonApplication')->unbuild($application));
             $viewModel->setVariable('isUnread', $applicationIsUnread);
             $return = $viewModel;
             break;
         case 'pdf':
             $pdf = $this->serviceLocator->get('Core/html2pdf');
             $return['format'] = $format;
             break;
         default:
             $contentCollector = $this->getPluginManager()->get('Core/ContentCollector');
             $contentCollector->setTemplate('applications/manage/details/action-buttons');
             $actionButtons = $contentCollector->trigger('application.detail.actionbuttons', $application);
             $return = new ViewModel($return);
             $return->addChild($actionButtons, 'externActionButtons');
             $allowSubsequentAttachmentUpload = $this->serviceLocator->get('Applications/Options')->getAllowSubsequentAttachmentUpload();
             if ($allowSubsequentAttachmentUpload && $this->acl($application, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, 'test')) {
                 $attachmentsForm = $this->serviceLocator->get('forms')->get('Applications/Attachments');
                 $attachmentsForm->bind($application->getAttachments());
                 /* @var $request \Zend\Http\PhpEnvironment\Request */
                 $request = $this->getRequest();
                 if ($request->isPost() && $attachmentsForm->get('return')->getValue() === $request->getPost('return')) {
                     $data = array_merge($attachmentsForm->getOption('use_post_array') ? $request->getPost()->toArray() : [], $attachmentsForm->getOption('use_files_array') ? $request->getFiles()->toArray() : []);
                     $attachmentsForm->setData($data);
                     if (!$attachmentsForm->isValid()) {
                         return new JsonModel(['valid' => false, 'errors' => $attachmentsForm->getMessages()]);
                     }
                     $content = $attachmentsForm->getHydrator()->getLastUploadedFile()->getUri();
                     return new JsonModel(['valid' => $attachmentsForm->isValid(), 'content' => $content]);
                 }
                 $return->setVariable('attachmentsForm', $attachmentsForm);
             }
             break;
     }
     return $return;
 }
Beispiel #25
0
 public function refreshAction()
 {
     $form = $this->_getForm();
     $captcha = $form->get('captcha')->getCaptcha();
     $data = array();
     $data['id'] = $captcha->generate();
     $data['src'] = $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix();
     $jsonModel = new JsonModel();
     $jsonModel->setVariables($data);
     return $jsonModel;
 }
Beispiel #26
0
 public function savecompanyfeatureAction()
 {
     $actionIds = $this->getRequest()->getPost('actionIds');
     $companyId = $this->getRequest()->getPost('companyId');
     $jsonModel = new JsonModel();
     if (!$companyId) {
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Dữ liệu không hợp lệ']]);
         return $jsonModel;
     }
     $companyFeature = new \Company\Model\Feature();
     $companyFeature->setCompanyId($companyId);
     $companyFeatureMapper = $this->getServiceLocator()->get('\\Company\\Model\\FeatureMapper');
     $companyFeatureMapper->deleteCompanyFeature($companyFeature);
     if ($actionIds) {
         $actionIds = explode(',', $actionIds);
         foreach ($actionIds as $actionId) {
             $companyFeature->setActionId($actionId);
             if (!$companyFeatureMapper->isExisted($companyFeature)) {
                 $companyFeatureMapper->save($companyFeature);
             }
         }
     }
     $jsonModel->setVariables(['code' => 1]);
     return $jsonModel;
 }
 /**
  * Helper action for userselect form element.
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function searchUsersAction()
 {
     if (!$this->getRequest()->isXmlHttpRequest()) {
         throw new \RuntimeException('This action must be called via ajax request');
     }
     $model = new JsonModel();
     $query = $this->params()->fromPost('query', false);
     if (!$query) {
         $query = $this->params()->fromQuery('q', false);
     }
     if (false === $query) {
         $result = array();
     } else {
         $services = $this->getServiceLocator();
         $repositories = $services->get('repositories');
         $repository = $repositories->get('Auth/User');
         $users = $repository->findByQuery($query);
         $userFilter = $services->get('filtermanager')->get('Auth/Entity/UserToSearchResult');
         $filterFunc = function ($user) use($userFilter) {
             return $userFilter->filter($user);
         };
         $result = array_values(array_map($filterFunc, $users->toArray()));
     }
     //$model->setVariable('users', $result);
     $model->setVariables($result);
     return $model;
 }
Beispiel #28
0
 public function renderError(MvcEvent $e)
 {
     // must be an error
     if (!$e->isError()) {
         return;
     }
     $request = $e->getRequest();
     if (!$request instanceof HttpRequest) {
         return;
     }
     // We ought to check for a JSON accept header here, except that we
     // don't need to as we only ever send back JSON.
     // If we have a JsonModel in the result, then do nothing
     $currentModel = $e->getResult();
     if ($currentModel instanceof JsonModel) {
         return;
     }
     // Create a new JsonModel and populate with default error information
     $model = new JsonModel();
     // Override with information from actual ViewModel
     $displayExceptions = true;
     if ($currentModel instanceof ModelInterface) {
         $model->setVariables($currentModel->getVariables());
         if ($model->display_exceptions) {
             $displayExceptions = (bool) $data['display_exceptions'];
         }
     }
     // Check for exception
     $exception = $currentModel->getVariable('exception');
     if ($exception && $displayExceptions) {
         // If a code was set in the Exception, then assume that it's the
         // HTTP Status code to be sent back to the client
         if ($exception->getCode()) {
             $e->getResponse()->setStatusCode($exception->getCode());
         }
         // Should probably only render a backtrace this if in development mode!
         $model->backtrace = explode("\n", $exception->getTraceAsString());
         // Assign the message & any previous ones
         $model->message = $exception->getMessage();
         $previousMessages = array();
         while ($exception = $exception->getPrevious()) {
             $previousMessages[] = "* " . $exception->getMessage();
         }
         if (count($previousMessages)) {
             $exceptionString = implode("\n", $previousMessages);
             $model->previous_messages = $exceptionString;
         }
     }
     // Set the result and view model to our new JsonModel
     $model->setTerminal(true);
     $e->setResult($model);
     $e->setViewModel($model);
 }
Beispiel #29
-1
 /**
  * Remove event
  *
  * @return JsonModel
  */
 public function removeEventAction()
 {
     $model = Event\Model::fromId($this->params()->fromRoute('id'));
     $success = false;
     if (!empty($model)) {
         $model->delete();
         $success = true;
     }
     $jsonModel = new JsonModel();
     $jsonModel->setVariables(array('success' => $success));
     $jsonModel->setTerminal(true);
     return $jsonModel;
 }
 /**
  * Get all files from all folders and list them in the gallery
  * getcwd() is there to make the work with images path easier.
  *
  * @return JsonModel
  */
 public function filesAction()
 {
     chdir(getcwd() . '/public/');
     $this->makeDir();
     $this->getView()->setTerminal(true);
     $dir = new RecursiveDirectoryIterator('userfiles/', FilesystemIterator::SKIP_DOTS);
     $iterator = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
     $iterator->setMaxDepth(50);
     $files = $this->extractImages($iterator);
     chdir(dirname(getcwd()));
     $model = new JsonModel();
     $model->setVariables(['files' => $files]);
     return $model;
 }