Exemple #1
0
 /**
  * Update the flag state of a question attempt.
  *
  * @param int $qubaid the question usage id.
  * @param int $questionid the question id.
  * @param int $qaid the question_attempt id.
  * @param int $slot the slot number within the usage.
  * @param string $checksum checksum, as computed by {@link get_toggle_checksum()}
  *      corresponding to the last three arguments and the users username.
  * @param bool $newstate the new state of the flag. true = flagged.
  * @return array (success infos and fail infos)
  * @since Moodle 3.1
  */
 public static function update_flag($qubaid, $questionid, $qaid, $slot, $checksum, $newstate)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::update_flag_parameters(), array('qubaid' => $qubaid, 'questionid' => $questionid, 'qaid' => $qaid, 'slot' => $slot, 'checksum' => $checksum, 'newstate' => $newstate));
     $warnings = array();
     self::validate_context(context_system::instance());
     // The checksum will be checked to provide security flagging other users questions.
     question_flags::update_flag($params['qubaid'], $params['questionid'], $params['qaid'], $params['slot'], $params['checksum'], $params['newstate']);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
Exemple #2
0
 /**
  * Update the flag state of a question attempt.
  *
  * @param int $qubaid the question usage id.
  * @param int $questionid the question id.
  * @param int $qaid the question_attempt id.
  * @param int $slot the slot number within the usage.
  * @param string $checksum checksum, as computed by {@link get_toggle_checksum()}
  *      corresponding to the last three arguments and the users username.
  * @param bool $newstate the new state of the flag. true = flagged.
  * @return array (success infos and fail infos)
  * @since Moodle 3.1
  */
 public static function update_flag($qubaid, $questionid, $qaid, $slot, $checksum, $newstate)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::update_flag_parameters(), array('qubaid' => $qubaid, 'questionid' => $questionid, 'qaid' => $qaid, 'slot' => $slot, 'checksum' => $checksum, 'newstate' => $newstate));
     $warnings = array();
     // Check user is logged in.
     require_login(null, false, null, false, true);
     // The checksum will be checked to provide security flagging other users questions.
     question_flags::update_flag($params['qubaid'], $params['questionid'], $params['qaid'], $params['slot'], $params['checksum'], $params['newstate']);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
Exemple #3
0
 /**
  * Render the question flag, assuming $flagsoption allows it.
  *
  * @param question_attempt $qa the question attempt to display.
  * @param int $flagsoption the option that says whether flags should be displayed.
  */
 protected function question_flag(question_attempt $qa, $flagsoption)
 {
     global $CFG;
     $divattributes = array('class' => 'questionflag');
     switch ($flagsoption) {
         case question_display_options::VISIBLE:
             $flagcontent = $this->get_flag_html($qa->is_flagged());
             break;
         case question_display_options::EDITABLE:
             $id = $qa->get_flag_field_name();
             // The checkbox id must be different from any element name, because
             // of a stupid IE bug:
             // http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/
             $checkboxattributes = array('type' => 'checkbox', 'id' => $id . 'checkbox', 'name' => $id, 'value' => 1);
             if ($qa->is_flagged()) {
                 $checkboxattributes['checked'] = 'checked';
             }
             $postdata = question_flags::get_postdata($qa);
             $flagcontent = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $id, 'value' => 0)) . html_writer::empty_tag('input', $checkboxattributes) . html_writer::empty_tag('input', array('type' => 'hidden', 'value' => $postdata, 'class' => 'questionflagpostdata')) . html_writer::tag('label', $this->get_flag_html($qa->is_flagged(), $id . 'img'), array('id' => $id . 'label', 'for' => $id . 'checkbox')) . "\n";
             $divattributes = array('class' => 'questionflag editable', 'aria-atomic' => 'true', 'aria-relevant' => 'text', 'aria-live' => 'assertive');
             break;
         default:
             $flagcontent = '';
     }
     return html_writer::nonempty_tag('div', $flagcontent, $divattributes);
 }
Exemple #4
0
 /**
  * Initialise the JavaScript required on pages where questions will be displayed.
  */
 public static function initialise_js()
 {
     return question_flags::initialise_js();
 }
Exemple #5
0
 /**
  * Render the question flag, assuming $flagsoption allows it.
  *
  * @param question_attempt $qa the question attempt to display.
  * @param int $flagsoption the option that says whether flags should be displayed.
  */
 protected function question_flag(question_attempt $qa, $flagsoption) {
     global $CFG;
     switch ($flagsoption) {
         case question_display_options::VISIBLE:
             $flagcontent = $this->get_flag_html($qa->is_flagged());
             break;
         case question_display_options::EDITABLE:
             $id = $qa->get_flag_field_name();
             if ($qa->is_flagged()) {
                 $checked = 'checked="checked" ';
             } else {
                 $checked = '';
             }
             $postdata = question_flags::get_postdata($qa);
             // The checkbox id must be different from any element name, because
             // of a stupid IE bug:
             // http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/
             $flagcontent = '<input type="hidden" name="' . $id . '" value="0" />' .
                     '<input type="checkbox" id="' . $id . 'checkbox" name="' . $id .
                             '" value="1" ' . $checked . ' />' .
                     '<input type="hidden" value="' . s($postdata) .
                             '" class="questionflagpostdata" />' .
                     '<label id="' . $id . 'label" for="' . $id . 'checkbox">' .
                             $this->get_flag_html($qa->is_flagged(), $id . 'img') .
                             '</label>' . "\n";
             break;
         default:
             $flagcontent = '';
     }
     if ($flagcontent) {
         return '<div class="questionflag">' . $flagcontent . "</div>\n";
     }
 }
Exemple #6
0
// Moodle 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 Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Used by ajax calls to toggle the flagged state of a question in an attempt.
 *
 * @package    moodlecore
 * @subpackage questionengine
 * @copyright  2009 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
require_once '../config.php';
require_once $CFG->dirroot . '/question/engine/lib.php';
// Parameters
$qaid = required_param('qaid', PARAM_INT);
$qubaid = required_param('qubaid', PARAM_INT);
$questionid = required_param('qid', PARAM_INT);
$slot = required_param('slot', PARAM_INT);
$newstate = required_param('newstate', PARAM_BOOL);
$checksum = required_param('checksum', PARAM_ALPHANUM);
// Check user is logged in.
require_login();
require_sesskey();
// Check that the requested session really exists
question_flags::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, $newstate);
echo 'OK';