diff --git a/.gitignore b/Badges/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from .gitignore rename to Badges/.gitignore diff --git a/Badges/CHANGEDB.php b/Badges/CHANGEDB.php index 8fd82c9..616584e 100644 --- a/Badges/CHANGEDB.php +++ b/Badges/CHANGEDB.php @@ -163,3 +163,7 @@ ++$count; $sql[$count][0] = '2.5.04'; $sql[$count][1] = ""; + +++$count; +$sql[$count][0] = '2.5.05'; +$sql[$count][1] = ""; \ No newline at end of file diff --git a/Badges/CHANGELOG.txt b/Badges/CHANGELOG.txt index eed391e..31bffd0 100644 --- a/Badges/CHANGELOG.txt +++ b/Badges/CHANGELOG.txt @@ -1,5 +1,9 @@ CHANGELOG ========= +v2.5.05 +------- +Table OOification + v2.5.04 ------- Form OOification and some session handling improvements diff --git a/Badges/badges_grant.php b/Badges/badges_grant.php index ef094ab..f2649ad 100644 --- a/Badges/badges_grant.php +++ b/Badges/badges_grant.php @@ -19,6 +19,10 @@ use Gibbon\Forms\Form; use Gibbon\Forms\DatabaseFormFactory; +use Gibbon\Tables\DataTable; +use Gibbon\Services\Format; +use Gibbon\Module\Badges\Domain\BadgeGateway; + //Module includes include './modules/'.$gibbon->session->get('module').'/moduleFunctions.php'; @@ -35,11 +39,10 @@ returnProcess($guid, $_GET['return'], null, null); } - $gibbonSchoolYearID = $_GET['gibbonSchoolYearID'] ?? $gibbon->session->get('gibbonSchoolYearID'); - if (isset($_GET['gibbonSchoolYearID'])) { + $gibbonSchoolYearID = $_GET['gibbonSchoolYearID'] ?? ''; - } - if ($gibbonSchoolYearID == $gibbon->session->get('gibbonSchoolYearID')) { + if ($gibbonSchoolYearID == '' or $gibbonSchoolYearID == $gibbon->session->get('gibbonSchoolYearID')) { + $gibbonSchoolYearID = $gibbon->session->get('gibbonSchoolYearID'); $gibbonSchoolYearName = $gibbon->session->get('gibbonSchoolYearName'); } @@ -83,38 +86,48 @@ } echo ''; - $gibbonPersonID2 = $_GET['gibbonPersonID2'] ?? ''; - $badgesBadgeID2 = $_GET['badgesBadgeID2'] ?? ''; - $gibbonYearGroupID = $_GET['gibbonYearGroupID'] ?? ''; - $type = $_GET['type'] ?? ''; + $gibbonPersonID2 = null; + if (isset($_GET['gibbonPersonID2'])) { + $gibbonPersonID2 = $_GET['gibbonPersonID2']; + } + $badgesBadgeID2 = null; + if (isset($_GET['badgesBadgeID2'])) { + $badgesBadgeID2 = $_GET['badgesBadgeID2']; + } + $gibbonYearGroupID = null; + if (isset($_GET['gibbonYearGroupID'])) { + $gibbonYearGroupID = $_GET['gibbonYearGroupID']; + } + $type = null; + if (isset($_GET['type'])) { + $type = $_GET['type']; + } $form = Form::create('grantbadges',$gibbon->session->get('absoluteURL').'/index.php?q=/modules/Badges/badges_grant.php','GET'); $form->setFactory(DatabaseFormFactory::create($pdo)); - $form->addClass('noIntBorder'); - $form->setTitle(__('Filter')); + $form->addRow()->addHeading(__('Filter')); $form->addRow(); $row = $form->addRow(); - $row->addLabel('gibbonPersonID2',__('User')); - $row->addSelectStudent('gibbonPersonID2', $gibbon->session->get('gibbonSchoolYearID'))->selected($gibbonPersonID2)->placeholder(); + $row->addLabel('gibbonPersonIDMulti',__('User')); + $row->addSelectStudent('gibbonPersonIDMulti', $gibbon->session->get('gibbonSchoolYearID'))->selectMultiple(); $sql = "SELECT badgesBadgeID as value, name, category FROM badgesBadge WHERE active='Y' ORDER BY category, name"; $row = $form->addRow(); - $row->addLabel('badgesBadgeID2',__('Badges')); - $row->addSelect('badgesBadgeID2')->fromQuery($pdo, $sql, [], 'category')->selected($badgesBadgeID2)->placeholder(); + $row->addLabel('badgesBadgeID',__('Badges')); + $row->addSelect('badgesBadgeID')->fromQuery($pdo, $sql, [], 'category')->placeholder(); $row = $form->addRow(); $row->addSearchSubmit($gibbon->session); $form->addHiddenValue('q',$_GET['q']); - $form->addRow(); echo $form->getOutput(); ?> - - + + '; echo __('Badges'); @@ -143,123 +156,65 @@ $gibbonHookID = $rowHook['gibbonHookID']; } - //Search with filters applied - try { - $data = array(); - $sqlWhere = 'AND '; - if ($gibbonPersonID2 != '') { - $data['gibbonPersonID'] = $gibbonPersonID2; - $sqlWhere .= 'badgesBadgeStudent.gibbonPersonID=:gibbonPersonID AND '; - } - if ($badgesBadgeID2 != '') { - $data['badgesBadgeID2'] = $badgesBadgeID2; - $sqlWhere .= 'badgesBadge.badgesBadgeID=:badgesBadgeID2 AND '; - } - $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 "
".$e->getMessage().'
'; - } - $sqlPage = $sql.' LIMIT '.$gibbon->session->get('pagination').' OFFSET '.(($page - 1) * $gibbon->session->get('pagination')); - - echo "
"; - echo "session->get('module')."/badges_grant_add.php&gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID'>".__('Add').""; - echo '
'; - - if ($result->rowCount() < 1) { - echo "
"; - echo __('There are no records to display.'); - echo '
'; - } 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 ""; - echo ""; - echo "'; - echo ''; - echo ''; - echo "'; - echo ''; - - $count = 0; - $rowNum = 'odd'; - try { - $resultPage = $connection2->prepare($sqlPage); - $resultPage->execute($data); - } catch (PDOException $e) { - echo "
".$e->getMessage().'
'; - } - while ($row = $resultPage->fetch()) { - if ($count % 2 == 0) { - $rowNum = 'even'; - } else { - $rowNum = 'odd'; + $badgesGateway = $container->get(BadgeGateway::class); + $criteria = $badgesGateway->newQueryCriteria() + ->filterBy('studentIdMulti',$_GET['gibbonPersonIDMulti'] ?? '') + ->filterBy('badgeId',$_GET['badgesBadgeID'] ?? '') + ->fromPOST(); + + $badges = $badgesGateway->queryBadgesStudents($criteria,$gibbonSchoolYearID); + $table = DataTable::createPaginated('badges',$criteria); + + //Setup params + $table + ->addHeaderAction('add',__('Add')) + ->setURL('/modules/Badges/badges_grant_add.php') + ->addParam('gibbonPersonID2',$gibbonPersonID2) + ->addParam('badgesBadgeID2',$badgesBadgeID2) + ->addParam('gibbonSchoolYearID',$gibbonSchoolYearID); + + //Setup columns + $table->addExpandableColumn('comment') + ->format(function($row) { + $output = ''; + if (!empty($row['comment']) && $row['comment'] != '') { + $output .= ''.__('Comment').'
'; + $output .= nl2brr($row['comment']).'

