<commit_before><?php
/**
 * @version     $Id$
 * @category	Nooku
 * @package     Nooku_Server
 * @subpackage  Modules
 * @copyright   Copyright (C) 2011 Timble CVBA and Contributors. (http://www.timble.net).
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Listbox Template Helper
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/johnbell>
 * @category	Nooku
 * @package     Nooku_Server
 * @subpackage  Modules    
 */

class ComModulesTemplateHelperListbox extends KTemplateHelperListbox
{
	/**
	 * Customized to add a few attributes.
	 *
	 * @TODO propose making the onchange attribute the default?
	 * 
	 * @param 	array 	An optional array with configuration options
	 * @return	string	Html
	 * @see __call()
	 */
	protected function _listbox($config = array())
 	{
		$config = new KConfig($config);

		$config->append(array(
			//@TODO state isn't applied, work on patch later
			'state'		=> array(
				'application'	=> $config->application
			),
			'attribs'	=> array(
				'onchange' => 'this.form.submit()'
			)
		));

		return parent::_listbox($config);
 	}

 	/**
     * Generates a list over positions
     *
     * The list is the array over positions coming from the application template merged with the module positions currently in use
     * that may not be defined in the xml
     *
     * @param   array   An optional array with configuration options
     * @return  string  Html
     */
    public function positions($config = array())
    {
        $config = new KConfig($config);
        $config->append(array(
            'position' => 'left'
        ));
        
        $model = KFactory::get('admin::com.modules.model.modules');
        $query = KFactory::tmp('lib.koowa.database.query')
					->distinct()
				    ->select('template')
					->where('client_id', '=', (int)($model->getState()->application == 'admin'));

		//@TODO if com.templates is refactored to nooku, specifying the table name is no longer necessary
		$table		= KFactory::get('admin::com.templates.database.table.menu', array('name' => 'templates_menu'));
		$templates	= $table->select($query, KDatabase::FETCH_FIELD_LIST);
		$modules	= $model->getColumn('position');
		$positions	= $modules->getColumn('position');
		$root		= $model->getState()->application == 'admin' ? JPATH_ADMINISTRATOR : JPATH_ROOT;

        $template   = KFactory::tmp('admin::com.templates.model.templates')
                          ->application($model->getState()->application)
                          ->default(1)
                          ->getItem();

		foreach($template->positions as $position)
		{
			if(!in_array((string)$position, $positions)) {
				$positions[] = (string)$position;
			}
		}

		$positions = array_unique($positions);
		sort($positions);
        <commit_msg>re #86 no need to query the db anymore for what template to get<commit_after><?php
/**
 * @version     $Id$
 * @category	Nooku
 * @package     Nooku_Server
 * @subpackage  Modules
 * @copyright   Copyright (C) 2011 Timble CVBA and Contributors. (http://www.timble.net).
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

/**
 * Listbox Template Helper
 *
 * @author      <NAME> <http://nooku.assembla.com/profile/johnbell>
 * @category	Nooku
 * @package     Nooku_Server
 * @subpackage  Modules    
 */

class ComModulesTemplateHelperListbox extends KTemplateHelperListbox
{
	/**
	 * Customized to add a few attributes.
	 *
	 * @TODO propose making the onchange attribute the default?
	 * 
	 * @param 	array 	An optional array with configuration options
	 * @return	string	Html
	 * @see __call()
	 */
	protected function _listbox($config = array())
 	{
		$config = new KConfig($config);

		$config->append(array(
			//@TODO state isn't applied, work on patch later
			'state'		=> array(
				'application'	=> $config->application
			),
			'attribs'	=> array(
				'onchange' => 'this.form.submit()'
			)
		));

		return parent::_listbox($config);
 	}

 	/**
     * Generates a list over positions
     *
     * The list is the array over positions coming from the application template merged with the module positions currently in use
     * that may not be defined in the xml
     *
     * @param   array   An optional array with configuration options
     * @return  string  Html
     */
    public function positions($config = array())
    {
        $config = new KConfig($config);
        $config->append(array(
            'position' => 'left'
        ));
        
        $model      = KFactory::get('admin::com.modules.model.modules');
		$rowset     = $model->getColumn('position');
		$positions  = $rowset->getColumn('position');
		$root		= $model->getState()->application == 'admin' ? JPATH_ADMINISTRATOR : JPATH_ROOT;

        $template   = KFactory::tmp('admin::com.templates.model.templates')
                          ->application($model->getState()->application)
                          ->default(1)
                          ->getItem();

		foreach($template->positions as $position)
		{
			if(!in_array((string)$position, $positions)) {
				$positions[] = (string)$position;
			}
		}

		$positions = array_unique($positions);
		sort($positions);
        
{'fraction_non_alphanumeric': 0.14030418250950571, 'fraction_numerical': 0.002661596958174905, 'mean_word_length': 2.776740847092606, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, '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': '2893787', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1568, 'n_words': 388}