class SearcherComponent extends Object
{
var $order_field = "bfs";
var $order_dir = "DESC";
var $controller = true;
var $sqlcondition = false;
var $sqlcolumn = false;
var $sqlfrom = "`cake_votes` AS `Vote`";
var $sqlgroupby = false;
var $sqljoin = false;
var $sql = false;
var $sqlorder;
var $sessionname = false;
var $arrjoin = array("descriptor" => 0, "cantonsum" => 0, "party" => 0, "association" => 0, "canton" => 0);
var $complexQueries = array("descriptor","party","association","canton");
var $votelist_properties = false;
public $searchform = array();
function startup(&$controller)
{
// Searchmod
$generalsearch = $controller->Session->read("generalsearch"); // Aus Session lesen
if(array_key_exists("searchmod",$_GET)){
$generalsearch["mod"] = $_GET["searchmod"];
$controller->Session->write("generalsearch",$generalsearch);
}
$this->sessionname = $generalsearch["mod"]."searchform";
$controller->helpers[] = "Db.Searcher";
$controller->searchform = $controller->Session->read($this->sessionname."FORM"); // Aus Session lesen
}
function load(&$controller){
// Searchform
if(array_key_exists("searchfilter", $_POST)){
$controller->searchform = $_POST;
$controller->Session->write($this->sessionname."FORM", $controller->searchform);
}
// Votelist Order
$votelist_properties = $controller->Session->read("votelist_properties");
if(array_key_exists("sortBy",$_GET)){
$this->order_field = $_GET["sortBy"];
if(array_key_exists("direction",$_GET)){
$this->order_dir = $_GET["direction"];
}
$votelist_properties = array("order_dir" => $this->order_dir, "order_field" => $this->order_field);
$controller->Session->write("votelist_properties",$votelist_properties);
}elseif(is_array($votelist_properties)){
$this->order_dir = $votelist_properties["order_dir"];
$this->order_field = $votelist_properties["order_field"];
}else{
$votelist_properties = array("order_dir" => $this->order_dir, "order_field" => $this->order_field);
}
$controller->set("votelist_properties",$votelist_properties);
}
function reload(&$controller){
// Searchform
if(array_key_exists("0",$controller->params["pass"])){
switch ($controller->params["pass"]["0"]){
case "addfilter":
$controller->searchform["data"]["Extsearch"] = $controller->params["data"]["Extsearch"];
$controller->searchform["data"]["Extsearch"]["elements"][] = "";
$controller->Session->write($this->sessionname."FORM",$controller->searchform);
break;
case "submitfilter":
$controller->searchform["data"]["Extsearch"] = $controller->params["data"]["Extsearch"];
$controller->Session->write($this->sessionname."FORM",$controller->searchform);
break;
case "delfilter":
$controller->searchform["data"]["Extsearch"] = $controller->params["data"]["Extsearch"];
if(array_key_exists(1,$controller->params["pass"])){
unset($controller->searchform["data"]["Extsearch"]["elements"][$controller->params["pass"]["1"]]);
}
$controller->Session->write($this->sessionname."FORM",$controller->searchform);
break;
default:
$controller->searchform = $controller->Session->read($this->sessionname."FORM");
break;
}
}
}
function getcondition($searchform, $show_all=false)
{
$link = "AND";
// Convert Searchform to SQL String
if(is_array($searchform)){
if($this->sessionname=="erwsearchform"){
if (!isset($searchform["data"]["Extsearch"])){
$searchform["data"] = array();
$searchform["data"]["Extsearch"] = array('elements' => array());
}
foreach($searchform["data"]["Extsearch"]["elements"] as $number => $field) {
if($field && array_key_exists($number.":value",$searchform["data"]["Extsearch"]) && array_key_exists($number.":link",$searchform["data"]["Extsearch"]) && array_key_exists($number.":operator",$searchform["data"]["Extsearch"])){
$value = $searchform["data"]["Extsearch"][$number.":value"];
$value = mysql_escape_string($value);
$operator = $this->translateOperator($searchform["data"]["Extsearch"][$number.":operator"]);
$link = $searchform["data"]["Extsearch"][$number.":link"];
if($value && $operator && $link){
switch ($field){
case "bfs":
if($operator=="LIKE"){
$this->sqlcondition .= "(`$field` LIKE \"$value\" OR `$field` LIKE \"$value.%\") $link ";
}else{
$this->sqlcondition .= "`$field` $operator \"$value\" $link ";
}
break;
case "signatures_invalid":
$this->sqlcondition .= "(`signatures_total` - `signatures_valid` $operator \"$value\") $link ";
break;
case "signatures":
$this->sqlcondition .= "(`signatures_valid $operator \"$value\") $link ";
break;
case "text": // Volltext
$this->sqlcondition .= "(`title_de` $operator \"%$value%\" OR `title_fr` $operator \"%$value%\" OR `description1` $operator \"%$value%\" OR `description2` $operator \"%$value%\" OR `description3` $operator \"%$value%\" OR `description4` $operator \"%$value%\" OR `title_de_common` LIKE \"%$value%\" OR `title_de_short` LIKE \"%$value%\" OR `initiator` LIKE \"%$value%\" OR `subtitle` $operator \"%$value%\") $link ";
break;
case "descriptor":
if(!$this->arrjoin["descriptor"]){
$this->sqlgroupby = "GROUP BY Vote.id";
}
$this->arrjoin["descriptor"]++;
$this->sqljoin .= " LEFT JOIN (
SELECT `Vote_Descriptor".$this->arrjoin["descriptor"]."`.vote_id, `Descriptor".$this->arrjoin["descriptor"]."`.descriptor
FROM cake_votes_descriptors AS `Vote_Descriptor".$this->arrjoin["descriptor"]."`
LEFT JOIN cake_descriptors AS `Descriptor".$this->arrjoin["descriptor"]."`
ON `Vote_Descriptor".$this->arrjoin["descriptor"]."`.descriptor_id = `Descriptor".$this->arrjoin["descriptor"]."`.id
) AS `Descriptor".$this->arrjoin["descriptor"]."`
ON Vote.id = `Descriptor".$this->arrjoin["descriptor"]."`.vote_id";
$this->sqlcondition .= "`Descriptor".$this->arrjoin["descriptor"]."`.descriptor $operator \"$value%\" $link ";
break;
case "year":
$this->sqlcondition .= "LEFT(fulldate,4) $operator \"$value\" $link ";
break;
case "cantonsum":
$this->sqlcondition .= "(`voteyes_canton_sum` $operator \"$value\") $link ";
break;
case "party":
if(!$this->arrjoin["party"]){
$this->sqlgroupby = "GROUP BY Vote.id";
}
$this->arrjoin["party"]++;
if($value!=9){
$sloganCondition = "AND `Slogan".$this->arrjoin["party"]."`.slogan = \"$value\") AND ";
}else{
$sloganCondition = "AND (`Slogan".$this->arrjoin["party"]."`.slogan = \"3\" OR ".
"`Slogan".$this->arrjoin["party"]."`.slogan = \"4\" OR ".
"`Slogan".$this->arrjoin["party"]."`.slogan = \"5\")) AND ";
}
list($party, $canton) = split(":",$operator);
$this->sqljoin .= " LEFT JOIN cake_slogans AS `Slogan".$this->arrjoin["party"]."`
ON `Vote`.id = `Slogan".$this->arrjoin["party"]."`.vote_id";
$this->sqlcondition .= "(`Slogan".$this->arrjoin["party"]."`.canton_id = \"$canton\"
AND `Slogan".$this->arrjoin["party"]."`.party_id = \"$party\" ".$sloganCondition;
break;
case "association":
if(!$this->arrjoin["association"]){
$this->sqlgroupby = "GROUP BY Vote.id";
}
$this->arrjoin["association"]++;
$this->sqljoin .= " LEFT JOIN cake_slogans AS `Association".$this->arrjoin["association"]."`
ON `Vote`.id = `Association".$this->arrjoin["association"]."`.vote_id";
$this->sqlcondition .= "(`Association".$this->arrjoin["association"]."`.party_id = \"$operator\"
AND `Association".$this->arrjoin["association"]."`.slogan = \"$value\") AND ";
break;
case "canton":
if(!$this->arrjoin["canton"]){
$this->sqlgroupby = "GROUP BY Vote.id";
}
$this->arrjoin["canton"]++;
if($value==1){$operatorValue = ">";}elseif($value==2){$operatorValue = "<";}
$this->sqljoin .= " LEFT JOIN (
SELECT `Vote_Canton".$this->arrjoin["canton"]."`.vote_id, `Vote_Canton".$this->arrjoin["canton"]."`.resultyes_abs, `Vote_Canton".$this->arrjoin["canton"]."`.resultno_abs, `Vote_Canton".$this->arrjoin["canton"]."`.canton_id
FROM cake_votes_cantons AS `Vote_Canton".$this->arrjoin["canton"]."`
) AS `Canton".$this->arrjoin["canton"]."`
ON Vote.id = `Canton".$this->arrjoin["canton"]."`.vote_id";
$this->sqlcondition .= "(`Canton".$this->arrjoin["canton"]."`.canton_id = $operator AND `Canton".$this->arrjoin["canton"]."`.resultyes_abs $operatorValue `Canton".$this->arrjoin["canton"]."`.resultno_abs) $link ";
break;
default:
if($searchform["data"]["Extsearch"][$number.":operator"] == "contain"){
$containSigns = "%";
}else{
$containSigns = "";
}
$this->sqlcondition .= "`$field` $operator \"$containSigns$value$containSigns\" $link ";
break;
}
}
}
}
}else{
if(!isset($searchform["data"]["Search"])){
$searchform["data"]["Search"] = array();
}
foreach($searchform["data"]["Search"] as $field => $value) {
if($value){
$value = mysql_escape_string($value);
switch ($field){
case "fulldate_from_year":
$this->sqlcondition .= " LEFT(fulldate,4) >= \"$value\" $link ";
break;
case "fulldate_to_year":
$this->sqlcondition .= " LEFT(fulldate,4) <= \"$value\" $link ";
break;
case "title_de":
$this->sqlcondition .= " (title_de LIKE \"%$value%\" OR title_de_common LIKE \"%$value%\" OR title_de_short LIKE \"%$value%\" ) $link ";
break;
case "fulltext":
$this->sqlcondition .= " (`title_de` LIKE \"%$value%\" OR `source` LIKE \"%$value%\" OR `literature` LIKE \"%$value%\" OR `title_fr` LIKE \"%$value%\" OR `description1` LIKE \"%$value%\" OR `description2` LIKE \"%$value%\" OR `description3` LIKE \"%$value%\" OR `description4` LIKE \"%$value%\" OR `title_de_common` LIKE \"%$value%\" OR `title_de_short` LIKE \"%$value%\" OR `initiator` LIKE \"%$value%\" OR `subtitle` LIKE \"%$value%\") $link ";
break;
case "bfs":
$this->sqlcondition .= "(`$field` LIKE \"$value\" OR `$field` LIKE \"$value.%\") $link ";
break;
case "lawtype_id":
$this->sqlcondition .= " `$field` LIKE \"$value\" $link ";
break;
case "descriptor_id":
$this->sqljoin .= " LEFT JOIN (
SELECT `Vote_Descriptor`.vote_id, `Descriptor`.descriptor
FROM cake_votes_descriptors AS `Vote_Descriptor`
LEFT JOIN cake_descriptors AS `Descriptor`
ON `Vote_Descriptor`.descriptor_id = `Descriptor`.id
) AS `Descriptor2`
ON Vote.id = `Descriptor2`.vote_id";
$this->sqlcondition .= "`Descriptor2`.descriptor LIKE \"$value%\" $link ";
$this->sqlgroupby = " GROUP BY Vote.id";
break;
}
}
}
}
}
if($this->order_field){
if($this->order_field == "voteyes_canton_sum"){
$newColumn= "IF (req_majority = 1 OR req_majority = 2,1,0) AS isreqmaiority, ";
$newOrder = "isreqmaiority DESC,";
}else{
$newColumn = "";
$newOrder = "";
}
$this->sqlcolumn = ", $newColumn IF(".$this->order_field." IS NULL, 1, 0) AS isitnull";
$sqlorderWhole = "ORDER BY isitnull ASC, $newOrder ".$this->order_field." ".$this->order_dir;
$newOrder = false;
}
if($link == "OR"){$cond = "1<1";}else{$cond = "1=1";}
if($show_all){
$state_filter = "";
}else{
$state_filter = " state = 1 AND";
}
$this->sql = "SELECT `Vote`.* ".$this->sqlcolumn." FROM ".$this->sqlfrom." ".$this->sqljoin." WHERE ".$state_filter." ".$this->sqlcondition." ".$cond." ".$this->sqlgroupby." ".$sqlorderWhole;
}
function imagineDuration($searchform){
$countSubquery = 0;
if(is_array($searchform)){
if($this->sessionname=="erwsearchform"){
if (!array_key_exists("Extsearch",$searchform)){
$searchform["Extsearch"] = array('elements' => array());
}
if(isset($searchform["Extsearch"]["elements"])){
foreach($searchform["Extsearch"]["elements"] as $number => $field) {
if(in_array($field, $this->complexQueries)){
$countSubquery++;
}
}
}
}
}
return($countSubquery);
}
function translateOperator($operator){
if($operator){
switch($operator){
case "equal":
return("LIKE");
break;
case "contain":
return("LIKE");
break;
case "bigger":
return(">");
break;
case "smaller":
return("<");
break;
default:
return($operator);
break;
}
}
}
public function get_year_options(){
$maxYear = date('Y');
$minYear = YEAR_OF_FIRST_VOTE;
$years = array();
for($i=$minYear;$i<=$maxYear;$i++){
$years[$i] = $i;
}
return $years;
}
}
?>
Strict Standards: Non-static method App::core() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 429
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Warning: Illegal string offset 'file' in /home/swissvotes/public_html/cake/libs/debugger.php on line 632
Warning: Illegal string offset 'line' in /home/swissvotes/public_html/cake/libs/debugger.php on line 632
Strict Standards: Non-static method App::core() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 429
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 398
Strict Standards: Non-static method Configure::read() should not be called statically in /home/swissvotes/public_html/cake/basics.php on line 233
Strict Standards: Non-static method Configure::getInstance() should not be called statically in /home/swissvotes/public_html/cake/libs/configure.php on line 163
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 667
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 667
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 678
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 678
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 683
Warning (2): Cannot modify header information - headers already sent by (output started at /home/swissvotes/public_html/app/plugins/db/controllers/components/searcher.php:326) [APP/views/layouts/default.ctp, line 8]
header - [internal], line ??
include - APP/views/layouts/default.ctp, line 8
View::_render() - CORE/cake/libs/view/view.php, line 731
View::renderLayout() - CORE/cake/libs/view/view.php, line 489
View::render() - CORE/cake/libs/view/view.php, line 435
Controller::render() - CORE/cake/libs/controller/controller.php, line 909
ErrorHandler::_outputMessage() - CORE/cake/libs/error.php, line 458
ErrorHandler::missingComponentClass() - CORE/cake/libs/error.php, line 433
Object::dispatchMethod() - CORE/cake/libs/object.php, line 112
ErrorHandler::__construct() - CORE/cake/libs/error.php, line 125
Object::cakeError() - CORE/cake/libs/object.php, line 199
Component::_loadComponents() - CORE/cake/libs/controller/component.php, line 228
Component::init() - CORE/cake/libs/controller/component.php, line 78
Controller::constructClasses() - CORE/cake/libs/controller/controller.php, line 483
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 185
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 170
[main] - APP/webroot/index.php, line 84
Strict Standards: Non-static method Configure::read() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 308
Strict Standards: Non-static method Configure::getInstance() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/configure.php on line 163
Strict Standards: Non-static method CakeLog::write() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 311
Strict Standards: Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/debugger.php on line 311
Strict Standards: Non-static method CakeLog::getInstance() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/cake_log.php on line 230
Strict Standards: Non-static method App::import() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/cake_log.php on line 180
Strict Standards: Non-static method App::getInstance() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/configure.php on line 917
Strict Standards: Non-static method Inflector::underscore() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/configure.php on line 948
Strict Standards: Non-static method Inflector::getInstance() should not be called statically, assuming $this from incompatible context in /home/swissvotes/public_html/cake/libs/inflector.php on line 514 Errors » SWISSVOTES
Eine Dienstleistung des Instituts für Politikwissenschaft der Universität Bern und des Année Politique Suisse
Swissvotes
die Datenbank der eidgenössischen Volksabstimmungen