-
-
Save kentfredric/4128689 to your computer and use it in GitHub Desktop.
WIP: Survey question summary, based on older Countries MVC model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'models/question.php'; | |
require_once ("dbconfig.php"); | |
class Model { | |
private function summary_stats() { | |
$translation_table = array ( | |
'cheeseCheck1a' => 40, | |
'cheeseCheck1b' => 41, | |
'cheeseCheck1c' => 42, | |
'cheeseCheck1d' => 43, | |
'cheeseCheck2a' => 44, | |
'cheeseCheck2b' => 45, | |
'cheeseCheck2c' => 46, | |
'cheeseCheck2d' => 47, | |
); | |
$offset_table = array ( | |
'cheeseQ1' => 0 - 1, | |
'cheeseQ2' => 5 - 1, | |
'cheeseQ3' => 10 - 1, | |
'cheeseQ4' => 15 - 1, | |
'cheeseQ5' => 20 - 1, | |
'cheeseQ6' => 25 - 1, | |
'cheeseQ7' => 30 - 1, | |
); | |
$summ = array_fill( 0, 49, 0 ); | |
$dbc = new DBConfig(); | |
$db = new PDO($dbc -> dsn, $dbc -> user, $dbc -> pass); | |
$sql = "select * from it609data order by firstname"; | |
$rows = $db -> query($sql); | |
foreach ($rows as $row) { | |
foreach( $offset_table as $source => $offset ) { | |
$real_offset = $row[$source] + $offset; | |
$summ[ $real_offset ] += 1; | |
} | |
foreach ( $translation_table as $source => $target ) { | |
if( $row[$source] == 1 ) { | |
$summ[$target] += 1; | |
} | |
} | |
$summ[48] += 1; | |
} | |
$db = null; | |
return $summ; | |
} | |
public function summary(){ | |
$summ = this->summary_stats(); | |
$summResults = array(); | |
$radiooptions = array(); | |
$totalRecords = $summ[48]; | |
for ($i = 0;$i<8;$i++) | |
{ | |
$radioparts = array(); | |
for ($i = 0;$i < 5; $i++) | |
{ | |
$questionName = "Question" + ($i + 1); | |
$radioparts[$i] = new Question($questionName, $summ[$i]); | |
} | |
usort($radioparts, array("Question", "cmp_obj")); | |
$radiooptions[$i] = $radioparts[4]; | |
} | |
return $countries; | |
/* | |
return array( | |
"1"=>new Country("1","New Zealand",268680,4383600,16.32,"newzeala.gif"), | |
"2"=>new Country("2","China",9596960,1339190000,139.54,"china.gif"), | |
"3"=>new Country("3","Australia",7686850,22421417,2.92,"australi.gif"), | |
); | |
*/ | |
} | |
public function getCountry($cid){ | |
$allCountries = $this->getCountries(); | |
return $allCountries[$cid]; | |
} | |
public function updateCountry($country){ | |
$countries = array(); | |
$dbc = new DBConfig(); | |
$db = new PDO($dbc -> dsn, $dbc -> user, $dbc -> pass); | |
$sql = "update countries set name=?,population=?,area=?,popdensity=? where cid=?"; | |
$st = $db->prepare($sql); | |
$st->bindParam(1,$country->name); | |
$st->bindParam(2,$country->population); | |
$st->bindParam(3,$country->area); | |
$st->bindParam(4,$country->popdensity); | |
$st->bindParam(5,$country->cid); | |
$st->execute(); | |
$db=null; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment