PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/pdf/code/trunk/administrator/components/com_artofpdf/controllers/pdf.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 174 lines | 82 code | 25 blank | 67 comment | 9 complexity | 866949a4e87aa9ffb5b64a93288a988f MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: pdf.php 278 2010-09-14 11:11:09Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_artofpdf
  6. * @copyright Copyright 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License version 2 or later.
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // No direct access
  11. defined('_JEXEC') or die;
  12. juimport('joomla.application.component.controllerform');
  13. /**
  14. * ArtofPdf display helper.
  15. *
  16. * @package NewLifeInIT
  17. * @subpackage com_artofpdf
  18. * @since 1.0
  19. */
  20. class ArtofPdfControllerPdf extends JControllerForm
  21. {
  22. /**
  23. * Method to add a new record.
  24. *
  25. * @return void
  26. * @since 1.0
  27. */
  28. public function add()
  29. {
  30. // Initialise variables.
  31. $tmpl = JRequest::getString('tmpl');
  32. $layout = JRequest::getString('layout', 'edit');
  33. $append = '';
  34. // Setup redirect info.
  35. if ($tmpl) {
  36. $append .= '&tmpl='.$tmpl;
  37. }
  38. if ($layout) {
  39. $append .= '&layout='.$layout;
  40. }
  41. // Redirect to the edit screen.
  42. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$append, false));
  43. }
  44. /**
  45. * Method to check if you can add a new record.
  46. *
  47. * Extended classes can override this if necessary.
  48. *
  49. * @param array An array of input data.
  50. *
  51. * @return boolean
  52. * @since 1.0
  53. */
  54. protected function allowAdd($data = array())
  55. {
  56. return true;
  57. }
  58. /**
  59. * Method to check if you can add a new record.
  60. *
  61. * Extended classes can override this if necessary.
  62. *
  63. * @param array An array of input data.
  64. * @param string The name of the key for the primary key.
  65. *
  66. * @return boolean
  67. * @since 1.0
  68. */
  69. protected function allowEdit($data = array(), $key = 'id')
  70. {
  71. return true;
  72. }
  73. /**
  74. * Make the selected PDFs
  75. *
  76. * @return void
  77. * @since 1.0
  78. */
  79. public function make()
  80. {
  81. // Check for request forgeries.
  82. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  83. // Set the redirect for this action.
  84. $this->setRedirect(JRoute::_('index.php?option=com_artofpdf&view=pdfs', false));
  85. // Initialise variables.
  86. $pks = JRequest::getVar('cid', array(), 'post', 'array');
  87. // Check that the array is populated.
  88. if (empty($pks)) {
  89. $this->setMessage(JText::_('COM_ARTOFPDF_ERROR_NO_PDFS'), 'error');
  90. return false;
  91. }
  92. // Load the model.
  93. $model = $this->getModel();
  94. $result = true;
  95. try
  96. {
  97. // Loop through all the PDF's
  98. foreach ($pks as $pk)
  99. {
  100. if ($pdf = $model->getItem($pk)) {
  101. // Transform the data into an assoc array.
  102. $data = json_decode($pdf->data, true);
  103. // Loop through the types of data we have.
  104. foreach ($data as $type => $content)
  105. {
  106. // Load the model for the type.
  107. if ($subModel = $this->getModel($type)) {
  108. // Load the view
  109. if ($view = $this->getView($type, 'html')) {
  110. // Push the PDF data into the model.
  111. $subModel->setContent($content);
  112. // Push the model into the view.
  113. $view->setModel($subModel, true);
  114. // Push the content into the view.
  115. $view->content = $content;
  116. // Get the view output
  117. ob_start();
  118. $view->display();
  119. $buffer = ob_get_contents();
  120. ob_end_clean();
  121. $model->make($pdf, $buffer);
  122. }
  123. else {
  124. JError::raiseWarning(500, JText::sprintf('COM_ARTOFPDF_ERROR_VIEW_NOT_FOUND', $type));
  125. $result = false;
  126. }
  127. }
  128. else {
  129. JError::raiseWarning(500, JText::sprintf('COM_ARTOFPDF_ERROR_MODEL_NOT_FOUND', $type));
  130. $result = false;
  131. }
  132. }
  133. }
  134. else {
  135. JError::raiseWarning(500, JText::sprintf('COM_ARTOFPDF_ERROR_PDF_NOT_FOUND', $pk));
  136. $result = false;
  137. }
  138. }
  139. }
  140. catch (Exception $e)
  141. {
  142. // Catch any exceptions within the PDF making process.
  143. $this->setMessage($e->getMessage, 'error');
  144. return false;
  145. }
  146. $this->setMessage(JText::_('COM_ARTOFPDF_SUCCESS_MAKE'));
  147. return $result;
  148. }
  149. }