Skip to content

Commit

Permalink
v2.8.02
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Parker committed Mar 27, 2022
1 parent 8666c53 commit 121d4e9
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 291 deletions.
6 changes: 6 additions & 0 deletions Badges/CHANGEDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,9 @@
++$count;
$sql[$count][0] = '2.8.01';
$sql[$count][1] = "";

++$count;
$sql[$count][0] = '2.8.02';
$sql[$count][1] = "
UPDATE badgesBadgeStudent SET date=SUBSTRING(timestamp, 1, 10) WHERE date='0000-00-00';end
";
5 changes: 5 additions & 0 deletions Badges/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
CHANGELOG
=========
v2.8.02
-------
Refactoring of printPagination
Fixed empty grant date bug

v2.8.01
-------
Refactoring of linkTop divs
Expand Down
205 changes: 67 additions & 138 deletions Badges/badges_grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

use Gibbon\Forms\Form;
use Gibbon\Services\Format;
use Gibbon\Tables\DataTable;
use Gibbon\Forms\DatabaseFormFactory;
use Gibbon\Module\Badges\Domain\BadgeGateway;

//Module includes
include './modules/'.$gibbon->session->get('module').'/moduleFunctions.php';
Expand All @@ -34,9 +36,6 @@
$page->breadcrumbs->add(__('Grant Badges'));

$gibbonSchoolYearID = $_GET['gibbonSchoolYearID'] ?? $gibbon->session->get('gibbonSchoolYearID');
if (isset($_GET['gibbonSchoolYearID'])) {

}
if ($gibbonSchoolYearID == $gibbon->session->get('gibbonSchoolYearID')) {
$gibbonSchoolYearName = $gibbon->session->get('gibbonSchoolYearName');
}
Expand All @@ -61,6 +60,17 @@
}
}

//Get gibbonHookID for link to Student Profile
$gibbonHookID = null;
$dataHook = array();
$sqlHook = "SELECT gibbonHookID FROM gibbonHook WHERE name='Badges' AND type='Student Profile' AND gibbonModuleID=(SELECT gibbonModuleID FROM gibbonModule WHERE name='Badges')";
$resultHook = $connection2->prepare($sqlHook);
$resultHook->execute($dataHook);
if ($resultHook->rowCount() == 1) {
$rowHook = $resultHook->fetch();
$gibbonHookID = $rowHook['gibbonHookID'];
}

