/content/code/trunk/modules/mod_artofcontent_docman/helper.php
PHP | 90 lines | 38 code | 11 blank | 41 comment | 7 complexity | 6db136d598b95be55a0e14f0f2f5632b MD5 | raw file
- <?php
- /**
- * @version $Id:combolayout.php 2547 2007-11-10 04:37:15Z masterchief $
- * @package NewLifeInIT
- * @subpackage mod_artofcontent_docman
- * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
- * @author Andrew Eddie <andrew.eddie@newlifeinit.com>
- * @link http://www.theartofjoomla.com/extensions/artof-content.html
- */
- // No direct access.
- defined('JPATH_BASE') or die();
- /**
- * Artof Content DocMAN module helper.
- *
- * @package NewLifeInIT
- * @subpackage mod_artofcontent_docman
- * @since 1.0
- */
- class modArtofContentDocManHelper
- {
- /**
- * Get the DOCman category id from the category params.
- *
- * @param int $id The category or article id.
- * @param string $view The name of the view.
- *
- * @return int
- * @since 1.0
- * @throws Exception on error.
- */
- public static function getCategoryId($id, $view)
- {
- // Validate inputs.
- if (empty($id)) {
- return 0;
- }
- // Initialise variables.
- $db = JFactory::getDbo();
- if ($view == 'article') {
- $query = 'SELECT c.params' .
- ' FROM #__categories AS c' .
- ' INNER JOIN #__content AS a ON a.catid = c.id' .
- ' WHERE a.id = '.(int) $id;
- }
- else {
- $query = 'SELECT c.params' .
- ' FROM #__categories AS c' .
- ' WHERE c.id = '.(int) $id;
- }
- $db->setQuery($query);
- $params = $db->loadResult();
- if ($db->getErrorNum()) {
- throw new Exception($db->getErrorMsg());
- }
- $params = new JParameter($params);
- return $params->get('docman_category_id');
- }
- /**
- * Truncates text blocks over the specified character limit. This
- * method is UTF-8 safe.
- *
- * @param string $text The text to truncate.
- * @param int $length The maximum length of the text.
- * @param string $append An optional string to append (eg, '...') to the truncated string.
- *
- * @return string The truncated text.
- * @since 7-Oct-2010
- */
- public function truncate($text, $length = 0, $append = '')
- {
- // Truncate the item text if it is too long.
- if ($length > 0 && JString::strlen($text) > $length) {
- $text = JString::substr($text, 0, $length);
- $text = $text.$append;
- }
- return $text;
- }
- }