<commit_before><?php
###########################################################
# Copyright 2011 Daniel 'grindhold' Brendle and Team
#
# This file is part of Scoville.
#
# Scoville is free software: you can redistribute it and/or 
# modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation, either 
# version 3 of the License, or (at your option) any later 
# version.
#
# Scoville 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public 
# License along with Scoville. 
# If not, see http://www.gnu.org/licenses/.
###########################################################
namespace scv;

include_once 'core.php';

class SiteException extends \Exception{}
class WidgetException extends \Exception{}

class CompositeManager extends Singleton{
	private static $instance = null;
	
	/**
	 * Get Singleton Instance
	 * 
	 * Returns the singleton Instance of the Rightsmanager
	 * 
	 * @return RightsManager The rights manager
	 */
	public static function getInstance(){
		if (CompositeManager::$instance==null){
			CompositeManager::$instance = new CompositeManager();
			CompositeManager::$instance->init();
		}
		return CompositeManager::$instance;
	}
	
	protected function init(){}
	
	
	public function getFirstSite(){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT FIRST 1 SIT_ID, SIT_NAME, SIT_DESCRIPTION, SIT_SPACES, SIT_FILENAME FROM SITES ORDER BY SIT_ID;";
		$res=$db->query($core,$stmnt);
		if($set = $db->fetchArray($res)){
			$site = new Site();
			$site->setId($set['SIT_ID']);
			$site->setName($set['SIT_NAME']);
			$site->setDescription($set['SIT_DESCRIPTION']);
			$site->setFilename($set['SIT_FILENAME']);
			$site->setSpaces($set['SIT_SPACES']);
			return $site;
		}else{
			throw SiteException("GetFirstSite: There is no existing Site in the Database!");
		}
	}
	
	public function getSite($siteId){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT SIT_NAME, SIT_DESCRIPTION, SIT_SPACES, SIT_FILENAME FROM SITES WHERE SIT_ID = ? ;";
		$res=$db->query($core,$stmnt,array($siteId));
		if($set = $db->fetchArray($res)){
			$site = new Site();
			$site->setId($siteId);
			$site->setName($set['SIT_NAME']);
			$site->setDescription($set['SIT_DESCRIPTION']);
			$site->setFilename($set['SIT_FILENAME']);
			$site->setSpaces($set['SIT_SPACES']);
			return $site;
		}else{
			throw SiteException("Get: This Site does not exist in Database");
		}
	}
	
	public function getSitesMeta($withMinimap=false){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$ret = array();
		
		//Suboptimal, aber hoechstwahrscheinlich nicht performancekritisch
		$stmnt = "SELECT SIT_ID FROM SITES;";
		$res = $db->query($core,$stmnt);
		while($set= $db->fetchArray($res)){
			$site = $this->getSite($set['SIT_ID']);
			$ret[] = $site->getMeta($withMinimap);
		}
		return $ret;
	}
	
	public function getWidget($id){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT WGT_NAME, WGT_SIT_ID, WGT_MOD_ID, WGT_SPACE FROM WIDGETS WHERE WGT_ID = ?;";
		$res = $db->query($core,$stmnt,array($id));
		if ($set = $db->fetchArray($res)){
			$wgt = new Widget();
			$wgt->setId($id);
			$wgt->setName($set['WGT_NAME']);
			$wgt->setSiteId($set['WGT_SIT_ID']);
			$wgt->setModuleId($set['WGT_MOD_ID']);
			$wgt->setSpace($set['WGT_SPACE']);
			return $wgt;
		}else{
			throw new WidgetException("Get: There is now widget with the id $id");
		}
	}
	
	public function createWidget($moduleName,$name){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT MOD_ID FROM MODULES WHERE MOD_NAME = ? ";
		$res = $db->query($core,$stmnt, array($moduleName));
		if ($set = $db->fetchArray($res)){
			$moduleId = $set['MOD_ID'];
		}else{
			throw new WidgetException("GetWidgetsOfModule: This module is not installed or does not exist");
		}
		
		$widget = new Widget();
		$widget->setName($name);
		$widget->setModuleId($moduleId);
		$widget->store();
		return $widget->getId();
	}
	
	public function getWidgetsForSiteMeta($site){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$ret = array();
		for ($i = 1;$i< $site->getSpaces()+1 ; $i++){
			$ret[$i] = 0;
		}
		
		$stmnt = "SELECT WGT_ID, WGT_NAME, WGT_MOD_ID, WGT_SPACE FROM WIDGETS WHERE WGT_SIT_ID = ? ;";
		$res = $db->query($core,$stmnt,array($site->getId()));
		while($set = $db->fetchArray($res)){
			$ret[$set['WGT_SPACE']] = array("id"=>$set['WGT_ID'],"name"=>$set['WGT_NAME'],"mouledId"=>$set['WGT_MOD_ID']);
		}
		return $ret;
	} 
	
