/pdf/code/trunk/administrator/components/com_artofpdf/controllers/pdf.php
PHP | 174 lines | 82 code | 25 blank | 67 comment | 9 complexity | 866949a4e87aa9ffb5b64a93288a988f MD5 | raw file
- <?php
- /**
- * @version $Id: pdf.php 278 2010-09-14 11:11:09Z eddieajau $
- * @package NewLifeInIT
- * @subpackage com_artofpdf
- * @copyright Copyright 2010 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License version 2 or later.
- * @link http://www.theartofjoomla.com
- */
- // No direct access
- defined('_JEXEC') or die;
- juimport('joomla.application.component.controllerform');
- /**
- * ArtofPdf display helper.
- *
- * @package NewLifeInIT
- * @subpackage com_artofpdf
- * @since 1.0
- */
- class ArtofPdfControllerPdf extends JControllerForm
- {
- /**
- * Method to add a new record.
- *
- * @return void
- * @since 1.0
- */
- public function add()
- {
- // Initialise variables.
- $tmpl = JRequest::getString('tmpl');
- $layout = JRequest::getString('layout', 'edit');
- $append = '';
- // Setup redirect info.
- if ($tmpl) {
- $append .= '&tmpl='.$tmpl;
- }
- if ($layout) {
- $append .= '&layout='.$layout;
- }
- // Redirect to the edit screen.
- $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$append, false));
- }
- /**
- * Method to check if you can add a new record.
- *
- * Extended classes can override this if necessary.
- *
- * @param array An array of input data.
- *
- * @return boolean
- * @since 1.0
- */
- protected function allowAdd($data = array())
- {
- return true;
- }
- /**
- * Method to check if you can add a new record.
- *
- * Extended classes can override this if necessary.
- *
- * @param array An array of input data.
- * @param string The name of the key for the primary key.
- *
- * @return boolean
- * @since 1.0
- */
- protected function allowEdit($data = array(), $key = 'id')
- {
- return true;
- }
- /**
- * Make the selected PDFs
- *
- * @return void
- * @since 1.0
- */
- public function make()
- {
- // Check for request forgeries.
- JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
- // Set the redirect for this action.
- $this->setRedirect(JRoute::_('index.php?option=com_artofpdf&view=pdfs', false));
- // Initialise variables.
- $pks = JRequest::getVar('cid', array(), 'post', 'array');
- // Check that the array is populated.
- if (empty($pks)) {
- $this->setMessage(JText::_('COM_ARTOFPDF_ERROR_NO_PDFS'), 'error');
- return false;
- }
- // Load the model.
- $model = $this->getModel();
- $result = true;
- try
- {
- // Loop through all the PDF's
- foreach ($pks as $pk)
- {
- if ($pdf = $model->getItem($pk)) {
- // Transform the data into an assoc array.
- $data = json_decode($pdf->data, true);
- // Loop through the types of data we have.
- foreach ($data as $type => $content)
- {
- // Load the model for the type.
- if ($subModel = $this->getModel($type)) {
- // Load the view
- if ($view = $this->getView($type, 'html')) {
- // Push the PDF data into the model.
- $subModel->setContent($content);
- // Push the model into the view.
- $view->setModel($subModel, true);
- // Push the content into the view.
- $view->content = $content;
- // Get the view output
- ob_start();
- $view->display();
- $buffer = ob_get_contents();
- ob_end_clean();
- $model->make($pdf, $buffer);
- }
- else {
- JError::raiseWarning(500, JText::sprintf('COM_ARTOFPDF_ERROR_VIEW_NOT_FOUND', $type));
- $result = false;
- }
- }
- else {
- JError::raiseWarning(500, JText::sprintf('COM_ARTOFPDF_ERROR_MODEL_NOT_FOUND', $type));
- $result = false;
- }
- }
- }
- else {
- JError::raiseWarning(500, JText::sprintf('COM_ARTOFPDF_ERROR_PDF_NOT_FOUND', $pk));
- $result = false;
- }
- }
- }
- catch (Exception $e)
- {
- // Catch any exceptions within the PDF making process.
- $this->setMessage($e->getMessage, 'error');
- return false;
- }
- $this->setMessage(JText::_('COM_ARTOFPDF_SUCCESS_MAKE'));
- return $result;
- }
- }