<commit_before><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

/**
 *
 * Course asset groups table class
 * 
 */
class CoursesTableAssetGroup extends JTable
{
	/**
	 * int(11) ID, primary key for course asset grouping table
	 * 
	 * @var integer
	 */
	var $id = NULL;

	/**
	 * int(11) Course unit id of this asset group (references #__course_units.gidNumber)
	 * 
	 * @var integer
	 */
	var $unit_id = NULL;

	/**
	 * varchar(255) Alias
	 * 
	 * @var string
	 */
	var $alias = NULL;

	/**
	 * varchar(255) Asset grouping title
	 * 
	 * @var string
	 */
	var $title = NULL;

	/**
	 * varchar(255) Asset group description
	 * 
	 * @var string
	 */
	var $description = NULL;

	/**
	 * int(11) Ordering
	 * 
	 * @var integer
	 */
	var $ordering = NULL;

	/**
	 * varchar(255) Asset group type
	 * 
	 * @var string
	 */
	var $parent = NULL;

	/**
	 * datetime Created date for unit
	 * 
	 * @var string
	 */
	var $created = NULL;

	/**
	 * int(11) Who created the unit (reference #__users.id)
	 * 
	 * @var integer
	 */
	var $created_by = NULL;

	/**
	 * tinyint(2)
	 * 
	 * @var integer
	 */
	var $state = NULL;

	/**
	 * Contructor method for JTable class
	 * 
	 * @param  database object
	 * @return void
	 */
	public function __construct(&$db)
	{
		parent::__construct('#__courses_asset_groups', 'id', $db);
	}

	/**
	 * Override the check function to do a little input cleanup
	 * 
	 * @return return true
	 */
	public function check()
	{
		$this->unit_id = intval($this->unit_id);
		if (!$this->unit_id) 
		{
			$this->setError(JText::_('Missing unit ID'));
			return false;
		}

		$this->title = trim($this->title);
		if (!$this->title) 
		{
			$this->setError(JText::_('Missing title'));
			return false;
		}

		if (!$this->alias)
		{
			$this->alias = strtolower($this->title);
		}
		$this->alias = preg_replace("/[^a-zA-Z0-9\-_]/", '', $this->alias);

		if (!$this->id)
		{
			$high = $this->getHighestOrder($this->unit_id, $this->parent);
			$this->ordering = ($high + 1);

			$this->state = ($this->state) ? $this->state : 1;

			$juser =& JFactory::getUser();
			$this->created = date('Y-m-d H:i:s', time());
			$this->created_by = $juser->get('id');
		}

		return true;
	}

	/**
	 * Get the last page in the ordering
	 * 
	 * @param      string  $offering_id    Course alias (cn)
	 * @return     integer
	 */
	public function getHighestOrder($unit_id, $parent=0)
	{
		$sql = "SELECT ordering from $this->_tbl WHERE `unit_id`=" . $this->_db->Quote(intval($unit_id)) . " AND `parent`=" . $this->_db->Quote(intval($parent)) . " ORDER BY ordering DESC LIMIT 1";
		$this->_db->setQuery($sql);
		return $this->_db->loadResult();
	}

