Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Conflicts:
	Model/Email.php
	README.md
  • Loading branch information
rubenarslan committed Nov 4, 2013
2 parents f841c68 + 2083bb2 commit 0694ffb
Show file tree
Hide file tree
Showing 35 changed files with 1,113 additions and 751 deletions.
88 changes: 39 additions & 49 deletions Model/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,80 +87,70 @@ public function removeFromRun($run_id)
}
public function test()
{
$join = join_builder($this->dbh, $this->condition);
$q = "SELECT DISTINCT ( {$this->condition} ) AS test,`survey_run_sessions`.session FROM `survey_run_sessions`
$join
WHERE
`survey_run_sessions`.run_id = :run_id
$q = "SELECT `survey_run_sessions`.session,`survey_run_sessions`.id,`survey_run_sessions`.position FROM `survey_run_sessions`
ORDER BY IF(ISNULL( ( {$this->condition} ) ),1,0), RAND()
WHERE
`survey_run_sessions`.run_id = :run_id
LIMIT 20";
ORDER BY `survey_run_sessions`.position DESC,RAND()
echo "<pre>$q</pre>";
$evaluate = $this->dbh->prepare($q); // should use readonly
$evaluate->bindParam(':run_id',$this->run_id);
LIMIT 20";
$get_sessions = $this->dbh->prepare($q); // should use readonly
$get_sessions->bindParam(':run_id',$this->run_id);

$evaluate->execute() or die(print_r($evaluate->errorInfo(), true));
if($evaluate->rowCount()>=1):
$get_sessions->execute() or die(print_r($get_sessions->errorInfo(), true));
if($get_sessions->rowCount()>=1):
$results = array();
while($temp = $evaluate->fetch())
while($temp = $get_sessions->fetch())
$results[] = $temp;
else:
echo 'Nothing found';
echo 'No data to compare to yet.';
return false;
endif;


$openCPU = $this->makeOpenCPU();
$this->run_session_id = current($results)['id'];

$openCPU->addUserData($this->getUserDataInRun(
$this->dataNeeded($this->dbh,$this->condition)
));
echo $openCPU->evaluateAdmin($this->condition);

echo '<table class="table table-striped">
<thead><tr>
<th>Code</th>
<th>Code (Position)</th>
<th>Test</th>
</tr></thead>
<tbody>"';
foreach($results AS $row):
$openCPU = $this->makeOpenCPU();
$this->run_session_id = $row['id'];

$openCPU->addUserData($this->getUserDataInRun(
$this->dataNeeded($this->dbh,$this->condition)
));

echo "<tr>
<td><small>{$row['session']}</small></td>
<td>".h((int)$row['test'])."</td>
<td style='word-wrap:break-word;max-width:150px'><small>".$row['session']." ({$row['position']})</small></td>
<td>".stringBool($openCPU->evaluate($this->condition) )."</td>
</tr>";
endforeach;
echo '</tbody></table>';
$this->run_session_id = null;
}
public function exec()
{
$join = join_builder($this->dbh, $this->condition);

$q = "SELECT ( {$this->condition} ) AS test FROM `survey_run_sessions`

$join
WHERE
`survey_run_sessions`.`id` = :run_session_id
ORDER BY IF(ISNULL( ( {$this->condition} ) ),1,0), `survey_unit_sessions`.id DESC
LIMIT 1";

# pr($q);
$evaluate = $this->dbh->prepare($q); // should use readonly
$evaluate->bindParam(":run_session_id", $this->run_session_id);
$openCPU = $this->makeOpenCPU();

$evaluate->execute() or die(print_r($evaluate->errorInfo(), true));
if($evaluate->rowCount()===1):
$temp = $evaluate->fetch();
$result = (bool)$temp['test'];
else:
$result = false;
endif;
# pr($temp);
# pr($this->run_session_id);

// evaluate condition
$openCPU->addUserData($this->getUserDataInRun(
$this->dataNeeded($this->dbh,$this->condition)
));
$result = (bool)$openCPU->evaluate($this->condition);
$join = join_builder($this->dbh, $this->condition);

$position = $result ? $this->if_true : $this->if_false;
# $run_to_id = $this->getUnitIdAtPosition( $run_to );

# $run_session = new RunSession($this->dbh, $this->run_id, $this->user_id, $this->session);

global $run_session;
if($run_session->session):
$this->end();
Expand Down
230 changes: 230 additions & 0 deletions Model/DearyLiewald.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?php
require_once INCLUDE_ROOT."Model/DB.php";
require_once INCLUDE_ROOT."Model/Item.php";
require_once INCLUDE_ROOT."Model/RunUnit.php";

class DearyLiewald extends RunUnit {
public $id = null;
public $name = null;
public $run_name = null;
public $logo_name = null;
public $items = array();
public $maximum_number_displayed = null;
public $unanswered_batch = array();
public $already_answered = 0;
public $not_answered = 0;
public $progress = 0;
public $session = null;
public $errors = array();
public $results_table = null;
public $run_session_id = null;
public $settings = array();
protected $dbh;

public function __construct($fdb, $session, $unit)
{
parent::__construct($fdb,$session,$unit);


$study_data = $this->dbh->prepare("SELECT id,name FROM `survey_dearyliewalds` WHERE id = :study_id LIMIT 1");
$study_data->bindParam(":study_id",$unit['unit_id']);
$study_data->execute() or die(print_r($study_data->errorInfo(), true));
$vars = $study_data->fetch(PDO::FETCH_ASSOC);

if($vars):
$this->id = $vars['id'];
$this->name = $vars['name'];
# $this->logo_name = $vars['logo_name'];
$this->results_table = $this->name;
$this->getSettings();
endif;

$this->getNextItems();

# if(isset($_POST['session_id']))
# {
$this->post($_POST);
# }

if($this->getProgress()===1)
$this->end();
}
protected function getSettings()
{
$study_settings = $this->dbh->prepare("SELECT `key`, `value` FROM `survey_settings` WHERE study_id = :study_id");
$study_settings->bindParam(":study_id",$this->id);
$study_settings->execute() or die(print_r($study_settings->errorInfo(), true));
while($setting = $study_settings->fetch(PDO::FETCH_ASSOC))
$this->settings[$setting['key']] = $setting['value'];

return $this->settings;
}
public function render() {
$ret = $this->render_form_header().
$this->render_items().
$this->render_form_footer();
$this->dbh = NULL;
return $ret;
}
public function post($posted) {

unset($posted['id']); // cant overwrite your session
unset($posted['session']); // cant overwrite your session
unset($posted['session_id']); // cant overwrite your session ID
unset($posted['study_id']); // cant overwrite your study ID
unset($posted['created']); // cant overwrite
unset($posted['modified']); // cant overwrite
unset($posted['ended']); // cant overwrite


$answered = $this->dbh->prepare("INSERT INTO `survey_items_display` (item_id, session_id, answered, answered_time, modified)
VALUES( :item_id, :session_id, 1, NOW(), NOW() )
ON DUPLICATE KEY UPDATE answered = 1,answered_time = NOW()");

$answered->bindParam(":session_id", $this->session_id);

$start_entry = $this->dbh->prepare("INSERT INTO `{$this->results_table}` (`session_id`, `study_id`, `created`, `modified`)
VALUES(:session_id, :study_id, NOW(), NOW())
ON DUPLICATE KEY UPDATE modified = NOW();");
$start_entry->bindParam(":session_id", $this->session_id);
$start_entry->bindParam(":study_id", $this->id);
$start_entry->execute() or die(print_r($start_entry->errorInfo(), true));


foreach($posted AS $name => $value)
{
if (isset($this->unanswered_batch[$name])) {
$value = $this->unanswered_batch[$name]->validateInput($value);
if( ! $this->unanswered_batch[$name]->error )
{
$this->dbh->beginTransaction() or die(print_r($answered->errorInfo(), true));
$answered->bindParam(":item_id", $this->unanswered_batch[$name]->id);
$answered->execute() or die(print_r($answered->errorInfo(), true));

$post_form = $this->dbh->prepare("UPDATE `{$this->results_table}`
SET
`$name` = :$name
WHERE session_id = :session_id AND study_id = :study_id;");
$post_form->bindParam(":$name", $value);
$post_form->bindParam(":session_id", $this->session_id);
$post_form->bindParam(":study_id", $this->id);

try
{
$post_form->execute();
$this->dbh->commit();
}
catch(Exception $e)
{
pr($e);
pr($value);
}
unset($this->unanswered_batch[$name]);
} else {
$this->errors[$name] = $this->unanswered_batch[$name]->error;
}
}
} //endforeach

if(empty($this->errors) AND !empty($posted))
{ // PRG
redirect_to(WEBROOT."{$this->run_name}");
} else
{
$this->getProgress();
}

}

public function end()
{
$post_form = $this->dbh->prepare("UPDATE
`{$this->results_table}`
SET `ended` = NOW()
WHERE `session_id` = :session_id AND
`study_id` = :study_id AND
`ended` IS NULL;");
$post_form->bindParam(":session_id", $this->session_id);
$post_form->bindParam(":study_id", $this->id);
$post_form->execute() or die(print_r($post_form->errorInfo(), true));

return parent::end();
}
public function exec()
{
if($this->called_by_cron)
return true; // never show to the cronjob
if($this->getProgress()===1) {
$this->end();
return false;
}

$action = WEBROOT."{$this->run_name}";

if(!isset($this->settings['form_classes'])) $this->settings['form_classes'] = '';
$form =

return array('title' => (isset($this->settings['title'])?$this->settings['title']: null),
'body' =>
'<form action="'.$action.'" method="post" class="form-horizontal '.$this->settings['form_classes'].'" accept-charset="utf-8">
<script type="text/javascript" src="'.WEBROOT.'assets/deary_liewald^ .js"></script>
<input type="hidden" name="session_id" value="' . $this->session_id . '" />
<div class="control-group error form-message">
<div class="control-label">'.implode("<br>",array_unique($this->errors)).'
</div></div>
<div class="row-fluid">
<div id="span12">
'.

(isset($this->settings['title'])?"<h1>{$this->settings['title']}</h1>":'') .
(isset($this->settings['description'])?"<p class='lead'>{$this->settings['description']}</p>":'') .
'
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="session_outer">
<div id="session">
<h4>Hier gelangen Sie zu Ihrem persönlichen Trainingsbereich.</h4>
<p> Bitte klicken Sie auf „Weiter“, um mit dem Training anzufangen.</p>
<div class="session_begin">
Für die korrekte Darstellung der Aufgabe, müssen Sie JavaScript in Ihren Browser-Einstellungen erlauben.
Eine genaue Anleitung dafür finden Sie <a href="http://www.enable-javascript.com/de/">auf dieser Homepage</a>.
</div>
</div>
<div id="trial">
<div style="visibility:hidden" id="fixation"></div>
<div style="visibility:hidden" id="probe1_top" class="probe_top"></div>
<div style="visibility:hidden" id="probe1_bottom" class="probe"></div>
<div style="visibility:hidden" id="probe2_top" class="probe_top"></div>
<div style="visibility:hidden" id="probe2_bottom" class="probe"></div>
<div style="visibility:hidden" id="mistake_message">Falsche Antwort</div>
</div>
</div>
</div> <!-- end of span12 div -->
</div> <!-- end of row-fluid div -->
</form>
'.
(isset($this->settings['problem_email'])?
'
<div class="row-fluid">
<div class="span12">'.
(isset($this->settings['problem_text'])?
str_replace("%s",$this->settings['problem_email'],$this->settings['problem_text']) :
('<a href="mailto:'.$this->settings['problem_email'].'">'.$this->settings['problem_email'].'</a>')
).
'</div>
</div>
':'')
);

}
}
Loading

0 comments on commit 0694ffb

Please sign in to comment.