private function _testEnabled($method = 'GET') { $request = new Request(); $request->env('REQUEST_METHOD', $method); $request->here = '/pages/home'; $response = new Response(); $View = new View($request, $response); $View->loadHelper('ViewMemcached.ViewMemcached', ['cacheConfig' => TEST_CACHE_CONFIG]); $View->viewPath = 'Pages'; $View->set('test', 'value'); $View->render('home', 'default'); return $View->ViewMemcached->enabled(); }
/** * @return void */ public function testRoles() { $this->AuthUserHelper->config('multiRole', true); $user = ['id' => '1', 'Roles' => ['1', '2']]; $this->View->set('_authUser', $user); $this->assertSame(['user' => '1', 'moderator' => '2'], $this->AuthUserHelper->roles()); }
public function get_for_parent($parent, $page) { $comments = $this->Comments->find()->where(['Comments.object_id' => $parent])->limit(__MAX_COMMENTS_LISTED)->page($page)->order('Comments.created DESC')->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]]); // Reorder the Comments by creation order // (even though we got them by descending order) $collection = new Collection($comments); $comments = $collection->sortBy('Comment.created'); $view = new View($this->request, $this->response, null); $view->layout = 'ajax'; // layout to use or false to disable $view->set('comments', $comments->toArray()); $data['html'] = $view->render('Social.Comments/get_for_parent'); $this->layout = 'ajax'; $this->set('data', $data); $this->render('/Shared/json/data'); }
public function notifications($user = null, $page = 1) { // Getting the Activities personalized feed // NEW : User must subscribe individually to each Pole's Feed to be notified. // We only get the Activities for which the User is not the creator // that were created after the last time he read them. if (!$user) { $user = $this->loggedInUser->id; } // Then get all the subscriptions $Subscriptions = TableRegistry::get('Social.Subscriptions'); $subscriptions = $Subscriptions->find()->where(['Subscriptions.user_id' => $user])->all(); $subscriptions = (new Collection($subscriptions))->extract('feed_id')->toArray(); $query = $this->Activities->find()->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]])->limit(__MAX_NOTIFICATIONS_LISTED)->page($page)->order(['Activities.created DESC'])->matching('Feeds', function ($q) use($subscriptions) { return $q->where(['Feeds.id IN' => $subscriptions]); }); if ($this->request->is('ajax')) { if (isset($this->request->query['last_check'])) { $last_check = Time::createFromTimestamp($this->request->query['last_check'] / 1000); $activities = $query->where(['Activities.subject_id !=' => $user, 'Activities.created >' => $last_check->format('Y-m-d H:i:s')])->all(); } else { $activities = $query->where(['Activities.subject_id !=' => $user])->all(); } $count = $this->Activities->find()->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]])->limit(20000)->order(['Activities.created DESC'])->where(['Activities.subject_id !=' => $user, 'Activities.created >' => $this->loggedInUser->notifications_last_read])->matching('Feeds', function ($q) use($subscriptions) { return $q->where(['Feeds.id IN' => $subscriptions]); })->count(); $view = new View($this->request, $this->response, null); $view->layout = 'ajax'; // layout to use or false to disable $view->set('loggedInUser', $this->loggedInUser); $view->set('all_poles', $this->all_poles->toArray()); $view->set('activities', $activities->toArray()); $data['html'] = $view->render('Social.Activities/ajax_notifications'); $this->layout = 'ajax'; $data['count'] = $count; $data['success'] = true; $this->set('data', $data); $this->render('/Shared/json/data'); } else { $activities = $query->where(['Activities.subject_id !=' => $user])->all(); $this->set('activities', $activities->toArray()); // UI $this->set('section_title', __('Notifications')); $this->set('page_title', __('Notifications')); // Handling the breadcrumb $this->breadcrumb = array(__('Notifications') => '#'); } }
/** * Generate PDF * @param $id */ public function pdf($id = null) { $row = $this->Orders->findById($id)->contain(["Users", "Statuses", "Operations", "Accessories", "Images"])->first(); if (!$row) { throw new InternalErrorException("Chyba pri nacitani objednavky", 500); } $view = new View($this->request, $this->response, null); $view->layout = "ajax"; $view->set("row", $row); $html = $view->render("Orders/pdf"); $pdf = new \DOMPDF(); $pdf->load_html(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); $pdf->set_paper('a4', 'portrait'); $pdf->render(); $pdf->stream("order-" . $id . ".pdf", array("Attachment" => 0)); }