本文整理汇总了PHP中Exercise类的典型用法代码示例。如果您正苦于以下问题:PHP Exercise类的具体用法?PHP Exercise怎么用?PHP Exercise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Exercise类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getQuestion
/** hack to Just Get A Question from current dmid, using Excercise class
* to do our factorying for us.
* Obviously the factory code needs to be refactored to ElseWhere, but not on Sunday
* :-P
* (Sun 15 Jun 2008)
*/
function getQuestion( $dmid, $questionLanguages, $answerLanguages ) {
if ( !$questionLanguages )
throw new Exception( "Vocview: no question (original) languages provided!" );
if ( !$answerLanguages )
throw new Exception( "Vocview: no answer (translation) languages provided!" );
/* 3 men walked into a bar^wExercise
* fullset, fetcher, and subset
*/
/* our regular fetcher is provided by functions.php
* I suppose if I were tidier, I could use fetchers for
* persistence
*/
$fetcher = new OWFetcher();
/* fullset is a domdocument containing a <collection> of
* empty <defined-meanings/> (just their defined-meaning-id
* attribute is set)
* This format makes sense on some days, it's just
* massive nukular overkill today, specially since
* we only have 1 element :-P
* Still, if Exercise wants this as a dom, we can oblige.
*/
$xmlString = "
<collection>
<defined-meaning defined-meaning-id=\"$dmid\" />
</collection>
";
$xml = simplexml_load_string( $xmlString );
$fullset = dom_import_simplexml( $xml )->ownerDocument;
# et voila.
/* subset is a selection of stuff we are actually
* interested in, from the above, as an array of
* dmid's .... Oh look! We have just one!
*/
$subset = array( $dmid ); # :-P
# (ok, to be honest, it does also get auto-generated
# from the fullset, if we say nothing... but
# then where would the joke be? )
# and we already had the fetcher.
# So the fullset said to the fetcher: let's do this!
$exercise = new Exercise( $fetcher, $fullset, $subset );
$exercise->setQuestionLanguages( $questionLanguages );
$exercise->setAnswerLanguages( $answerLanguages );
# Ok, now let's see. which question did we need?
# (and setting selfcheck to false)
$question = $exercise->getQuestion( $dmid, false );
# Oh REALLY! And we needed to go through all that?
# well, let's return it, before people start asking
# more difficult questions.
return $question;
}
示例2: __construct
/**
* constructor of the class
*
* @author Olivier Brouckaert
* @param int $questionId that answers belong to
* @param int $course_id
*/
public function __construct($questionId, $course_id = null)
{
$this->questionId = intval($questionId);
$this->answer = array();
$this->correct = array();
$this->comment = array();
$this->weighting = array();
$this->position = array();
$this->hotspot_coordinates = array();
$this->hotspot_type = array();
$this->destination = array();
// clears $new_* arrays
$this->cancel();
if (!empty($course_id)) {
$courseInfo = api_get_course_info_by_id($course_id);
} else {
$courseInfo = api_get_course_info();
}
$this->course = $courseInfo;
$this->course_id = $courseInfo['real_id'];
// fills arrays
$objExercise = new Exercise($this->course_id);
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
$objExercise->read($exerciseId);
if ($objExercise->random_answers == '1') {
$this->readOrderedBy('rand()', '');
// randomize answers
} else {
$this->read();
// natural order
}
}
示例3: exercise_get
public function exercise_get($id = null)
{
$user = new User($this->user_id);
$exercise = new Exercise();
$exercise->where('id', $id);
$exercise->get();
$logs = $exercise->exerciselog;
$logs->get();
$response = array();
foreach ($logs as $log) {
array_push($response, $log->getData());
}
$this->response($response);
}
示例4: getContent
protected function getContent()
{
$content = '<ol class="breadcrumb">
<li><a href="' . ROOT_DIR . 'admin/courseadmin">' . I18n::t('courseoverview.title') . '</a></li>
<li><a href="' . ROOT_DIR . 'admin/lessonadmin/' . $this->course->getId() . '">' . $this->course->getName(I18n::getLang()) . '</a></li>
<li class="active">' . $this->lesson->getName(I18n::getLang()) . '</li>
</ol>';
$content .= '<form method="post"><input type="hidden" name="action" value="saveExercises" />
<table id="exercise-admin-table" class="table table-hover">
<thead>
<tr>
<th>' . I18n::t('admin.exerciseadmin.question') . '</th>
<th>' . I18n::t('admin.exerciseadmin.answer') . ' (EN)</th>
<th>' . I18n::t('admin.exerciseadmin.answer') . ' (DE)</th>
<th> </th>
</tr>
</thead>
<tbody>';
foreach ((array) Exercise::getMultipleExercises($this->lesson->getId(), 50, 0) as $exercise) {
$content .= '<tr><input type="hidden" name="exercise_id[]" value="' . $exercise->getId() . '" />
<td><input type="text" name="question[]" value="' . $exercise->getQuestion() . '" /></td>
<td><input type="text" name="answer_en[]" value="' . $exercise->getAnswer('en') . '" /></td>
<td><input type="text" name="answer_de[]" value="' . $exercise->getAnswer('de') . '" /></td>
</tr>';
}
$content .= '</tbody>
</table>
<table width="100%">
<tr><td width="50%" align="left"><button id="exercise-add-btn" class="btn btn-default" type="button">' . I18n::t('button.add') . '</button></td>
<td width="50%" align="right"><input type="submit" class="btn btn-default" value="' . I18n::t('button.save') . '" /></td></tr>
</table>
</form>';
return $content;
}
示例5: checkCode
public function checkCode()
{
Helpers::normalizeCode($this->code);
if (!($this->exercise = Exercise::model()->findByAttributes(array('code' => trim($this->code))))) {
$this->addError('code', Yii::t('swu', 'The code you entered does not exist.'));
}
}
示例6: main
function main() {
$collection_id = 376317; # olpc dictionary.... WAY too big
$fetcher = new OWFetcher();
echo "fullset...\n";
$fullSetXML = $fetcher->getFullSetXML_asString( $collection_id );
$fullSet = new DOMDocument();
$success = $fullSet->loadXML( $fullSetXML );
if ( !$success ) {
throw new Exception( "Failed to load category XML from server" );
}
$maxSubSet = dom2set( $fullSet );
# sort($maxSubSet); foreach ($maxSubSet as $dmid) {print "$dmid,";}
# var_dump($fullSet->saveXML());
$exercise = new Exercise( $fetcher, $fullSet, $maxSubSet ); # pwease, not the max!
# $exercise->setLanguages(array("eng","fra","deu"));
$exercise->setQuestionLanguages( array( "deu" ) );
$exercise->setAnswerLanguages( array( "eng" ) );
# $question_dmid=$maxSubSet[array_rand($maxSubSet)];
echo "question...\n";
# $questionNode=$exercise->getQuestionNode($question_dmid);
# dumpNode($questionNode);
$runex = $exercise->randSubExercise( 10 );
dumpExercise( $runex, 5 );
echo "\n\n=== presistence test ===\n\n";
saveExercise( $runex );
$exid = mysql_insert_id();
$loadex = loadExercise( $exid );
$loadex->setFetcher( $fetcher );
dumpExercise( $loadex, 10 );
}
示例7: sendCodes
public function sendCodes($controller)
{
if (!($student = Student::model()->findByAttributes(array('email' => $this->email)))) {
return false;
}
$exercises = Exercise::model()->with('assignment')->sortByDuedate()->findAllByAttributes(array('student_id' => $student->id));
foreach ($exercises as $exercise) {
$exercise->link = Yii::app()->controller->createAbsoluteSslUrl('exercise/info', array('k' => $exercise->generateAckKey()));
}
$options = array();
if (Helpers::getYiiParam('addOriginatingIP')) {
$options['originating_IP'] = sprintf('[%s]', Yii::app()->request->userHostAddress);
}
return MailTemplate::model()->mailFromTemplate('send_codes', array($student->email => $student->name), array('student' => $student, 'exercises' => $exercises), $options);
}
示例8: checkCode
public function checkCode()
{
if ($this->getError('verifyCode')) {
return;
// we don't provide any information about the code if the captcha is not valid
}
Helpers::normalizeCode($this->code);
if ($this->exercise = Exercise::model()->findByAttributes(array('code' => trim($this->code)))) {
if (!$this->byteacher and $this->exercise->duedate < date('Y-m-d H:m:s', time() - $this->exercise->assignment->grace * 24 * 60 * 60)) {
$this->addError('code', Yii::t('swu', 'The code provided is not valid anymore (time expired on %date%).', array('%date%' => $this->exercise->duedate)));
return;
}
} elseif ($this->code) {
$this->addError('code', Yii::t('swu', 'The code provided is not valid.'));
return;
}
}
示例9: get
public function get($functionName, $linkName, $params = array(), $checkSession = true)
{
$positive = function ($input) {
//$input = $input[count($input)-1];
$result = Model::isEmpty();
$result['content'] = array();
foreach ($input as $inp) {
if ($inp->getNumRows() > 0) {
// extract exercise data from db answer
$res = Exercise::ExtractExercise($inp->getResponse(), false);
$result['content'] = array_merge($result['content'], is_array($res) ? $res : array($res));
$result['status'] = 200;
}
}
return $result;
};
$params = DBJson::mysql_real_escape_string($params);
return $this->_component->call($linkName, $params, '', 200, $positive, array(), 'Model::isProblem', array(), 'Query');
}
示例10: saveExercises
public function saveExercises()
{
$successful = true;
$updateAmount = isset($_POST['exercise_id']) && !empty($_POST['exercise_id']) ? count($_POST['exercise_id']) : 0;
$i = 0;
// update exercises that were present in DB already
while ($i < $updateAmount) {
$id = $this->secureString($_POST['exercise_id'][$i]);
$question = $this->secureString($_POST['question'][$i]);
$answerEN = $this->secureString($_POST['answer_en'][$i]);
$answerDE = $this->secureString($_POST['answer_de'][$i]);
// do not update exercises with empty fields
if (empty($id) || empty($question) || empty($answerEN) || empty($answerDE)) {
$i++;
continue;
}
if (!Exercise::update($id, $question, $answerEN, $answerDE)) {
$successful = false;
}
$i++;
}
// add new exercises to DB
while ($i < count($_POST['question'])) {
$question = $this->secureString($_POST['question'][$i]);
$answerEN = $this->secureString($_POST['answer_en'][$i]);
$answerDE = $this->secureString($_POST['answer_de'][$i]);
// do not add exercises with empty fields
if (empty($question) || empty($answerEN) || empty($answerDE)) {
$i++;
continue;
}
if (!Exercise::createExercise($this->lesson->getId(), $question, $answerEN, $answerDE)) {
$successful = false;
}
$i++;
}
if ($successful) {
$this->getView()->addSuccessMessage('Exercises were successfully saved!');
} else {
$this->getView()->addErrorMessage('There was a problem saving one or more exercises..');
}
$this->defaultAction();
}
示例11: loadExercise
function loadExercise( $exercise_id ) {
if ( !is_int( $exercise_id ) )
throw new Exception( "persist; loadExercise exercise_id is not an integer" );
global $mysql_info;
DBTools::connect( $mysql_info );
$exercise_id = mysql_real_escape_string( $exercise_id );
$row = DBTools::doQuery( "select * from exercises where id=\"$exercise_id\"" );
$exercise = new Exercise();
$exercise->setId( $exercise_id );
$exercise->loadXML( $row["exercise"] );
$exercise->setQuestionLanguages( explode( ",", $row["questionLanguages"] ) );
$exercise->setAnswerLanguages( explode( ",", $row["answerLanguages"] ) );
return $exercise;
}
示例12: evaluate
public function evaluate()
{
if (isset($_POST['answer']) && !empty($_POST['answer'])) {
$input = $this->secureString($_POST['answer']);
$correct = $_SESSION['currentExercise']->getAnswer(I18n::getLang());
// trim whitespaces, remove not relevant characters in order to be more flexible with user input
$removedChars = '/(\\W+)|[0-9]|_/';
$input = trim($input);
$input = preg_replace($removedChars, '', $input);
$correct = trim($correct);
$correct = preg_replace($removedChars, '', $correct);
if (strtolower($input) === strtolower($correct)) {
$updated = Exercise::addCorrectAnswer($_SESSION['user']->getEmail(), $_SESSION['currentExercise']->getId());
if (!$updated) {
$this->getView()->addErrorMessage('Could not update DB.');
}
$this->getView()->addSuccessMessage(I18n::t('exercise.correct'));
} else {
$this->getView()->addErrorMessage(I18n::t('exercise.wrong'));
}
}
$this->defaultAction();
}
示例13: isset
// general parameters passed via POST/GET
if (empty($origin)) {
$origin = Security::remove_XSS($_REQUEST['origin']);
}
/** @var Exercise $objExercise */
if (empty($objExercise)) {
$objExercise = Session::read('objExercise');
}
if (empty($remind_list)) {
$remind_list = isset($_REQUEST['remind_list']) ? $_REQUEST['remind_list'] : null;
}
$exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0;
if (empty($objExercise)) {
// Redirect to the exercise overview
// Check if the exe_id exists
$objExercise = new Exercise();
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
if (!empty($exercise_stat_info) && isset($exercise_stat_info['exe_exo_id'])) {
header("Location: overview.php?exerciseId=" . $exercise_stat_info['exe_exo_id']);
exit;
}
api_not_allowed();
}
if (api_is_in_gradebook()) {
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'gradebook/index.php?' . api_get_cidreq(), 'name' => get_lang('ToolGradebook'));
}
$nameTools = get_lang('Exercises');
$interbreadcrumb[] = array("url" => "exercise.php?" . api_get_cidreq(), "name" => get_lang('Exercises'));
$htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_JS_PATH) . 'hotspot/js/hotspot.js"></script>';
$htmlHeadXtra[] = '<link rel="stylesheet" href="' . api_get_path(WEB_LIBRARY_JS_PATH) . 'hotspot/css/hotspot.css">';
if ($origin != 'learnpath') {
示例14: substr
}
if (isset($_REQUEST['quId']) && is_numeric($_REQUEST['quId'])) {
$quId = (int) $_REQUEST['quId'];
} else {
$quId = null;
}
if (isset($_REQUEST['filter'])) {
$filter = $_REQUEST['filter'];
} else {
$filter = 'all';
}
$categoryId = substr($filter, 0, 10) == 'categoryId' && is_numeric(substr($filter, 10)) ? substr($filter, 10) : null;
/*
* Init other vars
*/
$exercise = new Exercise();
if (!is_null($exId)) {
$exercise->load($exId);
}
$dialogBox = new DialogBox();
/*
* Execute commands
*/
// use question in exercise
if ($cmd == 'rqUse' && !is_null($quId) && !is_null($exId)) {
if ($exercise->addQuestion($quId)) {
// TODO show confirmation and back link
header('Location: ' . Url::Contextualize('edit_exercise.php?exId=' . $exId));
}
}
// delete question
示例15: isset
<?php
/* See license terms in /license.txt */
//require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$exercise_id = isset($_GET['exerciseId']) && !empty($_GET['exerciseId']) ? intval($_GET['exerciseId']) : 0;
// Access control
api_protect_course_script(true);
if (!api_is_allowed_to_edit()) {
api_not_allowed();
}
$objExercise = new Exercise();
$result = $objExercise->read($exercise_id);
if (!$result) {
api_not_allowed(true);
}
$interbreadcrumb[] = array("url" => "exercise.php?" . api_get_cidreq(), "name" => get_lang('Exercises'));
$interbreadcrumb[] = array("url" => "admin.php?exerciseId={$exercise_id}&" . api_get_cidreq(), "name" => $objExercise->name);
//Add the JS needed to use the jqgrid
$htmlHeadXtra[] = api_get_jqgrid_js();
// The header.
Display::display_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
//jqgrid will use this URL to do the selects
$minutes = 60;
$url = api_get_path(WEB_AJAX_PATH) . 'exercise.ajax.php?a=get_live_stats&exercise_id=' . $objExercise->id . '&minutes=' . $minutes;
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score'));
//Column config
$column_model = array(array('name' => 'firstname', 'index' => 'firstname', 'width' => '100', 'align' => 'left'), array('name' => 'lastname', 'index' => 'lastname', 'width' => '100', 'align' => 'left'), array('name' => 'start_date', 'index' => 'start_date', 'width' => '100', 'align' => 'left'), array('name' => 'question', 'index' => 'count_questions', 'width' => '60', 'align' => 'left', 'sortable' => 'false'), array('name' => 'score', 'index' => 'score', 'width' => '50', 'align' => 'left', 'sortable' => 'false'));
//Autowidth
$extra_params['autowidth'] = 'true';