	/**
	 * Build query method
	 * 
	 * @param  array $filters
	 * @return $query database query
	 */
	private function _buildQuery($filters=array())
	{
		$query  = " FROM $this->_tbl AS cag";
		$query .= " LEFT JOIN #__courses_offering_section_dates AS sd ON sd.scope='asset_group' AND sd.scope_id=cag.id";
		$query .= " LEFT JOIN #__courses_units AS cu ON cu.id = cag.unit_id";

		$where = array();

		if (isset($filters['section_id']) && $filters['section_id']) 
		{
			$where[] = "sd.section_id=" . $this->_db->Quote($filters['section_id']);
		}
		if (isset($filters['unit_id']) && $filters['unit_id']) 
		{
			$where[] = "cag.unit_id=" . $this->_db->Quote($filters['unit_id']);
		}<commit_msg>Bug fix to pull items without date entries<commit_after><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

/**
 *
 * Course asset groups table class
 * 
 */
class CoursesTableAssetGroup extends JTable
{
	/**
	 * int(11) ID, primary key for course asset grouping table
	 * 
	 * @var integer
	 */
	var $id = NULL;

	/**
	 * int(11) Course unit id of this asset group (references #__course_units.gidNumber)
	 * 
	 * @var integer
	 */
	var $unit_id = NULL;

	/**
	 * varchar(255) Alias
	 * 
	 * @var string
	 */
	var $alias = NULL;

	/**
	 * varchar(255) Asset grouping title
	 * 
	 * @var string
	 */
	var $title = NULL;

	/**
	 * varchar(255) Asset group description
	 * 
	 * @var string
	 */
	var $description = NULL;

	/**
	 * int(11) Ordering
	 * 
	 * @var integer
	 */
	var $ordering = NULL;

	/**
	 * varchar(255) Asset group type
	 * 
	 * @var string
	 */
	var $parent = NULL;

	/**
	 * datetime Created date for unit
	 * 
	 * @var string
	 */
	var $created = NULL;

	/**
	 * int(11) Who created the unit (reference #__users.id)
	 * 
	 * @var integer
	 */
	var $created_by = NULL;

	/**
	 * tinyint(2)
	 * 
	 * @var integer
	 */
	var $state = NULL;

	/**
	 * Contructor method for JTable class
	 * 
	 * @param  database object
	 * @return void
	 */
	public function __construct(&$db)
	{
		parent::__construct('#__courses_asset_groups', 'id', $db);
	}

	/**
	 * Override the check function to do a little input cleanup
	 * 
	 * @return return true
	 */
	public function check()
	{
		$this->unit_id = intval($this->unit_id);
		if (!$this->unit_id) 
		{
			$this->setError(JText::_('Missing unit ID'));
			return false;
		}

		$this->title = trim($this->title);
		if (!$this->title) 
		{
			$this->setError(JText::_('Missing title'));
			return false;
		}

		if (!$this->alias)
		{
			$this->alias = strtolower($this->title);
		}
		$this->alias = preg_replace("/[^a-zA-Z0-9\-_]/", '', $this->alias);

		if (!$this->id)
		{
			$high = $this->getHighestOrder($this->unit_id, $this->parent);
			$this->ordering = ($high + 1);

			$this->state = ($this->state) ? $this->state : 1;

			$juser =& JFactory::getUser();
			$this->created = date('Y-m-d H:i:s', time());
			$this->created_by = $juser->get('id');
		}

		return true;
	}

	/**
	 * Get the last page in the ordering
	 * 
	 * @param      string  $offering_id    Course alias (cn)
	 * @return     integer
	 */
	public function getHighestOrder($unit_id, $parent=0)
	{
		$sql = "SELECT ordering from $this->_tbl WHERE `unit_id`=" . $this->_db->Quote(intval($unit_id)) . " AND `parent`=" . $this->_db->Quote(intval($parent)) . " ORDER BY ordering DESC LIMIT 1";
		$this->_db->setQuery($sql);
		return $this->_db->loadResult();
	}

	/**
	 * Build query method
	 * 
	 * @param  array $filters
	 * @return $query database query
	 */
	private function _buildQuery($filters=array())
	{
		$query  = " FROM $this->_tbl AS cag";
		$query .= " LEFT JOIN #__courses_offering_section_dates AS sd ON sd.scope='asset_group' AND sd.scope_id=cag.id";
		if (isset($filters['section_id']) && $filters['section_id']) 
		{
			$query .= " AND sd.section_id=" . $this->_db->Quote($filters['section_id']);
		}
		$query .= " LEFT JOIN #__courses_units AS cu ON cu.id = cag.unit_id";

		$where = array();

		if (isset($filters['unit_id']) && $filters['unit_id']) 
		{
			$where[] = "cag.unit_id=" . $this->_db->Quote($filters['unit_id']);
		}
{'fraction_non_alphanumeric': 0.15643868701284444, 'fraction_numerical': 0.01031946426611044, 'mean_word_length': 3.1693363844393594, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3017239', 'n_tokens_mistral': 3403, 'n_tokens_neox': 2970, 'n_words': 886}