if ($gibbonSchoolYearID != '') {
$page->navigator->addSchoolYearNavigation($gibbonSchoolYearID);

Expand Down Expand Up @@ -91,156 +101,75 @@
$form->addHiddenValue('q',$_GET['q']);
$form->addRow();
echo $form->getOutput();
?>

$badgeGateway = $container->get(BadgeGateway::class);

<?php
// QUERY
$criteria = $badgeGateway->newQueryCriteria(true)
->sortBy(['timestamp'], 'DESC')
->pageSize(50)
->fromPOST();

$badges = $badgeGateway->queryBadgeGrants($criteria, $gibbonSchoolYearID, $gibbonPersonID2, $badgesBadgeID2);

echo '<h3>';
echo __('Badges');
echo '</h3>';
//Set pagination variable
$page = 1;
if (isset($_GET['page'])) {
$page = $_GET['page'];
}
if ((!is_numeric($page)) or $page < 1) {
$page = 1;
}
// TABLE
$table = DataTable::createPaginated('badges', $criteria);
$table->setTitle(__('View'));

//Get gibbonHookID for link to Student Profile
$gibbonHookID = null;
try {
$dataHook = array();
$sqlHook = "SELECT gibbonHookID FROM gibbonHook WHERE name='Badges' AND type='Student Profile' AND gibbonModuleID=(SELECT gibbonModuleID FROM gibbonModule WHERE name='Badges')";
$resultHook = $connection2->prepare($sqlHook);
$resultHook->execute($dataHook);
} catch (PDOException $e) {
$table->addHeaderAction('add', __('Add'))
->addParam('gibbonPersonID2', $gibbonPersonID2)
->addParam('badgesBadgeID2', $badgesBadgeID2)
->addParam('gibbonSchoolYearID', $gibbonSchoolYearID)
->setURL('/modules/Badges/badges_grant_add.php')
->displayLabel();

}
if ($resultHook->rowCount() == 1) {
$rowHook = $resultHook->fetch();
$gibbonHookID = $rowHook['gibbonHookID'];
}
$table->addExpandableColumn('comment')->format(function ($values) use ($session) {
$return = '';

//Search with filters applied
try {
$data = array();
$sqlWhere = 'AND ';
if ($gibbonPersonID2 != '') {
$data['gibbonPersonID'] = $gibbonPersonID2;
$sqlWhere .= 'badgesBadgeStudent.gibbonPersonID=:gibbonPersonID AND ';
if (!empty($values['description'])) {
$return .= Format::bold(__('Description'))."<br/>".$values['description']."<br/>";
}
if ($badgesBadgeID2 != '') {
$data['badgesBadgeID2'] = $badgesBadgeID2;
$sqlWhere .= 'badgesBadge.badgesBadgeID=:badgesBadgeID2 AND ';
if (!empty($values['comment'])) {
if (!empty($values['description'])) {
$return .= "<br/>";
}
$return .= Format::bold(__('Comment'))."<br/>".$values['comment'];
}
$sqlWhere = $sqlWhere == 'AND ' ? '' : substr($sqlWhere, 0, -5);

$data['gibbonSchoolYearID2'] = $gibbonSchoolYearID;
$sql = "SELECT badgesBadge.*, badgesBadgeStudent.*, surname, preferredName FROM badgesBadge JOIN badgesBadgeStudent ON (badgesBadgeStudent.badgesBadgeID=badgesBadge.badgesBadgeID) JOIN gibbonPerson ON (badgesBadgeStudent.gibbonPersonID=gibbonPerson.gibbonPersonID) WHERE badgesBadgeStudent.gibbonSchoolYearID=:gibbonSchoolYearID2 $sqlWhere ORDER BY timestamp DESC";
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
echo "<div class='error'>".$e->getMessage().'</div>';
}
$sqlPage = $sql.' LIMIT '.$gibbon->session->get('pagination').' OFFSET '.(($page - 1) * $gibbon->session->get('pagination'));

echo "<p class='text-right mb-2 text-xs'>";
echo "<a href='".$gibbon->session->get('absoluteURL').'/index.php?q=/modules/'.$gibbon->session->get('module')."/badges_grant_add.php&gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID'>".__('Add')."<img style='margin: 0 0 -4px 5px' title='".__('Add')."' src='./themes/".$gibbon->session->get('gibbonThemeName')."/img/page_new.png'/></a>";
echo '</p>';
return $return;
});

if ($result->rowCount() < 1) {
echo "<div class='error'>";
echo __('There are no records to display.');
echo '</div>';
} else {
if ($result->rowCount() > $gibbon->session->get('pagination')) {
printPagination($guid, $result->rowCount(), $page, $gibbon->session->get('pagination'), 'top', "gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID");
}

echo "<table cellspacing='0' style='width: 100%'>";
echo "<tr class='head'>";
echo "<th style='width: 180px'>";
echo __('Badges');
echo '</th>';
echo '<th>';
echo __('Student');
echo '</th>';
echo '<th>';
echo __('Date');
echo '</th>';
echo "<th style='min-width: 70px'>";
echo __('Actions');
echo '</th>';
echo '</tr>';

$count = 0;
$rowNum = 'odd';
try {
$resultPage = $connection2->prepare($sqlPage);
$resultPage->execute($data);
} catch (PDOException $e) {
echo "<div class='error'>".$e->getMessage().'</div>';
}
while ($row = $resultPage->fetch()) {
if ($count % 2 == 0) {
$rowNum = 'even';
$table->addColumn('badge', __('Badge'))
->format(function ($values) use ($session) {
$return = "<div class='text-center'>";
if ($values['logo'] != '') {
$return .= "<img class='user' style='max-width: 150px' src='" . $session->get('absoluteURL','') . '/' . $values['logo'] . "'/>";
} else {
$rowNum = 'odd';
$return .= "<img class='user' style='max-width: 150px' src='" . $session->get('absoluteURL','') . '/themes/' . $session->get('gibbonThemeName') . "/img/anonymous_240_square.jpg'/>";
}
++$count;
$return .= "<br/>".Format::bold($values['name'])."</div>";

//COLOR ROW BY STATUS!
echo "<tr class=$rowNum>";
echo "<td style='font-weight: bold; text-align: center'>";
if ($row['logo'] != '') {
echo "<img class='user' style='margin-bottom: 10px; max-width: 150px' src='".$gibbon->session->get('absoluteURL').'/'.$row['logo']."'/>";
} else {
echo "<img class='user' style='margin-bottom: 10px; max-width: 150px' src='".$gibbon->session->get('absoluteURL').'/themes/'.$gibbon->session->get('gibbonThemeName')."/img/anonymous_240_square.jpg'/>";
}
echo $row['name'];
echo '</td>';
echo '<td>';
echo "<div style='padding: 2px 0px'><b><a href='index.php?q=/modules/Students/student_view_details.php&gibbonPersonID=".$row['gibbonPersonID']."&hook=Badges&module=Badges&action=View Badges_all&gibbonHookID=$gibbonHookID&search=&allStudents=&sort=surname, preferredName'>".Format::name('', $row['preferredName'], $row['surname'], 'Student', true).'</a><br/></div>';
echo '</td>';
echo '<td>';
echo Format::date($row['date']).'<br/>';
echo '</td>';
echo '<td>';
echo "<a class='thickbox' href='".$gibbon->session->get('absoluteURL').'/fullscreen.php?q=/modules/'.$gibbon->session->get('module').'/badges_grant_delete.php&badgesBadgeStudentID='.$row['badgesBadgeStudentID']."&gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID&width=650&height=135'><img title='".__('Delete')."' src='./themes/".$gibbon->session->get('gibbonThemeName')."/img/garbage.png'/></a> ";
echo "<script type='text/javascript'>";
echo '$(document).ready(function(){';
echo "\$(\".comment-$count\").hide();";
echo "\$(\".show_hide-$count\").fadeIn(1000);";
echo "\$(\".show_hide-$count\").click(function(){";
echo "\$(\".comment-$count\").fadeToggle(1000);";
echo '});';
echo '});';
echo '</script>';
if ($row['comment'] != '') {
echo "<a title='".__('View Description')."' class='show_hide-$count' onclick='false' href='#'><img style='padding-right: 5px' src='".$gibbon->session->get('absoluteURL')."/themes/Default/img/page_down.png' alt='".__('Show Comment')."' onclick='return false;' /></a>";
}
echo '</td>';
echo '</tr>';
if ($row['comment'] != '') {
echo "<tr class='comment-$count' id='comment-$count'>";
echo '<td colspan=4>';
if ($row['comment'] != '') {
echo '<b>'.__('Comment').'</b><br/>';
echo nl2brr($row['comment']).'<br/><br/>';
}
echo '</td>';
echo '</tr>';
}
}
echo '</table>';
return $return;
});

if ($result->rowCount() > $gibbon->session->get('pagination')) {
printPagination($guid, $result->rowCount(), $page, $gibbon->session->get('pagination'), 'bottom', "gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID");
}
}
$table->addColumn('student', __('Student'))
->format(function ($values) use ($gibbonHookID) {
return "<a href='index.php?q=/modules/Students/student_view_details.php&gibbonPersonID=".$values['gibbonPersonID']."&hook=Badges&module=Badges&action=View Badges_all&gibbonHookID=$gibbonHookID&search=&allStudents=&sort=surname, preferredName'>".Format::name('', $values['preferredName'], $values['surname'], 'Student', true).'</a>';
});

$table->addColumn('date', __('Date'))->format(Format::using('date', 'date'));

$actions = $table->addActionColumn()
->addParam('badgesBadgeStudentID')
->addParam('gibbonPersonID2', $gibbonPersonID2)
->addParam('badgesBadgeID2', $badgesBadgeID2)
->addParam('gibbonSchoolYearID', $gibbonSchoolYearID)
->format(function ($resource, $actions) {
$actions->addAction('delete', __('Delete'))
->setURL('/modules/Badges/badges_grant_delete.php');
});

echo $table->render($badges);
}
}
?>
2 changes: 1 addition & 1 deletion Badges/badges_grant_addProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
foreach ($gibbonPersonIDMulti as $gibbonPersonID) {
//Write to database
try {
$data = array('badgesBadgeID' => $badgesBadgeID, 'gibbonSchoolYearID' => $gibbonSchoolYearID, 'date' => Format::date($date), 'gibbonPersonID' => $gibbonPersonID, 'comment' => $comment, 'gibbonPersonIDCreator' => $gibbon->session->get('gibbonPersonID',''));
$data = array('badgesBadgeID' => $badgesBadgeID, 'gibbonSchoolYearID' => $gibbonSchoolYearID, 'date' => Format::dateConvert($date), 'gibbonPersonID' => $gibbonPersonID, 'comment' => $comment, 'gibbonPersonIDCreator' => $gibbon->session->get('gibbonPersonID',''));
$sql = 'INSERT INTO badgesBadgeStudent SET badgesBadgeID=:badgesBadgeID, gibbonSchoolYearID=:gibbonSchoolYearID, date=:date, gibbonPersonID=:gibbonPersonID, comment=:comment, gibbonPersonIDCreator=:gibbonPersonIDCreator';
$result = $connection2->prepare($sql);
$result->execute($data);
Expand Down
Loading

0 comments on commit 121d4e9

Please sign in to comment.