diff --git a/Alpha/Controller/ActiveRecordController.php b/Alpha/Controller/ActiveRecordController.php index 2e115ede..46bd7479 100644 --- a/Alpha/Controller/ActiveRecordController.php +++ b/Alpha/Controller/ActiveRecordController.php @@ -647,9 +647,9 @@ protected function renderPageLinks() if ($this->startPoint > 1) { // handle secure URLs if ($this->request->getParam('token', null) != null) - $body .= '
  • <<-Previous
  • '; + $body .= '
  • <<-Previous
  • '; else - $body .= '
  • startPoint-$config->get('app.list.page.amount')).'"><<-Previous
  • '; + $body .= '
  • startPoint-$config->get('app.list.page.amount')).'"><<-Previous
  • '; } elseif ($this->recordCount > $config->get('app.list.page.amount')){ $body .= '
  • <<-Previous
  • '; } @@ -660,9 +660,9 @@ protected function renderPageLinks() if ($i != ($this->startPoint-1)) { // handle secure URLs if ($this->request->getParam('token', null) != null) - $body .= '
  • '.$page.'
  • '; + $body .= '
  • '.$page.'
  • '; else - $body .= '
  • '.$page.'
  • '; + $body .= '
  • '.$page.'
  • '; } elseif ($this->recordCount > $config->get('app.list.page.amount')) { $body .= '
  • '.$page.'
  • '; } @@ -673,9 +673,9 @@ protected function renderPageLinks() if ($this->recordCount > $end) { // handle secure URLs if ($this->request->getParam('token', null) != null) - $body .= '
  • Next->>
  • '; + $body .= '
  • Next->>
  • '; else - $body .= '
  • startPoint+$config->get('app.list.page.amount')). + $body .= '
  • startPoint+$config->get('app.list.page.amount')). '">Next->>
  • '; } elseif ($this->recordCount > $config->get('app.list.page.amount')) { $body .= '
  • Next->>
  • '; diff --git a/Alpha/Controller/ArticleController.php b/Alpha/Controller/ArticleController.php index 2fd4ff0d..7ad9f9e8 100644 --- a/Alpha/Controller/ArticleController.php +++ b/Alpha/Controller/ArticleController.php @@ -261,7 +261,7 @@ public function doGET($request) // handle requests to view a list of articles if ($this->mode == 'read') { - $listController = new ListController(); + $listController = new ActiveRecordController(); $request->addParams(array('ActiveRecordType' => 'Alpha\Model\Article'));# $listController->setRequest($request); return $listController->doGET($request); @@ -677,7 +677,7 @@ public function doDELETE($request) $body .= '
    '; - $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ListController&ActiveRecordType='.get_class($this->BO))."'", + $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'", 'Back to List','cancelBut'); $body .= $temp->render(); diff --git a/Alpha/Controller/DEnumController.php b/Alpha/Controller/DEnumController.php index f2985a69..d6c342c8 100644 --- a/Alpha/Controller/DEnumController.php +++ b/Alpha/Controller/DEnumController.php @@ -59,7 +59,7 @@ * * */ -class DEnumController extends ListController implements ControllerInterface +class DEnumController extends ActiveRecordController implements ControllerInterface { /** * Trace logger diff --git a/Alpha/Controller/Front/FrontController.php b/Alpha/Controller/Front/FrontController.php index 5377f2e6..1795ea08 100644 --- a/Alpha/Controller/Front/FrontController.php +++ b/Alpha/Controller/Front/FrontController.php @@ -25,7 +25,6 @@ use Alpha\Controller\GenSecureQueryStringController; use Alpha\Controller\ImageController; use Alpha\Controller\ListActiveRecordsController; -use Alpha\Controller\ListController; use Alpha\Controller\LogController; use Alpha\Controller\LoginController; use Alpha\Controller\LogoutController; @@ -218,11 +217,6 @@ public function __construct() return $controller->process($request); }); - $this->addRoute('/listall/{ActiveRecordType}/{start}/{limit}', function($request) { - $controller = new ListController(); - return $controller->process($request); - })->value('start', 1)->value('limit', $config->get('app.list.page.amount')); - $this->addRoute('/log/{logPath}', function($request) { $controller = new LogController(); return $controller->process($request); diff --git a/Alpha/Controller/ListController.php b/Alpha/Controller/ListController.php deleted file mode 100644 index f859fe17..00000000 --- a/Alpha/Controller/ListController.php +++ /dev/null @@ -1,444 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
    - * Redistribution and use in source and binary forms, with or
    - * without modification, are permitted provided that the
    - * following conditions are met:
    - *
    - * * Redistributions of source code must retain the above
    - *   copyright notice, this list of conditions and the
    - *   following disclaimer.
    - * * Redistributions in binary form must reproduce the above
    - *   copyright notice, this list of conditions and the
    - *   following disclaimer in the documentation and/or other
    - *   materials provided with the distribution.
    - * * Neither the name of the Alpha Framework nor the names
    - *   of its contributors may be used to endorse or promote
    - *   products derived from this software without specific
    - *   prior written permission.
    - *
    - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
    - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
    - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
    - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    - * 
    - * - */ -class ListController extends Controller implements ControllerInterface -{ - /** - * The name of the ActiveRecord type that we will be creating - * - * @var string - * @since 2.0 - */ - protected $activeRecordType; - - /** - * The new default View object used for rendering the onjects to list - * - * @var Alpha\View\View - * @since 1.0 - */ - protected $BOView; - - /** - * The start number for list pageination - * - * @var integer - * @since 1.0 - */ - protected $startPoint = 1; - - /** - * The count of the BOs of this type in the database - * - * @var integer - * @since 1.0 - */ - protected $BOCount = 0; - - /** - * The field name to sort the list by (optional, default is OID) - * - * @var string - * @since 1.0 - */ - protected $sort; - - /** - * The order to sort the list by (optional, should be ASC or DESC, default is ASC) - * - * @var string - * @since 1.0 - */ - protected $order; - - /** - * The name of the BO field to filter the list by (optional) - * - * @var string - * @since 1.0 - */ - protected $filterField; - - /** - * The value of the filterField to filter by (optional) - * - * @var string - * @since 1.0 - */ - protected $filterValue; - - /** - * Trace logger - * - * @var Alpha\Util\Logging\Logger - * @since 1.0 - */ - private static $logger = null; - - /** - * Constructor to set up the object - * - * @param string $visibility - * @since 1.0 - */ - public function __construct($visibility='Admin') - { - self::$logger = new Logger('ListController'); - self::$logger->debug('>>__construct()'); - - $config = ConfigProvider::getInstance(); - - // ensure that the super class constructor is called, indicating the rights group - parent::__construct($visibility); - - self::$logger->debug('<<__construct'); - } - - /** - * 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 = ''; - - try { - if (isset($params['ActiveRecordType'])) { - $ActiveRecordType = urldecode($params['ActiveRecordType']); - $this->activeRecordType = $ActiveRecordType; - } else { - throw new IllegalArguementException('No ActiveRecord available to create!'); - } - - if (class_exists($ActiveRecordType)) - $this->BO = new $ActiveRecordType(); - else - throw new IllegalArguementException('No ActiveRecord available to create!'); - - $this->BOView = View::getInstance($this->BO); - - // TODO: order and sort not defined in the route in FrontController - if (isset($params['order'])) { - if($params['order'] == 'ASC' || $params['order'] == 'DESC') - $this->order = $params['order']; - else - throw new IllegalArguementException('Order value ['.$params['order'].'] provided is invalid!'); - } - - if (isset($params['sort'])) - $this->sort = $params['sort']; - - } catch (IllegalArguementException $e) { - self::$logger->error($e->getMessage()); - } - - $this->BOView = View::getInstance($this->BO); - - $body .= View::displayPageHead($this); - - $message = $this->getStatusMessage(); - if (!empty($message)) - $body .= $message; - - $body .= $this->renderBodyContent(); - - $body .= View::displayPageFoot($this); - - self::$logger->debug('< 'text/html')); - } - - /** - * Handle DELETE requests - * - * @param Alpha\Util\Http\Request $request - * @return Alpha\Util\Http\Response - * @since 1.0 - */ - public function doDELETE($request) - { - self::$logger->debug('>>doDELETE($request=['.var_export($request, true).'])'); - - $params = $request->getParams(); - - $body = ''; - - try { - // check the hidden security fields before accepting the form data - if (!$this->checkSecurityFields()) { - throw new SecurityException('This page cannot accept post data from remote servers!'); - self::$logger->debug('<activeRecordType = $ActiveRecordType; - } else { - throw new IllegalArguementException('No ActiveRecord available to create!'); - } - - if (isset($params['order'])) { - if ($params['order'] == 'ASC' || $params['order'] == 'DESC') - $this->order = $params['order']; - else - throw new IllegalArguementException('Order value ['.$params['order'].'] provided is invalid!'); - } - - if (isset($params['sort'])) - $this->sort = $params['sort']; - - if (!empty($params['deleteOID'])) { - if (!Validator::isInteger($params['deleteOID'])) - throw new IllegalArguementException('Invalid deleteOID ['.$params['deleteOID'].'] provided on the request!'); - - try { - $temp = new $ActiveRecordType(); - $temp->load($params['deleteOID']); - - ActiveRecord::begin(); - $temp->delete(); - self::$logger->action('Deleted an instance of '.$this->activeRecordType.' with id '.$params['deleteOID']); - ActiveRecord::commit(); - - $body .= View::displayPageHead($this); - - $body .= View::displayUpdateMessage($this->activeRecordType.' '.$params['deleteOID'].' deleted successfully.'); - - $body .= $this->renderBodyContent(); - } catch (AlphaException $e) { - self::$logger->error($e->getMessage()); - $body .= View::displayErrorMessage('Error deleting the BO of OID ['.$params['deleteOID'].'], check the log!'); - ActiveRecord::rollback(); - } - - ActiveRecord::disconnect(); - } - } catch (SecurityException $e) { - $body .= View::displayErrorMessage($e->getMessage()); - self::$logger->warn($e->getMessage()); - } catch (IllegalArguementException $e) { - $body .= View::displayErrorMessage($e->getMessage()); - self::$logger->error($e->getMessage()); - } - - $body .= View::displayPageFoot($this); - - self::$logger->debug('< 'text/html')); - } - - /** - * Sets up the title etc. and pagination start point - * - * @since 1.0 - */ - public function before_displayPageHead_callback() - { - // set up the title and meta details - if (!isset($this->title)) - $this->setTitle('Listing all '.$this->activeRecordType); - if (!isset($this->description)) - $this->setDescription('Page listing all '.$this->activeRecordType.'.'); - if (!isset($this->keywords)) - $this->setKeywords('list,all,'.$this->activeRecordType); - // set the start point for the list pagination - if ($this->request->getParam('start') != null) - $this->startPoint = $this->request->getParam('start'); - } - - /** - * Method to display the page footer with pageination links - * - * @return string - * @since 1.0 - */ - public function before_displayPageFoot_callback() - { - $html = $this->renderPageLinks(); - - $html .= '
    '; - - return $html; - } - - /** - * Method for rendering the pagination links - * - * @return string - * @since 1.0 - * @todo review how the links are generated - */ - protected function renderPageLinks() - { - $config = ConfigProvider::getInstance(); - - $html = ''; - - $end = (($this->startPoint-1)+$config->get('app.list.page.amount')); - - if ($end > $this->BOCount) - $end = $this->BOCount; - - if ($this->BOCount > 0) { - $html .= '
      '; - } else { - $html .= '

      The list is empty.  

      '; - - return $html; - } - - if ($this->startPoint > 1) { - // handle secure URLs - if ($this->request->getParam('token', null) != null) - $html .= '
    • <<-Previous
    • '; - else - $html .= '
    • startPoint-$config->get('app.list.page.amount')).'"><<-Previous
    • '; - } elseif ($this->BOCount > $config->get('app.list.page.amount')){ - $html .= '
    • <<-Previous
    • '; - } - - $page = 1; - - for ($i = 0; $i < $this->BOCount; $i+=$config->get('app.list.page.amount')) { - if ($i != ($this->startPoint-1)) { - // handle secure URLs - if ($this->request->getParam('token', null) != null) - $html .= '
    • '.$page.'
    • '; - else - $html .= '
    • '.$page.'
    • '; - } elseif ($this->BOCount > $config->get('app.list.page.amount')) { - $html .= '
    • '.$page.'
    • '; - } - - $page++; - } - - if ($this->BOCount > $end) { - // handle secure URLs - if ($this->request->getParam('token', null) != null) - $html .= '
    • Next->>
    • '; - else - $html .= '
    • startPoint+$config->get('app.list.page.amount')). - '">Next->>
    • '; - } elseif ($this->BOCount > $config->get('app.list.page.amount')) { - $html .= '
    • Next->>
    • '; - } - - $html .= '
    '; - - return $html; - } - - /** - * Method to display the main body HTML for this page - * - * @return string - * @since 1.0 - */ - protected function renderBodyContent() - { - $config = ConfigProvider::getInstance(); - - $body = ''; - - // get all of the BOs and invoke the listView on each one - $className = $this->activeRecordType; - $temp = new $className; - - if (isset($this->filterField) && isset($this->filterValue)) { - if (isset($this->sort) && isset($this->order)) { - $objects = $temp->loadAllByAttribute($this->filterField, $this->filterValue, $this->startPoint-1, $config->get('app.list.page.amount'), - $this->sort, $this->order); - } else { - $objects = $temp->loadAllByAttribute($this->filterField, $this->filterValue, $this->startPoint-1, $config->get('app.list.page.amount')); - } - - $this->BOCount = $temp->getCount(array($this->filterField), array($this->filterValue)); - } else { - if (isset($this->sort) && isset($this->order)) - $objects = $temp->loadAll($this->startPoint-1, $config->get('app.list.page.amount'), $this->sort, $this->order); - else - $objects = $temp->loadAll($this->startPoint-1, $config->get('app.list.page.amount')); - - $this->BOCount = $temp->getCount(); - } - - ActiveRecord::disconnect(); - - $body .= View::renderDeleteForm($this->request->getURI()); - - foreach ($objects as $object) { - $temp = View::getInstance($object); - $fields = array('formAction' => $this->request->getURI()); - $body .= $temp->listView($fields); - } - - return $body; - } -} - -?> \ No newline at end of file diff --git a/Alpha/Controller/SequenceController.php b/Alpha/Controller/SequenceController.php index a361240c..da1049da 100644 --- a/Alpha/Controller/SequenceController.php +++ b/Alpha/Controller/SequenceController.php @@ -53,7 +53,7 @@ * * */ -class SequenceController extends ListController implements ControllerInterface +class SequenceController extends ActiveRecordController implements ControllerInterface { /** * Trace logger diff --git a/Alpha/View/ArticleCommentView.php b/Alpha/View/ArticleCommentView.php index cfaf40ae..aa4d18f2 100644 --- a/Alpha/View/ArticleCommentView.php +++ b/Alpha/View/ArticleCommentView.php @@ -183,7 +183,7 @@ public function editView($fields=array()) $temp = new Button($js, "Delete", "deleteBut"); $html .= $temp->render(); $html .= '  '; - $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ListController&ActiveRecordType='.get_class($this->BO))."'",'Back to List','cancelBut'); + $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'",'Back to List','cancelBut'); $html .= $temp->render(); $html .= ''; diff --git a/Alpha/View/ArticleView.php b/Alpha/View/ArticleView.php index 91822ec2..40557ce1 100644 --- a/Alpha/View/ArticleView.php +++ b/Alpha/View/ArticleView.php @@ -152,7 +152,7 @@ public function editView($fields=array()) $button = new Button($js, "Delete", "deleteBut"); $fields['deleteButton'] = $button->render(); - $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ListController&ActiveRecordType='.get_class($this->BO))."'", "Back to List", "cancelBut"); + $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'", "Back to List", "cancelBut"); $fields['cancelButton'] = $button->render(); $tags = array(); diff --git a/Alpha/View/Renderer/Html/RendererProviderHTML.php b/Alpha/View/Renderer/Html/RendererProviderHTML.php index 6405f001..8ac7db54 100644 --- a/Alpha/View/Renderer/Html/RendererProviderHTML.php +++ b/Alpha/View/Renderer/Html/RendererProviderHTML.php @@ -184,7 +184,7 @@ public function editView($fields=array()) $button = new Button($js, "Delete", "deleteBut"); $fields['deleteButton'] = $button->render(); - $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ListController&ActiveRecordType='.get_class($this->BO))."'", "Back to List", "cancelBut"); + $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'", "Back to List", "cancelBut"); $fields['cancelButton'] = $button->render(); // buffer security fields to $formSecurityFields variable @@ -435,7 +435,7 @@ public function adminView($fields=array()) // list all button if ($this->BO->checkTableExists()) { - $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\\Controller\\ListController&ActiveRecordType='.get_class($this->BO))."'", "List All", "list".stripslashes(get_class($this->BO))."But"); + $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'", "List All", "list".stripslashes(get_class($this->BO))."But"); $fields['listButton'] = $button->render(); } else { $fields['listButton'] = ''; diff --git a/test/Alpha/Test/Controller/ListControllerTest.php b/test/Alpha/Test/Controller/ListControllerTest.php deleted file mode 100644 index d18088f4..00000000 --- a/test/Alpha/Test/Controller/ListControllerTest.php +++ /dev/null @@ -1,118 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
    - * Redistribution and use in source and binary forms, with or
    - * without modification, are permitted provided that the
    - * following conditions are met:
    - *
    - * * Redistributions of source code must retain the above
    - *   copyright notice, this list of conditions and the
    - *   following disclaimer.
    - * * Redistributions in binary form must reproduce the above
    - *   copyright notice, this list of conditions and the
    - *   following disclaimer in the documentation and/or other
    - *   materials provided with the distribution.
    - * * Neither the name of the Alpha Framework nor the names
    - *   of its contributors may be used to endorse or promote
    - *   products derived from this software without specific
    - *   prior written permission.
    - *
    - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
    - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
    - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
    - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    - * 
    - * - */ -class ListControllerTest extends ControllerTestCase -{ - /** - * Testing the doGET method - */ - public function testDoGET() - { - $person1 = $this->createPersonObject('person-one'); - $person1->save(); - $person2 = $this->createPersonObject('person-two'); - $person2->save(); - - $front = new FrontController(); - - $request = new Request(array('method' => 'GET', 'URI' => '/listall/'.urlencode('Alpha\Model\Person'))); - $response = $front->process($request); - - $this->assertEquals(200, $response->getStatus(), 'Testing the doGET method'); - $this->assertEquals('text/html', $response->getHeader('Content-Type'), 'Testing the doGET method'); - - $request = new Request(array('method' => 'GET', 'URI' => '/listall/'.urlencode('Alpha\Model\Person').'/0/1')); - $response = $front->process($request); - - $this->assertEquals(200, $response->getStatus(), 'Testing the doGET method'); - $this->assertEquals('text/html', $response->getHeader('Content-Type'), 'Testing the doGET method'); - } - - public function testDoDELETE() - { - $person = $this->createPersonObject('person-three'); - $person->save(); - - $front = new FrontController(); - $controller = new ListController(); - - $securityParams = $controller->generateSecurityFields(); - - $person = $this->createPersonObject('test'); - $person->save(); - - $params = array('deleteOID' => $person->getOID(), 'var1' => $securityParams[0], 'var2' => $securityParams[1]); - - $request = new Request(array('method' => 'DELETE', 'URI' => '/listall/'.urlencode('Alpha\Model\Person'), 'params' => $params)); - - $response = $front->process($request); - - $this->assertEquals(200, $response->getStatus(), 'Testing the doDELETE method'); - - $person2 = new Person(); - - try { - $person2->load($person->getOID());echo "11\n"; - $this->fail('Confirming that the Person record has been deleted'); - } catch (RecordNotFoundException $e) { - $this->assertEquals('Failed to load object of OID [00000000003] not found in database.', $e->getMessage()); - } - } -} - -?> \ No newline at end of file