/** * Private method to generate the main body HTML for this page. * * @since 1.0 * * @return string */ private function displayBodyContent() { $classNames = ActiveRecord::getBOClassNames(); $body = ''; $fields = array('formAction' => $this->request->getURI()); foreach ($classNames as $className) { try { $activeRecord = new $className(); $view = View::getInstance($activeRecord); $body .= $view->adminView($fields); } catch (AlphaException $e) { self::$logger->error("[{$classname}]:" . $e->getMessage()); // its possible that the exception occured due to the table schema being out of date if ($activeRecord->checkTableExists() && $activeRecord->checkTableNeedsUpdate()) { $missingFields = $activeRecord->findMissingFields(); $count = count($missingFields); for ($i = 0; $i < $count; ++$i) { $activeRecord->addProperty($missingFields[$i]); } // now try again... $activeRecord = new $className(); $view = View::getInstance($activeRecord); $body .= $view->adminView($fields); } } catch (\Exception $e) { self::$logger->error($e->getMessage()); $body .= View::displayErrorMessage('Error accessing the class [' . $classname . '], check the log!'); } } return $body; }
/** * Renders the search result list. * * @param array $results * @param string $query * @param bool $showTags * * @since 1.0 * * @return string */ protected function renderResultList($results, $query = '', $showTags = true) { $config = ConfigProvider::getInstance(); // used to track when our pagination range ends $end = $this->startPoint + $config->get('app.list.page.amount'); $body = ''; if (!empty($query)) { $body .= '<h2>Displaying results for "' . $query . '"</h2>'; } foreach ($results as $bo) { if ($bo instanceof \Alpha\Model\Article && $bo->get('published') == false) { --$this->resultCount; } else { $view = View::getInstance($bo); $URI = $this->request->getURI(); $body .= $view->listView(array('formAction' => $URI)); if ($showTags) { $tags = $bo->getPropObject('tags')->getRelatedObjects(); if (count($tags) > 0) { $body .= '<p>Tags: '; $queryTerms = explode(' ', mb_strtolower($query)); foreach ($tags as $tag) { $body .= in_array($tag->get('content'), $queryTerms) ? '<strong>' . $tag->get('content') . ' </strong>' : $tag->get('content') . ' '; } $body .= '</p>'; } } } } return $body; }
/** * Testing the renderAllFields() method. * * @since 2.0 */ public function testRenderAllFields() { $article = new Article(); $article->set('title', 'Test Article'); $this->view = View::getInstance($article); $this->assertNotEmpty($this->view->renderAllFields('view'), 'Testing the renderAllFields() method'); $this->assertTrue(strpos($this->view->renderAllFields('view'), 'Test Article') !== false, 'Testing the renderAllFields() method'); }
/** * Method to handle PUT requests. * * @param Alpha\Util\Http\Request $request * * @throws Alpha\Exception\IllegalArguementException * @throws Alpha\Exception\SecurityException * * @return Alpha\Util\Http\Response * * @since 2.0 */ public function doPUT($request) { self::$logger->debug('>>doPUT(request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $params = $request->getParams(); $accept = $request->getAccept(); try { if (isset($params['ActiveRecordType'])) { $ActiveRecordType = urldecode($params['ActiveRecordType']); } else { throw new IllegalArguementException('No ActiveRecord available to edit!'); } if (class_exists($ActiveRecordType)) { $record = new $ActiveRecordType(); } else { throw new IllegalArguementException('No ActiveRecord [' . $ActiveRecordType . '] available to edit!'); } // check the hidden security fields before accepting the form POST data if (!$this->checkSecurityFields()) { throw new SecurityException('This page cannot accept post data from remote servers!'); } $record->load($params['ActiveRecordOID']); $record->populateFromArray($params); $record->save(); self::$logger->action('Saved ' . $ActiveRecordType . ' instance with OID ' . $record->getOID()); if (isset($params['statusMessage'])) { $this->setStatusMessage(View::displayUpdateMessage($params['statusMessage'])); } else { $this->setStatusMessage(View::displayUpdateMessage('Saved')); } ActiveRecord::disconnect(); } catch (SecurityException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotAllowedException($e->getMessage()); } catch (IllegalArguementException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The record that you have requested cannot be found!'); } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The record that you have requested cannot be found!'); } catch (ValidationException $e) { self::$logger->warn($e->getMessage() . ', query [' . $record->getLastQuery() . ']'); $this->setStatusMessage(View::displayErrorMessage($e->getMessage())); } if ($accept == 'application/json') { $view = View::getInstance($record, false, $accept); $body = $view->detailedView(); $response = new Response(200); $response->setHeader('Content-Type', 'application/json'); $response->setHeader('Location', $config->get('app.url') . '/record/' . $params['ActiveRecordType'] . '/' . $record->getOID()); $response->setBody($body); } else { $response = new Response(301); if ($this->getNextJob() != '') { $response->redirect($this->getNextJob()); } else { if ($this->request->isSecureURI()) { $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $ActiveRecordType . '&ActiveRecordOID=' . $record->getOID() . '&view=edit')); } else { $response->redirect($config->get('app.url') . '/record/' . $params['ActiveRecordType'] . '/' . $record->getOID() . '/edit'); } } } self::$logger->debug('<<doPUT'); return $response; }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $body = View::displayPageHead($this); $sequence = new Sequence(); // make sure that the Sequence tables exist if (!$sequence->checkTableExists()) { $body .= View::displayErrorMessage('Warning! The Sequence table do not exist, attempting to create it now...'); $sequence->makeTable(); } // set the start point for the list pagination if (isset($params['start']) ? $this->startPoint = $params['start'] : ($this->startPoint = 1)) { } $records = $sequence->loadAll($this->startPoint); ActiveRecord::disconnect(); $this->BOCount = $sequence->getCount(); $body .= View::renderDeleteForm($this->request->getURI()); foreach ($records as $record) { $view = View::getInstance($record); $body .= $view->listView(array('URI' => $request->getURI())); } $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Testing the editView() method. * * @since 2.0 */ public function testEditView() { $articleComment = new ArticleComment(); $articleComment->set('content', 'test comment'); $articleComment->save(); $view = View::getInstance($articleComment); $this->assertNotEmpty($view->editView(array('formAction' => '/')), 'Testing the editView() method'); $this->assertTrue(strpos($view->editView(array('formAction' => '/')), 'Update Your Comment') !== false, 'Testing the editView() method'); }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $params = $request->getParams(); $body = ''; // load one DEnum if (isset($params['denumOID'])) { $BOoid = $params['denumOID']; // set up the title and meta details $this->setTitle('Editing a DEnum'); $this->setDescription('Page to edit a DEnum.'); $this->setKeywords('edit,DEnum'); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } try { $this->BO->load($BOoid); ActiveRecord::disconnect(); $this->BOName = 'DEnum'; $this->BOView = View::getInstance($this->BO); $body .= View::renderDeleteForm($request->getURI()); $body .= $this->BOView->editView(array('URI' => $request->getURI())); } catch (RecordNotFoundException $e) { self::$logger->error('Unable to load the DEnum of id [' . $params['denumOID'] . '], error was [' . $e->getMessage() . ']'); } } else { // load all DEnums // set up the title and meta details $this->setTitle('Listing all DEnums'); $this->setDescription('Page to list all DEnums.'); $this->setKeywords('list,all,DEnums'); $body .= View::displayPageHead($this); // make sure that the DEnum tables exist if (!$this->BO->checkTableExists()) { $body .= View::displayErrorMessage('Warning! The DEnum tables do not exist, attempting to create them now...'); $body .= $this->createDEnumTables(); } // get all of the BOs and invoke the list view on each one // set the start point for the list pagination if (isset($params['start']) ? $this->startPoint = $params['start'] : ($this->startPoint = 1)) { } $objects = $this->BO->loadAll($this->startPoint); ActiveRecord::disconnect(); $this->BOCount = $this->BO->getCount(); $body .= View::renderDeleteForm($request->getURI()); foreach ($objects as $object) { $temp = View::getInstance($object); $body .= $temp->listView(array('URI' => $request->getURI())); } } $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * constructor to set up the object. * * @since 1.0 */ public function __construct() { self::$logger = new Logger('LoginController'); self::$logger->debug('>>__construct()'); $config = ConfigProvider::getInstance(); // ensure that the super class constructor is called, indicating the rights group parent::__construct('Public'); $this->personObject = new Person(); $this->personView = View::getInstance($this->personObject); $this->setRecord($this->personObject); // set up the title and meta details $this->setTitle('Login to ' . $config->get('app.title')); $this->setDescription('Login page.'); $this->setKeywords('login,logon'); self::$logger->debug('<<__construct'); }
/** * Method for displaying the user comments for the article. * * @return string * * @since 1.0 */ private function renderComments() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $html = ''; $comments = $this->record->getArticleComments(); $commentsCount = count($comments); $URL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\ArticleComment'); $fields = array('formAction' => $URL); if ($config->get('cms.display.comments') && $commentsCount > 0) { $html .= '<h2>There are [' . $commentsCount . '] user comments for this article</h2>'; for ($i = 0; $i < $commentsCount; ++$i) { $view = View::getInstance($comments[$i]); $html .= $view->markdownView($fields); } } if ($session->get('currentUser') != null && $config->get('cms.comments.allowed')) { $comment = new ArticleComment(); $comment->set('articleOID', $this->record->getID()); $view = View::getInstance($comment); $html .= $view->createView($fields); } return $html; }
/** * Testing the detailedView() method. * * @since 2.0 */ public function testDetailedView() { $sequence = new Sequence(); $sequence->load(1); $view = View::getInstance($sequence); $this->assertNotEmpty($view->detailedView(), 'Testing the detailedView() method'); $this->assertTrue(strpos($view->detailedView(), 'TEST') !== false, 'Testing the detailedView() method'); }