Alpha Framework alpha--controller
[ class tree: alpha--controller ] [ index: alpha--controller ] [ all elements ]

Source for file ViewArticlePDF.php

Documentation is available at ViewArticlePDF.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/AlphaConfig.inc';
  6.     $config AlphaConfig::getInstance();
  7. }
  8.  
  9. require_once $config->get('sysRoot').'alpha/util/TCPDFFacade.inc';
  10. require_once $config->get('sysRoot').'alpha/util/AlphaMarkdown.inc';
  11. require_once $config->get('sysRoot').'alpha/controller/AlphaController.inc';
  12. require_once $config->get('sysRoot').'alpha/model/ArticleObject.inc';
  13.  
  14. /**
  15.  * 
  16.  * Controller used to display PDF version of an article where the title is provided in GET vars
  17.  * 
  18.  * @package alpha::controller
  19.  * @since 1.0
  20.  * @author John Collins <dev@alphaframework.org>
  21.  * @version $Id: ViewArticlePDF.php 1453 2011-12-04 15:12:54Z johnc $
  22.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  23.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  24.  *  All rights reserved.
  25.  * 
  26.  *  <pre>
  27.  *  Redistribution and use in source and binary forms, with or
  28.  *  without modification, are permitted provided that the
  29.  *  following conditions are met:
  30.  * 
  31.  *  * Redistributions of source code must retain the above
  32.  *    copyright notice, this list of conditions and the
  33.  *    following disclaimer.
  34.  *  * Redistributions in binary form must reproduce the above
  35.  *    copyright notice, this list of conditions and the
  36.  *    following disclaimer in the documentation and/or other
  37.  *    materials provided with the distribution.
  38.  *  * Neither the name of the Alpha Framework nor the names
  39.  *    of its contributors may be used to endorse or promote
  40.  *    products derived from this software without specific
  41.  *    prior written permission.
  42.  *   
  43.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  44.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  45.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  46.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  47.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  48.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  49.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  50.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  51.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  52.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  53.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  54.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56.  *  </pre>
  57.  *  
  58.  */
  59. class ViewArticlePDF extends AlphaController {
  60.     /**
  61.      * Trace logger
  62.      * 
  63.      * @var Logger 
  64.      * @since 1.0
  65.      */
  66.     private static $logger null;
  67.     
  68.     /**
  69.      * The type of BO to serve as a PDF
  70.      * 
  71.      * @var string 
  72.      * @since 1.0
  73.      */
  74.     protected $BOName = 'ArticleObject';
  75.                             
  76.     /**
  77.      * Constructor to set up the object
  78.      * 
  79.      * @since 1.0
  80.      */
  81.     public function __construct({
  82.         self::$logger new Logger('ViewArticlePDF');
  83.         self::$logger->debug('>>__construct()');
  84.         
  85.         global $config;
  86.         
  87.         // ensure that the super class constructor is called, indicating the rights group
  88.         parent::__construct('Public');
  89.         
  90.         self::$logger->debug('<<__construct');
  91.     }
  92.     
  93.     /**
  94.      * Handle GET requests
  95.      * 
  96.      * @param array $params 
  97.      * @since 1.0
  98.      * @throws ResourceNotFoundException
  99.      */
  100.     public function doGET($params{
  101.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  102.         
  103.         global $config;
  104.         
  105.         try {
  106.             // ensure that a title is provided
  107.             if (isset($params['title'])) {
  108.                 $title str_replace('_'' '$params['title']);
  109.             }else{
  110.                 throw new IllegalArguementException('Could not load the article as a title was not supplied!');
  111.             }
  112.             
  113.             $this->BO = new $this->BOName;
  114.             $this->BO->loadByAttribute('title'$title);
  115.             
  116.             AlphaDAO::disconnect();
  117.             
  118.             $pdf new TCPDFFacade($this->BO);
  119.             
  120.         }catch(IllegalArguementException $e{
  121.             self::$logger->error($e->getMessage());
  122.             throw new ResourceNotFoundException($e->getMessage());
  123.         }catch(BONotFoundException $e{
  124.             self::$logger->error($e->getMessage());
  125.             throw new ResourceNotFoundException($e->getMessage());
  126.         }
  127.         
  128.         self::$logger->debug('<<doGET');
  129.     }
  130.     
  131.     /**
  132.      * Handle POST requests
  133.      * 
  134.      * @param array $params 
  135.      * @since 1.0
  136.      */
  137.     public function doPOST($params{
  138.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  139.         
  140.         self::$logger->debug('<<doPOST');        
  141.     }
  142. }
  143.  
  144. // now build the new controller
  145. if(basename($_SERVER['PHP_SELF']== 'ViewArticlePDF.php'{
  146.     $controller new ViewArticlePDF();
  147.     
  148.     if(!empty($_POST)) {            
  149.         $controller->doPOST($_REQUEST);
  150.     }else{
  151.         $controller->doGET($_GET);
  152.     }
  153. }
  154.  
  155. ?>

Documentation generated on Tue, 13 Dec 2011 20:27:47 +0000 by phpDocumentor 1.4.3