	public function getWidgetsOfModule($moduleName){
		$core = Core::getInstance();<commit_msg>BugFix: WidgetMeta returned field 'mouledId' instead of 'moduleId'<commit_after><?php
###########################################################
# Copyright 2011 Daniel 'grindhold' Brendle and Team
#
# This file is part of Scoville.
#
# Scoville is free software: you can redistribute it and/or 
# modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation, either 
# version 3 of the License, or (at your option) any later 
# version.
#
# Scoville 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public 
# License along with Scoville. 
# If not, see http://www.gnu.org/licenses/.
###########################################################
namespace scv;

include_once 'core.php';

class SiteException extends \Exception{}
class WidgetException extends \Exception{}

class CompositeManager extends Singleton{
	private static $instance = null;
	
	/**
	 * Get Singleton Instance
	 * 
	 * Returns the singleton Instance of the Rightsmanager
	 * 
	 * @return RightsManager The rights manager
	 */
	public static function getInstance(){
		if (CompositeManager::$instance==null){
			CompositeManager::$instance = new CompositeManager();
			CompositeManager::$instance->init();
		}
		return CompositeManager::$instance;
	}
	
	protected function init(){}
	
	
	public function getFirstSite(){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT FIRST 1 SIT_ID, SIT_NAME, SIT_DESCRIPTION, SIT_SPACES, SIT_FILENAME FROM SITES ORDER BY SIT_ID;";
		$res=$db->query($core,$stmnt);
		if($set = $db->fetchArray($res)){
			$site = new Site();
			$site->setId($set['SIT_ID']);
			$site->setName($set['SIT_NAME']);
			$site->setDescription($set['SIT_DESCRIPTION']);
			$site->setFilename($set['SIT_FILENAME']);
			$site->setSpaces($set['SIT_SPACES']);
			return $site;
		}else{
			throw SiteException("GetFirstSite: There is no existing Site in the Database!");
		}
	}
	
	public function getSite($siteId){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT SIT_NAME, SIT_DESCRIPTION, SIT_SPACES, SIT_FILENAME FROM SITES WHERE SIT_ID = ? ;";
		$res=$db->query($core,$stmnt,array($siteId));
		if($set = $db->fetchArray($res)){
			$site = new Site();
			$site->setId($siteId);
			$site->setName($set['SIT_NAME']);
			$site->setDescription($set['SIT_DESCRIPTION']);
			$site->setFilename($set['SIT_FILENAME']);
			$site->setSpaces($set['SIT_SPACES']);
			return $site;
		}else{
			throw SiteException("Get: This Site does not exist in Database");
		}
	}
	
	public function getSitesMeta($withMinimap=false){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$ret = array();
		
		//Suboptimal, aber hoechstwahrscheinlich nicht performancekritisch
		$stmnt = "SELECT SIT_ID FROM SITES;";
		$res = $db->query($core,$stmnt);
		while($set= $db->fetchArray($res)){
			$site = $this->getSite($set['SIT_ID']);
			$ret[] = $site->getMeta($withMinimap);
		}
		return $ret;
	}
	
	public function getWidget($id){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT WGT_NAME, WGT_SIT_ID, WGT_MOD_ID, WGT_SPACE FROM WIDGETS WHERE WGT_ID = ?;";
		$res = $db->query($core,$stmnt,array($id));
		if ($set = $db->fetchArray($res)){
			$wgt = new Widget();
			$wgt->setId($id);
			$wgt->setName($set['WGT_NAME']);
			$wgt->setSiteId($set['WGT_SIT_ID']);
			$wgt->setModuleId($set['WGT_MOD_ID']);
			$wgt->setSpace($set['WGT_SPACE']);
			return $wgt;
		}else{
			throw new WidgetException("Get: There is now widget with the id $id");
		}
	}
	
	public function createWidget($moduleName,$name){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$stmnt = "SELECT MOD_ID FROM MODULES WHERE MOD_NAME = ? ";
		$res = $db->query($core,$stmnt, array($moduleName));
		if ($set = $db->fetchArray($res)){
			$moduleId = $set['MOD_ID'];
		}else{
			throw new WidgetException("GetWidgetsOfModule: This module is not installed or does not exist");
		}
		
		$widget = new Widget();
		$widget->setName($name);
		$widget->setModuleId($moduleId);
		$widget->store();
		return $widget->getId();
	}
	
	public function getWidgetsForSiteMeta($site){
		$core = Core::getInstance();
		$db = $core->getDB();
		
		$ret = array();
		for ($i = 1;$i< $site->getSpaces()+1 ; $i++){
			$ret[$i] = 0;
		}
		
		$stmnt = "SELECT WGT_ID, WGT_NAME, WGT_MOD_ID, WGT_SPACE FROM WIDGETS WHERE WGT_SIT_ID = ? ;";
		$res = $db->query($core,$stmnt,array($site->getId()));
		while($set = $db->fetchArray($res)){
			$ret[$set['WGT_SPACE']] = array("id"=>$set['WGT_ID'],"name"=>$set['WGT_NAME'],"moduleId"=>$set['WGT_MOD_ID']);
		}
		return $ret;
	} 
	
	public function getWidgetsOfModule($moduleName){
		$core = Core::getInstance();
{'fraction_non_alphanumeric': 0.1907337483416675, 'fraction_numerical': 0.0018369221349117256, 'mean_word_length': 4.691056910569106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4179953', 'n_tokens_mistral': 3704, 'n_tokens_neox': 3353, 'n_words': 806}