'; } - ++$count; + return $output; + }); - //COLOR ROW BY STATUS! - echo ""; - echo "'; - echo ''; - echo ''; - echo ''; - echo ''; - if ($row['comment'] != '') { - echo ""; - echo ''; - echo ''; - } - } - echo '
"; - echo __('Badges'); - echo ''; - echo __('Student'); - echo ''; - echo __('Date'); - echo '"; - echo __('Actions'); - echo '
"; + $table + ->addColumn('badge',__('Badge')) + ->width('155px') + ->format(function($row) use ($gibbon){ if ($row['logo'] != '') { - echo ""; + echo ""; } else { - echo "session->get('gibbonThemeName')."/img/anonymous_240_square.jpg'/>"; - } - echo $row['name']; - echo ''; - echo "
".formatName('', $row['preferredName'], $row['surname'], 'Student', true).'
'; - echo '
'; - echo dateConvertBack($guid, $row['date']).'
'; - echo '
'; - echo "session->get('module').'/badges_grant_delete.php&badgesBadgeStudentID='.$row['badgesBadgeStudentID']."&gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID&width=650&height=135'> "; - echo "'; - if ($row['comment'] != '') { - echo "".__("; + echo "session->get('gibbonThemeName') . "/img/anonymous_240_square.jpg'/>"; } - echo '
'; - if ($row['comment'] != '') { - echo ''.__('Comment').'
'; - echo nl2brr($row['comment']).'

'; - } - echo '
'; - - if ($result->rowCount() > $gibbon->session->get('pagination')) { - printPagination($guid, $result->rowCount(), $page, $gibbon->session->get('pagination'), 'bottom', "gibbonPersonID2=$gibbonPersonID2&badgesBadgeID2=$badgesBadgeID2&gibbonSchoolYearID=$gibbonSchoolYearID"); - } - } + echo "

" . $row['name'] . "

