Skip to content

Commit

Permalink
Merge pull request #530 from jwj61/motags
Browse files Browse the repository at this point in the history
Icons in LB1 to signal problems with math objects and static problems

Sounds like a good project. 

The issues with Prev/Next and the icon orders were fixed.  Everything else checks out so I'll merge.
  • Loading branch information
goehle committed Jan 2, 2015
2 parents 7ec410c + c67bdda commit 02a492b
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 15 deletions.
8 changes: 6 additions & 2 deletions bin/OPL-update
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ if($libraryVersion eq '2.5') {
morelt_id int(127) DEFAULT 0 NOT NULL,
level int(15),
language varchar(15),
static TINYINT,
MO TINYINT,
PRIMARY KEY (pgfile_id)
'],
[$tables{keyword}, '
Expand Down Expand Up @@ -644,7 +646,7 @@ sub pgfiles {
my $path_id = safe_get_id($tables{path}, 'path_id',
qq(WHERE path = ?), [$pgpath], 1, "", $pgpath, "", "");

# pgfile table -- set 2 defaults first
# pgfile table -- set 4 defaults first

## TODO this is where we have to deal with crosslists, and pgfileid
## will be an array of id's
Expand All @@ -653,12 +655,14 @@ sub pgfiles {
my $level = $tags->{Level} || 0;
# Default language is English
my $lang = $tags->{Language} || "en";
my $mathobj = $tags->{MO} || 0;
my $static = $tags->{Static} || 0;

my @pgfile_ids = ();

for my $DBsection_id (@DBsection_ids) {
my $pgfile_id = safe_get_id($tables{pgfile}, 'pgfile_id',
qq(WHERE filename = ? AND path_id = ? AND DBsection_id = ? ), [$pgfile, $path_id, $DBsection_id], 1, "", $DBsection_id, $author_id, $tags->{Institution}, $path_id, $pgfile, 0, $level, $lang);
qq(WHERE filename = ? AND path_id = ? AND DBsection_id = ? ), [$pgfile, $path_id, $DBsection_id], 1, "", $DBsection_id, $author_id, $tags->{Institution}, $path_id, $pgfile, 0, $level, $lang, $static, $mathobj);
push @pgfile_ids, $pgfile_id;
}
#if (scalar(@pgfile_ids)>1) {
Expand Down
31 changes: 31 additions & 0 deletions htdocs/helpFiles/UsesMathObjects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<!--
################################################################################
# WeBWorK Online Homework Delivery System
# Copyright © 2000-2014 The WeBWorK Project, http://openwebwork.sf.net/
# This program is free software; you can redistribute it and/or modify it under
# the terms of either: (a) the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version, or (b) the "Artistic License" which comes with this package.
#
# This program 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 either the GNU General Public License or the
# Artistic License for more details.
################################################################################
-->
<head>
<title>Uses Math Objects</title>
</head>

<body><br>
<p>
Some WeBWorK problems are programmed using what are called <i>Math Objects</i>.
These problems are preferred by some people because they
provide a more consistent collection of messages to faulty student
answers, particularly for answers which are way off base.
</p>


</body>
</html>
Binary file added htdocs/images/pibox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions htdocs/js/legacy/setmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function delrow(num) {
var loop = 1;
var mymltM = $('#mlt'+num);
var mymltMtext = 'L'; // so extra stuff is not deleted
if(mymltM) {
if(mymltM) {
mymltMtext = mymltM.text();
}
$('#pgrow'+num).remove();
Expand All @@ -289,7 +289,8 @@ function delrow(num) {
$('#mlt-table'+num).attr('id','mlt-table'+new_num);
var onclickfunction = mymltM.attr('onclick').replace(num,new_num);
mymltM.attr('id','mlt'+new_num).attr('onclick', onclickfunction);
mymltM.insertAfter('#inset'+new_num);
var insetel = $('#inset'+new_num);
insetel.next().after(mymltM).after(" ");
var classstr = $('#pgrow'+new_num).attr('class')
.replace('MLT'+mymlt,'NS'+new_num);
$('#pgrow'+new_num).attr('class',classstr);
Expand All @@ -313,10 +314,10 @@ function delrow(num) {

function findAPLindex(path) {
var j=0;
while ($('[name="all_past_list'+ j +'"]').val() != path && (j<100)) {
while ($('[name="all_past_list'+ j +'"]').val() != path && (j<1000)) {
j++;
}
if(j==100) { alert("Cannot find "+path);}
if(j==1000) { alert("Cannot find "+path);}
return j;
}

Expand Down
32 changes: 29 additions & 3 deletions lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ sub munge_pg_file_path {
return($pg_path);
}

## Problems straight from the OPL database come with MO and static
## tag information. This is for other times, like next/prev page.

sub getDBextras {
my $r = shift;
my $sourceFileName = shift;

if($sourceFileName =~ /^Library/) {
return @{WeBWorK::Utils::ListingDB::getDBextras($r, $sourceFileName)};
}

my $filePath = $r->ce->{courseDirs}{templates}."/$sourceFileName";
my $tag_obj = WeBWorK::Utils::Tags->new($filePath);
my $isMO = $tag_obj->{MO} || 0;
my $isstatic = $tag_obj->{Static} || 0;

return ($isMO, $isstatic);
}

## With MLT, problems come in groups, so we need to find next/prev
## problems. Return index, or -1 if there are no more.
sub next_prob_group {
Expand Down Expand Up @@ -933,6 +952,11 @@ sub make_data_row {
my $sourceFileData = shift;
my $sourceFileName = $sourceFileData->{filepath};
my $pg = shift;
my $isstatic = $sourceFileData->{static};
my $isMO = $sourceFileData->{MO};
if (not defined $isMO) {
($isMO, $isstatic) = getDBextras($r, $sourceFileName);
}
my $cnt = shift;
my $mltnumleft = shift;

Expand Down Expand Up @@ -1028,7 +1052,9 @@ sub make_data_row {

my $level =0;

my $rerand = '<span style="display: inline-block" onclick="randomize(\''.$sourceFileName.'\',\'render'.$cnt.'\')" title="Randomize"><i class="icon-random" ></i></span>';
my $rerand = $isstatic ? '' : '<span style="display: inline-block" onclick="randomize(\''.$sourceFileName.'\',\'render'.$cnt.'\')" title="Randomize"><i class="icon-random"></i></span>';
my $MOtag = $isMO ? $self->helpMacro("UsesMathObjects",'<img src="/webwork2_files/images/pibox.png" border="0" title="Uses Math Objects" alt="Uses Math Objects" />') : '';
$MOtag = '<span class="motag">'.$MOtag.'</span>';

print $mltstart;
# Print the cell
Expand All @@ -1041,7 +1067,7 @@ sub make_data_row {
"\n",CGI::span({-style=>"text-align: left; cursor: pointer"},CGI::span({id=>"filepath$cnt"},"Show path ...")),"\n",
'<script type="text/javascript">settoggle("filepath'.$cnt.'", "Show path ...", "Hide path: '.$sourceFileName.'")</script>',
CGI::span({-style=>"float:right ; text-align: right"},
$inSet, $mlt, $rerand,
$inSet, $MOtag, $mlt, $rerand,
$edit_link, " ", $try_link,
CGI::span({-name=>"dont_show",
-title=>"Hide this problem",
Expand Down Expand Up @@ -1528,7 +1554,7 @@ sub head {
my $ce = $self->r->ce;
my $webwork_htdocs_url = $ce->{webwork_htdocs_url};

print qq!<link rel="stylesheet" href="$webwork_htdocs_url/js/vendor/FontAwesome/css/font-awesome.css">!;
#print qq!<link rel="stylesheet" href="$webwork_htdocs_url/js/vendor/FontAwesome/css/font-awesome.css">!;

print qq!<script src="$webwork_htdocs_url/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>!;
print qq!<script src="$webwork_htdocs_url/js/vendor/jquery/jquery-ui.js"></script>!;
Expand Down
42 changes: 38 additions & 4 deletions lib/WeBWorK/Utils/ListingDB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use strict;
use DBI;
use WeBWorK::Utils qw(sortByName);
use WeBWorK::Utils::Tags;
use File::Basename;

use constant LIBRARY_STRUCTURE => {
textbook => { select => 'tbk.textbook_id,tbk.title,tbk.author,tbk.edition',
Expand All @@ -42,7 +43,7 @@ BEGIN
&createListing &updateListing &deleteListing &getAllChapters
&getAllSections &searchListings &getAllListings &getSectionListings
&getAllDBsubjects &getAllDBchapters &getAllDBsections &getDBTextbooks
&getDBListings &countDBListings &getTables
&getDBListings &countDBListings &getTables &getDBextras
);
%EXPORT_TAGS =();
@EXPORT_OK =qw();
Expand Down Expand Up @@ -122,7 +123,7 @@ sub getProblemTags {
my $path = shift;
my $tags = WeBWorK::Utils::Tags->new($path);
my %thash = ();
for my $j ('DBchapter', 'DBsection', 'DBsubject', 'Level') {
for my $j ('DBchapter', 'DBsection', 'DBsubject', 'Level', 'Status') {
$thash{$j} = $tags->{$j};
}
return \%thash;
Expand All @@ -135,11 +136,13 @@ sub setProblemTags {
my $chap = shift;
my $sect = shift;
my $level = shift;
my $status = shift || 0;
my $tags = WeBWorK::Utils::Tags->new($path);
$tags->settag('DBsubject', $subj, 1);
$tags->settag('DBchapter', $chap, 1);
$tags->settag('DBsection', $sect, 1);
$tags->settag('Level', $level, 1);
$tags->settag('Status', $status, 0) if $status;
eval {
$tags->write();
1;
Expand Down Expand Up @@ -182,6 +185,37 @@ sub makeKeywordWhere {
return "AND ( $where )";
}

=item getDBextras($path)
Get flags for whether a pg file uses Math Objects, and if it is static
$r is a Apache request object so we can get the right table names
$path is the path to the file
Out put is an array reference: [MO, static]
=cut

sub getDBextras {
my $r = shift;
my $path = shift;
my %tables = getTables($r->ce);
my $dbh = getDB($r->ce);
my ($mo, $static)=(0,0);

$path =~ s|^Library/||;
my $filename = basename $path;
$path = dirname $path;
my $query = "SELECT pgfile.MO, pgfile.static FROM `$tables{pgfile}` pgfile, `$tables{path}` p WHERE p.path=\"$path\" AND pgfile.path_id=p.path_id AND pgfile.filename=\"$filename\"";
my @res = $dbh->selectrow_array($query);
if(@res) {
$mo = $res[0];
$static = $res[1];
}

return [$mo, $static];
}

=item getDBTextbooks($r)
Returns textbook dependent entries.
Expand Down Expand Up @@ -440,10 +474,10 @@ sub getDBListings {
}
my @results=();
for my $pgid (@pg_ids) {
$query = "SELECT path, filename, morelt_id, pgfile_id FROM `$tables{pgfile}` pgf, `$tables{path}` p
$query = "SELECT path, filename, morelt_id, pgfile_id, static, MO FROM `$tables{pgfile}` pgf, `$tables{path}` p
WHERE p.path_id = pgf.path_id AND pgf.pgfile_id=\"$pgid\"";
my $row = $dbh->selectrow_arrayref($query);
push @results, {'path' => $row->[0], 'filename' => $row->[1], 'morelt' => $row->[2], 'pgid'=> $row->[3] };
push @results, {'path' => $row->[0], 'filename' => $row->[1], 'morelt' => $row->[2], 'pgid'=> $row->[3], 'static' => $row->[4], 'MO' => $row->[5] };

}
return @results;
Expand Down
4 changes: 2 additions & 2 deletions lib/WeBWorK/Utils/Tags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ our @EXPORT_OK = qw();
# list_set_versions
#);

use constant BASIC => qw( DBsubject DBchapter DBsection Date Institution Author MLT MLTleader Level Language );
use constant BASIC => qw( DBsubject DBchapter DBsection Date Institution Author MLT MLTleader Level Language Static MO Status );
use constant NUMBERED => qw( TitleText AuthorText EditionText Section Problem );

my $basics = join('|', BASIC);
Expand Down Expand Up @@ -333,7 +333,7 @@ sub copyin {
# }
# }
# Just copy in all basic tags
for my $j (qw( DBsubject DBchapter DBsection Date Institution Author MLT MLTleader Level )) {
for my $j (qw( DBsubject DBchapter DBsection MLT MLTleader Level )) {
$self->settag($j, $ob->{$j}) if(defined($ob->{$j}));
}
# Now copy in keywords
Expand Down

0 comments on commit 02a492b

Please sign in to comment.