public function getThumbsAction() { // width of html doc $screen_width = (int) $this->params()->fromQuery('screen_width'); //width of browser viewport $width = (int) $this->params()->fromQuery('width'); $height = (int) $this->params()->fromQuery('height'); $direction = $this->params()->fromQuery('direction'); $galleryModel = $this->getVideosModel(); $limit = $galleryModel->getLimit($width, $height); //$page = (int)$this->params('page'); $page = (int) $this->params()->fromQuery('page'); $offset = 0; if ($page > 0) { $offset = $page * $limit; } $cache = $this->getVideosModel()->getThumbVideosCache(); $key = $offset . "_" . $limit; $jsonStr = $cache->getItem($key, $success); if ($this->disableCache || !$success) { $thumbArr = $this->getVideosMapper()->fetchThumbArr($offset, $limit); if ($thumbArr) { $cache->setItem($key, serialize($thumbArr)); } } else { $thumbArr = unserialize($jsonStr); } $jsonModel = new JsonModel(array("result" => $thumbArr)); $jsonModel->setTerminal(true); 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); } }
public function testCanSerializeWithJsonpCallback() { $array = array('foo' => 'bar'); $model = new JsonModel($array); $model->setJsonpCallback('callback'); $this->assertEquals('callback(' . Json::encode($array) . ');', $model->serialize()); }
public function folderPermissionsAction() { $jsonModel = new JsonModel(); foreach ($this->config['component'] as $component) { if (@$component['image_path'] || @$component['video_path'] || @$component['file_path']) { if (isset($component['image_path']) && !empty($component['image_path'])) { if (!file_exists($component['image_path'])) { $oldmask = umask(0); mkdir($component['image_path'], 0777); umask($oldmask); $jsonModel->setVariable($component['image_path'], $component['image_path']); } } if (isset($component['video_path']) && !empty($component['video_path'])) { if (!file_exists($component['video_path'])) { $oldmask = umask(0); mkdir($component['video_path'], 0777); umask($oldmask); $jsonModel->setVariable($component['video_path'], $component['video_path']); } } if (isset($component['file_path']) && !empty($component['file_path'])) { if (!file_exists($component['file_path'])) { $oldmask = umask(0); mkdir($component['file_path'], 0777); umask($oldmask); $jsonModel->setVariable($component['file_path'], $component['file_path']); } } } } $response = $this->getResponse(); $response->setContent(json_encode($jsonModel->getVariables())); return $response; }
public function __invoke($variables = null, $options = null, $template = null) { $viewModel = new JsonModel($variables, $options); if ($template) { $viewModel->setTemplate($template); } return $viewModel; }
/** * 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; }
public static function getJson($data, $callback = null) { $json = new JsonModel($data); if ($callback != null) { $json->setJsonpCallback($callback); } return $json; }
/** * @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); }
/** * @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]); } }
/** * getJsonResponse * * @param Result $result result * * @return \Zend\Stdlib\ResponseInterface */ public function getJsonResponse($result) { $view = new JsonModel(); $view->setTerminal(true); $response = $this->getResponse(); $json = json_encode($result); $response->setContent($json); $response->getHeaders()->addHeaders(['Content-Type' => 'application/json']); return $response; }
/** * Call this method from the appropriate action method * * @return ApiProblemResponse|JsonModel */ public function handleRequest() { $request = $this->getRequest(); if ($request->getMethod() != $request::METHOD_GET) { return new ApiProblemResponse(new ApiProblem(405, 'Only the GET method is allowed for this URI')); } $model = new JsonModel([$this->property => $this->model->fetchAll()]); $model->setTerminal(true); return $model; }
/** * @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); }
/** * @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 deleteAction() { $id = $this->params()->fromQuery('id'); $em = $this->getEntityManager(); $jsonModel = new JsonModel(); /** @var $res \Base\Entity\Competition */ $res = $em->getRepository('Base\\Entity\\User')->find($id); $em->remove($res); $em->flush(); $jsonModel->setVariable('success', true); return $jsonModel; }
/** * 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); }
public function deleteAction() { $jsonModel = new JsonModel(); $id = (int) $this->params()->fromPost('id'); if ($id > 0) { $result = $this->getNoteTable()->delete($id); } else { $result = false; } $jsonModel->setVariable("result", $result); return $jsonModel; }
/** * 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')); }
/** * 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; }
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; }
public function loginAction() { $this->authService = new AuthenticationService(); $request = (array) Json::decode($this->getRequest()->getContent()); if ($this->getRequest()->isPost()) { $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter'); $login = new Login($request, $dbAdapter); if ($login->ValidFilter($request)) { $login->Auth($dbAdapter); } $result = new JsonModel(array('message' => $login->getMessage(), 'code' => $login->getCode())); echo $result->serialize(); exit; } }
/** * @param HttpRequest $request * * @return \Zend\View\Model\ViewModel */ public function build(HttpRequest $request, SmartServiceResult $result, $action) { $viewModel = null; if ($request->isXmlHttpRequest()) { $viewModel = new JsonModel(); $viewModel->setTerminal(true); } else { $viewModel = new \Zend\View\Model\ViewModel(); $viewModel->setVariable('entity', $result->getEntity()); $viewModel->setVariable('form', $result->getForm()); $viewModel->setVariable('list', $result->getList()); $viewModel->setTemplate(sprintf($this->getTemplate(), $action)); } return $viewModel; }
/** * Method executed when the render event is triggered * * @param MvcEvent $e * @return void */ public static function onRender(MvcEvent $e) { if ($e->getRequest() instanceof \Zend\Console\Request || $e->getResponse()->isOk() || $e->getResponse()->getStatusCode() == Response::STATUS_CODE_401) { return; } $httpCode = $e->getResponse()->getStatusCode(); $sm = $e->getApplication()->getServiceManager(); $viewModel = $e->getResult(); $exception = $viewModel->getVariable('exception'); $model = new JsonModel(array('errorCode' => !empty($exception) ? $exception->getCode() : $httpCode, 'errorMsg' => !empty($exception) ? $exception->getMessage() : NULL)); $model->setTerminal(true); $e->setResult($model); $e->setViewModel($model); $e->getResponse()->setStatusCode($httpCode); }
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; }
/** * 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); }
public function validFormAction() { $jsonModel = new JsonModel(); $formData = $this->params()->fromPost(); $formManager = $this->getServiceLocator()->get('formElementManager'); $form = $formManager->get('addressForm'); $form->setData($formData); $result = $form->isValid(); $messages = []; if (!$result) { $messages = $form->getMessages(); } $jsonModel->setVariable('jsonData', ['isValid' => $result, 'messages' => $messages]); $this->getResponse()->getHeaders()->addHeaderLine('content-type', 'application/json'); return $jsonModel; }
/** * @param null $variables * @param mixed|int $code - 0 for success * @param string $message - General public message for client * @param array $errors - Example - Pass the messages from input validator * @param null $options */ public function __construct($variables = null, $code = 0, $message = 'OK', $errors = [], $options = null) { $this->setCode($code); $this->setMessage($message); $this->setErrors($errors); parent::__construct($variables, $options); }
public function getCamGirlsOnlineAction() { $cache = $this->getCache(); $key = $this->getCacheKey(); $str = $cache->getItem($key, $success); if (!$success) { $res = $this->getCamTable()->getCamGirlsOnline(); $res = $this->getCamModel()->buildCamgirlArr($res); if ($res) { $cache->setItem($key, serialize($res)); } } else { $res = unserialize($str); } $jsonModel = new JsonModel(array("result" => $res)); $jsonModel->setTerminal(true); 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; }
/** * 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; }