"; + }); + $table + ->addColumn('student',__('Student')) + ->format(function($row) use ($gibbonHookID,$gibbon) + { + $link = Format::link($gibbon->session->get('absoluteURL').'/index.php?q=/modules/Students/student_view_details.php?gibbonPersonID=' . $row['gibbonPersonID'] . '&hook=Badges&action=View Badges_all&gibbonHookID=' . $gibbonHookID . '&search=&allStudents=&sort=surname, preferredName', + Format::name(null,$row['preferredName'],$row['surname'],'Student',true,false)); + return $link; + }); + + $table->addColumn('date',__('Date'))->format(Format::using('date','date')); + + //Setup actions + $actions = $table->addActionColumn(); + $actions->format(function ($row,$actions) use ($gibbon,$gibbonSchoolYearID){ + $actions->addAction('delete',__('Delete')) + ->setURL('/modules/Badges/badges_grant_delete.php') + ->addParam('badgesBadgeStudentID',$row['badgesBadgeStudentID']) + ->addParam('gibbonSchoolYearID',$gibbonSchoolYearID); + }); + echo $table->render($badges); } } ?> diff --git a/Badges/badges_grant_add.php b/Badges/badges_grant_add.php index 57f0a08..75c1662 100644 --- a/Badges/badges_grant_add.php +++ b/Badges/badges_grant_add.php @@ -30,16 +30,16 @@ echo ''; } else { //Proceed! - $gibbonSchoolYearID = $_GET['gibbonSchoolYearID'] ?? ''; - $page->breadcrumbs - ->add(__('Grant Badges'), 'badges_grant.php&gibbonSchoolYearID='.$gibbonSchoolYearID) + ->add(__('Grant Badges'), 'badges_grant.php') ->add(__('Add')); if (isset($_GET['return'])) { returnProcess($guid, $_GET['return'], null, null); } + $gibbonSchoolYearID = $_GET['gibbonSchoolYearID'] ?? ''; + echo "
"; //Get the gibbon persion and badge IDs @@ -47,13 +47,13 @@ $gibbonPersonID2 = ''; $badgesBadgeID2 = ''; if (isset($_GET['gibbonPersonID2']) || isset($_GET['badgesBadgeID2'])) { - //Only assign variable when it exists - $gibbonPersonID2 = $_GET['gibbonPersonID2'] ?? ''; - $badgesBadgeID2 = $_GET['badgesBadgeID2'] ?? ''; - - //Add a "Back to Results" link - if (!empty($gibbonPersonID2) OR !empty($badgesBadgeID2)) { - echo "".__('Back to Search Results').''; + if($_GET['gibbonPersonID2'] != '' && $_GET['badgesBadgeID2'] != '') + { + //Only assign variable when it exists + $gibbonPersonID2 = $_GET['gibbonPersonID2']; + $badgesBadgeID2 = $_GET['badgesBadgeID2']; + //Add a "Back to Results" link. + echo "".__('Back to Search Results').''; } } echo '
'; @@ -61,9 +61,9 @@ $form = Form::create('grantBadges', $gibbon->session->get('absoluteURL').'/modules/'.$gibbon->session->get('module').'/badges_grant_addProcess.php?gibbonPersonID2='.$gibbonPersonID2.'&badgesBadgeID2='.$badgesBadgeID2."&gibbonSchoolYearID=$gibbonSchoolYearID"); $form->setFactory(DatabaseFormFactory::create($pdo)); - + $form->addHiddenValue('address', $gibbon->session->get('address')); - $form->addHiddenValue('gibbonSchoolYearID', $gibbonSchoolYearID); + $form->addHiddenValue('gibbonSchoolYearID', $gibbon->session->get('gibbonSchoolYearID')); $row = $form->addRow(); $row->addLabel('gibbonPersonIDMulti', __('Students')); diff --git a/Badges/badges_grant_addProcess.php b/Badges/badges_grant_addProcess.php index 9e456e1..9222af3 100644 --- a/Badges/badges_grant_addProcess.php +++ b/Badges/badges_grant_addProcess.php @@ -19,6 +19,7 @@ include '../../gibbon.php'; + $gibbonSchoolYearID = $_POST['gibbonSchoolYearID']; $URL = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/'.getModuleName($_POST['address']).'/badges_grant_add.php&gibbonPersonID2='.$_GET['gibbonPersonID2'].'&badgesBadgeID2='.$_GET['badgesBadgeID2']."&gibbonSchoolYearID=$gibbonSchoolYearID"; @@ -29,10 +30,14 @@ header("Location: {$URL}"); } else { //Proceed! - $gibbonPersonIDMulti = $_POST['gibbonPersonIDMulti'] ?? null; - $badgesBadgeID = $_POST['badgesBadgeID'] ?? ''; - $date = $_POST['date'] ?? ''; - $comment = $_POST['comment'] ?? ''; + if (isset($_POST['gibbonPersonIDMulti'])) { + $gibbonPersonIDMulti = $_POST['gibbonPersonIDMulti']; + } else { + $gibbonPersonIDMulti = null; + } + $badgesBadgeID = $_POST['badgesBadgeID']; + $date = $_POST['date']; + $comment = $_POST['comment']; if ($gibbonPersonIDMulti == null or $date == '' or $badgesBadgeID == '' or $gibbonSchoolYearID == '') { //Fail 3 diff --git a/Badges/badges_grant_delete.php b/Badges/badges_grant_delete.php index 9b3c405..dc3710a 100644 --- a/Badges/badges_grant_delete.php +++ b/Badges/badges_grant_delete.php @@ -34,9 +34,9 @@ } //Check if school year specified - $badgesBadgeStudentID = $_GET['badgesBadgeStudentID']; - $gibbonSchoolYearID = $_GET['gibbonSchoolYearID']; - if ($badgesBadgeStudentID == '') { echo "
"; + $badgesBadgeStudentID = $_GET['badgesBadgeStudentID'] ?? ''; + $gibbonSchoolYearID = $_GET['gibbonSchoolYearID'] ?? ''; + if ($badgesBadgeStudentID == '' || $gibbonSchoolYearID == '') { echo "
"; echo __('You have not specified one or more required parameters.'); echo '
'; } else { @@ -57,7 +57,7 @@ //Let's go! $row = $result->fetch(); - $form = DeleteForm::createForm($gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module')."/badges_grant_deleteProcess.php?badgesBadgeStudentID=$badgesBadgeStudentID&gibbonPersonID2=".$_GET['gibbonPersonID2'].'&badgesBadgeID2='.$_GET['badgesBadgeID2']."&gibbonSchoolYearID=$gibbonSchoolYearID"); + $form = DeleteForm::createForm($gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module')."/badges_grant_deleteProcess.php?badgesBadgeStudentID=$badgesBadgeStudentID&gibbonPersonID2=".$row['gibbonPersonID'].'&badgesBadgeID2='.$row['badgesBadgeID']."&gibbonSchoolYearID=$gibbonSchoolYearID"); echo $form->getOutput(); } } diff --git a/Badges/badges_grant_deleteProcess.php b/Badges/badges_grant_deleteProcess.php index b35ce1c..481e2d2 100644 --- a/Badges/badges_grant_deleteProcess.php +++ b/Badges/badges_grant_deleteProcess.php @@ -20,8 +20,8 @@ include '../../gibbon.php'; -$badgesBadgeStudentID = $_GET['badgesBadgeStudentID'] ?? ''; -$gibbonSchoolYearID = $_POST['gibbonSchoolYearID'] ?? ''; +$badgesBadgeStudentID = $_GET['badgesBadgeStudentID']; +$gibbonSchoolYearID = $_POST['gibbonSchoolYearID']; $URL = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/'.getModuleName($_POST['address'])."/badges_grant_delete.php&badgesBadgeStudentID=$badgesBadgeStudentID&gibbonPersonID2=".$_GET['gibbonPersonID2'].'&badgesBadgeID2='.$_GET['badgesBadgeID2']."&gibbonSchoolYearID=$gibbonSchoolYearID"; $URLDelete = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/'.getModuleName($_POST['address']).'/badges_grant.php&gibbonPersonID2='.$_GET['gibbonPersonID2'].'&badgesBadgeID2='.$_GET['badgesBadgeID2']."&gibbonSchoolYearID=$gibbonSchoolYearID"; diff --git a/Badges/badges_manage.php b/Badges/badges_manage.php index fae8bcb..a90eff6 100644 --- a/Badges/badges_manage.php +++ b/Badges/badges_manage.php @@ -17,6 +17,9 @@ along with this program. If not, see . */ use Gibbon\Forms\Form; +use Gibbon\Tables\DataTable; +use Gibbon\Services\Format; +use Gibbon\Module\Badges\Domain\BadgeGateway; //Module includes include './modules/Badges/moduleFunctions.php'; @@ -57,12 +60,17 @@ $allRoles[$rowRoles['gibbonRoleID']] = $rowRoles['name']; } - $search = $_GET['search'] ?? ''; - $category = $_GET['category'] ?? ''; + $search = null; + if (isset($_GET['search'])) { + $search = $_GET['search']; + } + $category = null; + if (isset($_GET['category'])) { + $category = $_GET['category']; + } $form = Form::create('search', $gibbon->session->get('absoluteURL','').'/index.php', 'get'); $form->setTitle(__('Search & Filter')); - $form->addClass('noIntBorder'); $form->addHiddenValue('q', '/modules/'.$gibbon->session->get('module').'/badges_manage.php'); $form->addHiddenValue('address', '/modules/' . $gibbon->session->get('address')); @@ -86,125 +94,48 @@ echo __('View'); echo ''; - try { - $data = array(); - $sqlWhere = ''; - if ($search != '' || $category != '') { - $sqlWhere = 'WHERE '; - if ($search != '') { - $data['search'] = "%$search%"; - $sqlWhere .= 'badgesBadge.name LIKE :search AND '; - } - if ($category != '') { - $data['category'] = $category; - $sqlWhere .= 'badgesBadge.category=:category'; - } - if (mb_substr($sqlWhere, -5) == ' AND ') { - $sqlWhere = mb_substr($sqlWhere, 0, -5); - } - } - $sql = "SELECT badgesBadge.* FROM badgesBadge $sqlWhere ORDER BY category, badgesBadge.name"; - $sqlPage = $sql . ' LIMIT ' . $gibbon->session->get('pagination') . ' OFFSET ' . (($page - 1) * $gibbon->session->get('pagination')); - $result = $connection2->prepare($sql); - $result->execute($data); - } catch (PDOException $e) { - echo "
" . $e->getMessage() . '
'; - } - - echo "
"; - echo "" . __('Add') . ""; - echo '
'; - - if ($result->rowCount() < 1) { - echo "
"; - echo 'There are no badges to display.'; - echo '
'; - } else { - if ($result->rowCount() > $gibbon->session->get('pagination')) { - printPagination($guid, $result->rowCount(), $page, $gibbon->session->get('pagination'), 'top', "search=$search"); - } - - echo ""; - echo ""; - echo "'; - echo ''; - echo ''; - echo "'; - echo ''; - - $count = 0; - $rowNum = 'odd'; - try { - $resultPage = $connection2->prepare($sqlPage); - $resultPage->execute($data); - } catch (PDOException $e) { - echo "
" . $e->getMessage() . '
'; - } - while ($row = $resultPage->fetch()) { - if ($count % 2 == 0) { - $rowNum = 'even'; - } else { - $rowNum = 'odd'; - } - ++$count; - - if ($row['active'] == 'N') { - $rowNum = 'error'; - } - //COLOR ROW BY STATUS! - echo ""; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - if ($row['description'] != '') { - echo ""; - echo "'; - echo ''; - } - } - echo '
"; - echo __('Logo'); - echo ''; - echo 'Name
'; - echo '
'; - echo 'Category'; - echo '"; - echo 'Actions'; - echo '
'; - if ($row['logo'] != '') { - echo ""; - } else { - echo "session->get('gibbonThemeName') . "/img/anonymous_240_square.jpg'/>"; + $badgesGateway = $container->get(BadgeGateway::class); + $criteria = $badgesGateway->newQueryCriteria() + ->filterBy('badgeCategory',$_GET['category'] ?? '') + ->filterBy('badgeName',$_GET['search'] ?? '') + ->fromPOST(); + + $badges = $badgesGateway->queryBadges($criteria); + + $table = DataTable::createPaginated('badges',$criteria); + $table->addHeaderAction('add',__('Add'))->setURL('/modules/Badges/badges_manage_add.php') + ->addParam('search',$_GET['search'] ?? '') + ->addParam('category',$_GET['category'] ?? ''); + $table->addExpandableColumn('description') + ->format(function($row) { + $output = ''; + if (!empty($row['description']) && $row['description'] != '') { + $output .= ''.__('Description').'
'; + $output .= nl2brr($row['description']).'

