PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/content/code/trunk/modules/mod_artofcontent_docman/helper.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 90 lines | 38 code | 11 blank | 41 comment | 7 complexity | 6db136d598b95be55a0e14f0f2f5632b MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id:combolayout.php 2547 2007-11-10 04:37:15Z masterchief $
  4. * @package NewLifeInIT
  5. * @subpackage mod_artofcontent_docman
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @author Andrew Eddie <andrew.eddie@newlifeinit.com>
  9. * @link http://www.theartofjoomla.com/extensions/artof-content.html
  10. */
  11. // No direct access.
  12. defined('JPATH_BASE') or die();
  13. /**
  14. * Artof Content DocMAN module helper.
  15. *
  16. * @package NewLifeInIT
  17. * @subpackage mod_artofcontent_docman
  18. * @since 1.0
  19. */
  20. class modArtofContentDocManHelper
  21. {
  22. /**
  23. * Get the DOCman category id from the category params.
  24. *
  25. * @param int $id The category or article id.
  26. * @param string $view The name of the view.
  27. *
  28. * @return int
  29. * @since 1.0
  30. * @throws Exception on error.
  31. */
  32. public static function getCategoryId($id, $view)
  33. {
  34. // Validate inputs.
  35. if (empty($id)) {
  36. return 0;
  37. }
  38. // Initialise variables.
  39. $db = JFactory::getDbo();
  40. if ($view == 'article') {
  41. $query = 'SELECT c.params' .
  42. ' FROM #__categories AS c' .
  43. ' INNER JOIN #__content AS a ON a.catid = c.id' .
  44. ' WHERE a.id = '.(int) $id;
  45. }
  46. else {
  47. $query = 'SELECT c.params' .
  48. ' FROM #__categories AS c' .
  49. ' WHERE c.id = '.(int) $id;
  50. }
  51. $db->setQuery($query);
  52. $params = $db->loadResult();
  53. if ($db->getErrorNum()) {
  54. throw new Exception($db->getErrorMsg());
  55. }
  56. $params = new JParameter($params);
  57. return $params->get('docman_category_id');
  58. }
  59. /**
  60. * Truncates text blocks over the specified character limit. This
  61. * method is UTF-8 safe.
  62. *
  63. * @param string $text The text to truncate.
  64. * @param int $length The maximum length of the text.
  65. * @param string $append An optional string to append (eg, '...') to the truncated string.
  66. *
  67. * @return string The truncated text.
  68. * @since 7-Oct-2010
  69. */
  70. public function truncate($text, $length = 0, $append = '')
  71. {
  72. // Truncate the item text if it is too long.
  73. if ($length > 0 && JString::strlen($text) > $length) {
  74. $text = JString::substr($text, 0, $length);
  75. $text = $text.$append;
  76. }
  77. return $text;
  78. }
  79. }