Location: PHPKode > projects > injooosm > administrator/components/com_injooosm/models/config.php
<?php
/**
 * Joomla! 1.5 component injooosm
 *
 * @version $Id: config.php 2009-11-22 14:03:00$
 * @author Christian Knorr
 * @package injooosm
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');
/**
 * Model Class Configuration
 */
class injooosmModelConfig extends JModel  {
    /**
     * 
     */
    function __construct() {
		parent::__construct();
    }

    /**
     *
     * @return boolean
     */
	function cleanOSMconfig($row) {
// die($this->cfg->map);
		$newarray=array();
		$newosmopt="";
		$tmposmopt=array();
		$nothingwaschanged = true;
		while (list($key, $value) = each($row)) {
			if ($key == "osm_default_map") {
				$osm_default_map = ((int)$value +1);
				continue;
			}
			if (preg_match('/osm_allow_map_/',$key))
				$tmposmopt[] = $value;
			else
				$newarray[$key] = ($value);
		}
		for ($i=0;$i<9;$i++) {
			if (isset($tmposmopt[$i])) {
				$newosmopt .= $tmposmopt[$i];
				$nothingwaschanged = false;
			}
			else
				$newosmopt .= 0;
		}
// Schreibe OSM-Config nur wenn es verändert wurde,
// sonst geht sie verloren, wenn map nicht auf 'osm'
		if (($newarray['map'] == 'osm') AND ($nothingwaschanged == false) )
			$newarray['osm_allow_map'] = (int)($newosmopt.$osm_default_map);
		return ($newarray);
	}

    /**
     *
     * @return boolean
     */
    function saveConfig()  {

        // get post data
        $row =& JRequest::get( 'post' );
	// Bereinige $row um OSM-Available Map
	$row = $this->cleanOSMconfig($row);
        $table = $this->getTable( 'osm_config' );
        $table->bind( $row );

        if (!$table->store()) {
            return JError::raiseWarning( $table->getError() );
        }
        return TRUE;

    }
    /**
     *
     * @global object $mainframe
     * @return array
     */
    function getContent()  {
        global $mainframe;

        $db =& JFactory::getDBO();

        $query = "SELECT id, title FROM #__content WHERE"
                . "\n sectionid='0'"
                . "\n AND catid='0'"
                . "\n AND state='1'";

        $db->setQuery($query);
        $result = $db->loadObjectList();

        if ($db->getErrorNum()) {
			echo $db->stderr();
			return false;
		}

        return $result;
    }

    /**
     *
     * @global object $mainframe
     * @return boolean
     */
    function installCleanDB()  {
        global $mainframe;

        $db =& JFactory::getDBO();

        $file = JPath::clean(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_injooosm'.DS.'sql'.DS.'clean_install.sql');
        $buffer = file_get_contents($file);

        if($buffer === false) {
            return false;
        } else {
            jimport('joomla.installer.helper');
            $queries = JInstallerHelper::splitSql($buffer);

            foreach($queries as $query)  {
                $query = trim($query);
                if($query != '' && $query != '#') {
                    $db->setQuery($query);
                    $db->query();
                }
            }
		return true;
        }
        
    }

    /**
     *
     * @global object $mainframe
     * @return boolean
     */
    function updateDB()  {
        global $mainframe;

        $db =& JFactory::getDBO();

        $file = JPath::clean(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_injooosm'.DS.'sql'.DS.'update.sql');
        $buffer = file_get_contents($file);

        if($buffer === false) {
            return false;
        } else {
            jimport('joomla.installer.helper');
            $queries = JInstallerHelper::splitSql($buffer);

            foreach($queries as $query)  {
                $query = trim($query);
                if($query != '' && $query != '#') {
                    $db->setQuery($query);
                    $db->query();
                }
            }
		return true;
        }

    }

    function getTemplates()  {
        jimport('joomla.filesystem.file');

        $templates = JFolder::listFolderTree('../components/com_injooosm/assets/template','',1);
        return $templates;
    }
}
Return current item: injooosm