'; } - echo '
'; - echo $row['name']; - echo ''; - echo $row['category']; - echo ''; - echo "'; - echo " "; - echo " "; - if ($row['description'] != '') { - echo ""; - } - echo '
"; - echo nl2brr($row['description']); - echo '
'; - - if ($result->rowCount() > $gibbon->session->get('pagination')) { - printPagination($guid, $result->rowCount(), $page, $gibbon->session->get('pagination'), 'bottom', "search=$search"); + return $output; + }); + $table->AddColumn('logo',__('Logo'))->width('155px')->format(function($row) use ($gibbon){ + if ($row['logo'] != '') { + echo ""; + } else { + echo "session->get('gibbonThemeName') . "/img/anonymous_240_square.jpg'/>"; } - } + }); + $table->AddColumn('name',__('Name')); + $table->AddColumn('category',__('Category')); + + $actions = $table->addActionColumn('actions',__('Actions')) + ->addParam('badgesBadgeID') + ->addParam('category',$_GET['category'] ?? '') + ->addParam('search',$_GET['search'] ?? ''); + $actions->AddAction('edit',__('Edit'))->setURL('/modules/Badges/badges_manage_edit.php'); + $actions->AddAction('delete',__('Delete'))->setURL('/modules/Badges/badges_manage_delete.php'); + + echo $table->render($badges); + + } + ?> diff --git a/Badges/badges_manage_add.php b/Badges/badges_manage_add.php index fbf4e2f..e0a9cb9 100644 --- a/Badges/badges_manage_add.php +++ b/Badges/badges_manage_add.php @@ -35,7 +35,10 @@ ->add(__('Add Badges')); $returns = array(); - $editLink = isset($editLink) ? $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/Badges/badges_manage_edit.php&badgesBadgeID='.$_GET['editID'].'&search='.$_GET['search'].'&category='.$_GET['category'] : ''; + $editLink = ''; + if (isset($_GET['editID'])) { + $editLink = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/Badges/badges_manage_edit.php&badgesBadgeID='.$_GET['editID'].'&search='.$_GET['search'].'&category='.$_GET['category']; + } if (isset($_GET['return'])) { returnProcess($guid, $_GET['return'], $editLink, null); } @@ -47,8 +50,8 @@ } - $form = Form::create('badges', $gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module').'/badges_manage_addProcess.php?search='.$_GET['search'].'&category='.$_GET['category']); - + $form = Form::create('badges', $gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module').'/badges_manage_addProcess.php','POST'); + $form->addHiddenValue('address', $gibbon->session->get('address')); $row = $form->addRow(); @@ -58,7 +61,7 @@ $row = $form->addRow(); $row->addLabel('active', __('Active')); $row->addYesNo('active')->required(); - + $categories = getSettingByScope($connection2, 'Badges', 'badgeCategories'); $categories = !empty($categories) ? array_map('trim', explode(',', $categories)) : []; $row = $form->addRow(); @@ -68,17 +71,17 @@ $row = $form->addRow(); $row->addLabel('description', __('Description')); $row->addTextArea('description'); - + $fileUploader = new FileUploader($pdo, $gibbon->session); - + $row = $form->addRow(); $row->addLabel('file', __('Logo'))->description(__('240px x 240px')); $row->addFileUpload('file')->accepts($fileUploader->getFileExtensions('Graphics/Design')); - + $row = $form->addRow(); $row->addLabel('logoLicense', __('Logo License/Credits')); $row->addTextArea('logoLicense'); - + $row = $form->addRow(); $row->addSubmit(); diff --git a/Badges/badges_manage_addProcess.php b/Badges/badges_manage_addProcess.php index b9960b8..859efe0 100644 --- a/Badges/badges_manage_addProcess.php +++ b/Badges/badges_manage_addProcess.php @@ -20,8 +20,9 @@ include '../../gibbon.php'; include './moduleFunctions.php'; - -$URL = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/'.getModuleName($_POST['address']).'/badges_manage_add.php&search='.$_GET['search'].'&category='.$_GET['category']; +$category = $_GET['category'] ?? ''; +$search = $_GET['search'] ?? ''; +$URL = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/'.getModuleName($_POST['address']).'/badges_manage_add.php&search='. $search .'&category='.$category ?? ''; if (isActionAccessible($guid, $connection2, '/modules/Badges/badges_manage_add.php') == false) { //Fail 0 diff --git a/Badges/badges_manage_delete.php b/Badges/badges_manage_delete.php index 304a357..053cb79 100644 --- a/Badges/badges_manage_delete.php +++ b/Badges/badges_manage_delete.php @@ -58,7 +58,13 @@ //Let's go! $row = $result->fetch(); - $form = DeleteForm::createForm($gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module')."/badges_manage_deleteProcess.php?badgesBadgeID=$badgesBadgeID&search=".$_GET['search']."&&category=" . $_GET['category']); + if ($_GET['category'] != '') { + echo "
"; + echo "Back to Search Results"; + echo '
'; + } + + $form = DeleteForm::createForm($gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module')."/badges_manage_deleteProcess.php?badgesBadgeID=$badgesBadgeID&search=".$_GET['category']."&category=" . $_GET['category']); echo $form->getOutput(); } } diff --git a/Badges/badges_manage_edit.php b/Badges/badges_manage_edit.php index 2ae3534..edf2a7f 100644 --- a/Badges/badges_manage_edit.php +++ b/Badges/badges_manage_edit.php @@ -39,7 +39,9 @@ } //Check if school year specified - $badgesBadgeID = $_GET['badgesBadgeID']; + $badgesBadgeID = $_GET['badgesBadgeID'] ?? ''; + $search = $_GET['search'] ?? ''; + $category = $_GET['category'] ?? ''; if ($badgesBadgeID == '') { echo "
"; echo 'You have not specified a policy.'; echo '
'; @@ -61,13 +63,13 @@ //Let's go! $values = $result->fetch(); - if ($_GET['search'] != '' || $_GET['category'] != '') { + if ($category != '' || $category != '') { echo "
"; - echo "Back to Search Results"; + echo "Back to Search Results"; echo '
'; } - $form = Form::create('badges', $gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module').'/badges_manage_editProcess.php?badgesBadgeID='.$badgesBadgeID.'&search='.$_GET['search'].'&category='.$_GET['category']); + $form = Form::create('badges', $gibbon->session->get('absoluteURL','').'/modules/'.$gibbon->session->get('module').'/badges_manage_editProcess.php?badgesBadgeID='.$badgesBadgeID.'&search='.$category.'&category='.$category); $form->addHiddenValue('address', $gibbon->session->get('address')); diff --git a/Badges/badges_manage_editProcess.php b/Badges/badges_manage_editProcess.php index f682675..fce45fb 100644 --- a/Badges/badges_manage_editProcess.php +++ b/Badges/badges_manage_editProcess.php @@ -21,7 +21,7 @@ include './moduleFunctions.php'; -$badgesBadgeID = $_GET['badgesBadgeID'] ?? ''; +$badgesBadgeID = $_GET['badgesBadgeID']; $URL = $gibbon->session->get('absoluteURL','').'/index.php?q=/modules/'.getModuleName($_POST['address'])."/badges_manage_edit.php&badgesBadgeID=$badgesBadgeID&search=".$_GET['search']."&category=".$_GET['category']; if (isActionAccessible($guid, $connection2, '/modules/Badges/badges_manage_edit.php') == false) { diff --git a/Badges/badges_view.php b/Badges/badges_view.php index bc7bac8..7fb7944 100644 --- a/Badges/badges_view.php +++ b/Badges/badges_view.php @@ -39,9 +39,12 @@ echo '
'; } else { if ($highestAction == 'View Badges_all') { - $gibbonPersonID = $_GET['gibbonPersonID'] ?? ''; + $gibbonPersonID = null; + if (isset($_GET['gibbonPersonID'])) { + $gibbonPersonID = $_GET['gibbonPersonID']; + } - $form = Form::create('search', $gibbon->session->get('absoluteURL','').'/index.php', 'GET'); + $form = Form::create('search', $gibbon->session->get('absoluteURL','').'/index.php', 'get'); $form->setTitle(__('Choose Student')); $form->addClass('noIntBorder'); $form->setFactory(DatabaseFormFactory::create($pdo)); @@ -101,8 +104,10 @@ echo getBadges($connection2, $guid, $gibbon->session->get('gibbonPersonID')); } } elseif ($highestAction == 'View Badges_myChildren') { - $gibbonPersonID = $gibbon->session->get('gibbonPersonID') ?? $_GET['search']; - + $gibbonPersonID = $gibbon->session->get('gibbonPersonID'); + if (isset($_GET['search'])) { + $gibbonPersonID = $_GET['search']; + } //Test data access field for permission try { $data = array('gibbonPersonID' => $gibbon->session->get('gibbonPersonID')); diff --git a/Badges/badges_view_available.php b/Badges/badges_view_available.php index 16fcd9f..3d5a631 100644 --- a/Badges/badges_view_available.php +++ b/Badges/badges_view_available.php @@ -47,24 +47,23 @@ $form = Form::create('grantbadges',$gibbon->session->get('absoluteURL').'/index.php','GET'); $form->setFactory(DatabaseFormFactory::create($pdo)); - $form->addClass('noIntBorder'); $form->addHiddenValue('q','/modules/' . $gibbon->session->get('module') . '/badges_view_available.php'); $form->addHiddenValue('address',$gibbon->session->get('address')); - + $row = $form->addRow(); $row->addLabel('search',__('Search For'))->description("Badge name"); - $row->addTextField('search')->setValue($search); - + $row->addTextField('search'); + $sql = "SELECT distinct category as value, category as name FROM badgesBadge WHERE active='Y' ORDER BY category, name"; $row = $form->addRow(); $row->addLabel('category',__('Category')); - $row->addSelect('category')->fromQuery($pdo, $sql, [])->selected($category)->placeholder(); - + $row->addSelect('category')->fromQuery($pdo, $sql, [])->placeholder(); + $row = $form->addRow()->addSearchSubmit($gibbon->session); echo $form->getOutput(); ?> - + "; echo 'View'; diff --git a/Badges/hook_parentalDashboard_badgesView.php b/Badges/hook_parentalDashboard_badgesView.php index 671daf0..b15a036 100644 --- a/Badges/hook_parentalDashboard_badgesView.php +++ b/Badges/hook_parentalDashboard_badgesView.php @@ -23,7 +23,7 @@ $included = false; $includes = get_included_files(); foreach ($includes as $include) { - if ($include == $_SESSION[$guid]['absoluteURL'].'/modules/Badges/moduleFunctions.php') { + if ($include == $gibbon->session->get('absolutePath','').'/modules/Badges/moduleFunctions.php') { $included = true; } } diff --git a/Badges/manifest.php b/Badges/manifest.php index 8f1fdef..bb5a584 100644 --- a/Badges/manifest.php +++ b/Badges/manifest.php @@ -25,7 +25,7 @@ $entryURL = 'badges_view.php'; $type = 'Additional'; $category = 'Assess'; -$version = '2.5.04'; +$version = '2.5.05'; $author = 'Ross Parker'; $url = 'http://rossparker.org'; diff --git a/Badges/moduleFunctions.php b/Badges/moduleFunctions.php index 053120a..d7c507d 100644 --- a/Badges/moduleFunctions.php +++ b/Badges/moduleFunctions.php @@ -17,10 +17,18 @@ along with this program. If not, see . */ -function getBadges($connection2, $guid, $gibbonPersonID) +function getBadges($connection2, $guid, $gibbonPersonID, $gibbon = null) { $output = ''; + $gibbonThemeName = $_SESSION['gibbonThemeName'] ?? 'Default'; + $absoluteURL = $_SESSION['absoluteURL'] ?? ''; + if($gibbon != null) + { + $gibbonThemeName = $gibbon->session->get('gibbonThemeName'); + $absoluteURL = $gibbon->session->get('absoluteURL'); + } + try { $data = array('gibbonPersonID' => $gibbonPersonID); $sql = 'SELECT badgesBadgeStudent.*, badgesBadge.name AS award, badgesBadge.logo AS logo, badgesBadge.category AS category, gibbonSchoolYear.name AS year FROM badgesBadgeStudent JOIN badgesBadge ON (badgesBadgeStudent.badgesBadgeID=badgesBadge.badgesBadgeID) JOIN gibbonSchoolYear ON (badgesBadgeStudent.gibbonSchoolYearID=gibbonSchoolYear.gibbonSchoolYearID) WHERE gibbonPersonID=:gibbonPersonID ORDER BY gibbonSchoolYear.sequenceNumber DESC, date DESC'; @@ -43,13 +51,11 @@ function getBadges($connection2, $guid, $gibbonPersonID) $awardYears[$row['year']][1] = array("$innerCount" => $row['award']); $awardYears[$row['year']][2] = array("$innerCount" => $row['logo']); $awardYears[$row['year']][3] = array("$innerCount" => $row['category']); - $awardYears[$row['year']][4] = array("$innerCount" => $row['comment']); ++$innerCount; } else { //Already data, so start appending $awardYears[$row['year']][1][$innerCount] = $row['award']; $awardYears[$row['year']][2][$innerCount] = $row['logo']; $awardYears[$row['year']][3][$innerCount] = $row['category']; - $awardYears[$row['year']][4][$innerCount] = $row['comment']; ++$innerCount; } } @@ -72,16 +78,12 @@ function getBadges($connection2, $guid, $gibbonPersonID) $output .= ""; if ($awardYear[2][$count] != '') { - $output .= "
"; + $output .= "
"; } else { - $output .= "session->get('gibbonThemeName')."/img/anonymous_240_square.jpg'/>
"; + $output .= "
"; } $output .= ''.$awards.'
'; $output .= ''.$awardYear[3][$count].'
'; - if(array_key_exists($count,$awardYear[4])) - { - $output .= ''.$awardYear[4][$count].'
'; - } $output .= ''; if ($count % $columns == ($columns - 1)) { diff --git a/Badges/src/Domain/BadgeGateway.php b/Badges/src/Domain/BadgeGateway.php new file mode 100644 index 0000000..4196174 --- /dev/null +++ b/Badges/src/Domain/BadgeGateway.php @@ -0,0 +1,144 @@ +newQuery() + ->from($this->getTableName() . ' as bb') + ->cols([ + 'bbs.badgesBadgeStudentID as badgesBadgeStudentID', + 'bb.badgesBadgeID as badgesBadgeID', + 'bb.logo as logo', + 'bb.name as name', + 'bb.category as category', + 'bb.description as description', + 'bbs.date as date', + 'bbs.comment as comment', + 'p.gibbonPersonID as gibbonPersonID', + 'p.title as title', + 'p.surname as surname', + 'p.preferredName as preferredName' + ]) + ->innerJoin('badgesBadgeStudent as bbs', 'bbs.badgesBadgeID = bb.badgesBadgeID') + ->innerJoin('gibbonPerson as p', 'bbs.gibbonPersonID = p.gibbonPersonID') + ->where('bbs.gibbonSchoolYearID = :gibbonSchoolYearID') + ->bindValue('gibbonSchoolYearID', $gibbonSchoolYearID); + + $criteria->addFilterRules([ + 'studentName' => function($query,$nameNeedle) + { + $nameNeedle = '%' . $nameNeedle . '%'; + return $query + ->where("(p.surname like :nameNeedle or p.preferredName like :nameNeedle)") + ->bindValue('nameNeedle',$nameNeedle); + }, + 'badgeId' => function($query,$badgeID) + { + return $query + ->where("bb.badgesBadgeID = :badgeID") + ->bindValue('badgeID',$badgeID); + }, + 'studentId' => function($query,$studentID) + { + return $query + ->where("p.gibbonPersonID = :studentID") + ->bindValue('studentID',$studentID); + }, + 'studentIdMulti' => function($query,$studentIDArr) + { + $colName = 'p.gibbonPersonID'; + $whereClause = "("; + foreach($studentIDArr as $key => $studentID ) + { + $whereClause .= $colName . " = :needle_" . $key; + + if($key != (sizeof($studentIDArr) - 1)) + { + $whereClause .= ' OR '; + } + $query + ->bindValue('needle_' . $key ,$studentID); + } + $whereClause .= ")"; + $query->where($whereClause); + return $query; + + }, + 'badgeStudentID' => function($query,$badgeStudentID) + { + return $query + ->where("bbs.badgesBadgeStudentID = :badgeStudentID") + ->bindValue('badgeStudentID',$badgeStudentID); + }, + 'badgeName' => function($query,$badgeNameNeedle) + { + $badgeNameNeedle = '%' . $badgeNameNeedle . '%'; //Surround in wildcards + return $query + ->where("(bb.name like :badgeNameNeedle)") + ->bindValue('badgeNameNeedle',$badgeNameNeedle); + }, + 'badgeCategory' => function($query,$category) + { + return $query + ->where("(bb.category = :category)") + ->bindValue('category',$category); + + } + ]); + + return $this->runQuery($query,$criteria); + } + + public function queryBadges(QueryCriteria $criteria) + { + $query = $this + ->newQuery() + ->from($this->getTableName() . ' as bb') + ->cols([ + 'bb.badgesBadgeID as badgesBadgeID', + 'bb.logo as logo', + 'bb.name as name', + 'bb.category as category', + 'bb.description as description' + ]); + + $criteria->addFilterRules([ + 'badgeId' => function($query,$badgeID) + { + return $query + ->where("bb.badgesBadgeID = :badgeID") + ->bindValue('badgeID',$badgeID); + }, + 'badgeName' => function($query,$badgeNameNeedle) + { + $badgeNameNeedle = '%' . $badgeNameNeedle . '%'; //Surround in wildcards + return $query + ->where("(bb.name like :badgeNameNeedle)") + ->bindValue('badgeNameNeedle',$badgeNameNeedle); + }, + 'badgeCategory' => function($query,$category) + { + return $query + ->where("(bb.category = :category)") + ->bindValue('category',$category); + + } + ]); + + return $this->runQuery($query,$criteria); + } +} + +?> \ No newline at end of file diff --git a/Badges/version.php b/Badges/version.php index 39b0060..8c435c7 100644 --- a/Badges/version.php +++ b/Badges/version.php @@ -20,4 +20,4 @@ /** * Sets version information. */ -$moduleVersion = '2.5.04'; +$moduleVersion = '2.5.05';