From c5115754abe7fb046ecbfb9e4d94975502333e2a Mon Sep 17 00:00:00 2001 From: Ali Date: Wed, 24 Apr 2024 15:28:04 +0800 Subject: [PATCH 1/9] Behaviour: added the behaviour_view_my permission so that teachers can view the records created by them --- CHANGEDB.php | 1 + modules/Behaviour/behaviour_view.php | 6 +++++ modules/Behaviour/behaviour_view_details.php | 24 +++++++++++++++++--- modules/Behaviour/moduleFunctions.php | 15 ++++++++++-- modules/Students/student_view_details.php | 2 +- src/Domain/Behaviour/BehaviourGateway.php | 16 +++++++++++++ 6 files changed, 58 insertions(+), 6 deletions(-) diff --git a/CHANGEDB.php b/CHANGEDB.php index a9fb173ba9..42f58f023a 100644 --- a/CHANGEDB.php +++ b/CHANGEDB.php @@ -805,4 +805,5 @@ CREATE TABLE `gibbonBehaviourFollowUp` ( `gibbonBehaviourFollowUpID` INT(11) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, `gibbonBehaviourID` INT(12) UNSIGNED ZEROFILL NOT NULL, `gibbonPersonID` INT(10) UNSIGNED ZEROFILL NOT NULL, `followUp` TEXT, `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`gibbonBehaviourFollowUpID`), KEY `gibbonBehaviourID` (`gibbonBehaviourID`));end ALTER TABLE `gibbonReportingCriteriaType` ADD `options` TEXT NULL AFTER `gibbonScaleID`;end INSERT INTO `gibbonNotificationEvent` (`event`, `moduleName`, `actionName`, `type`, `scopes`, `active`) VALUES ('Student Form Group Changed', 'Admissions', 'View Student Profile_full', 'Core', 'All,gibbonYearGroupID', 'Y');end +INSERT INTO `gibbonAction` (`gibbonModuleID`, `name`, `precedence`, `category`, `description`, `URLList`, `entryURL`, `entrySidebar`, `menuShow`, `defaultPermissionAdmin`, `defaultPermissionTeacher`, `defaultPermissionStudent`, `defaultPermissionParent`, `defaultPermissionSupport`, `categoryPermissionStaff`, `categoryPermissionStudent`, `categoryPermissionParent`, `categoryPermissionOther`) VALUES((SELECT gibbonModuleID FROM gibbonModule WHERE name='Behaviour'), 'View Behaviour Records_my', 0, 'Behaviour Records', 'Enables users to view the behaviour records created by them', 'behaviour_view.php,behaviour_view_details.php', 'behaviour_view.php', 'Y', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y', 'N', 'N', 'N');end "; diff --git a/modules/Behaviour/behaviour_view.php b/modules/Behaviour/behaviour_view.php index a7aabad088..890a1a9a41 100644 --- a/modules/Behaviour/behaviour_view.php +++ b/modules/Behaviour/behaviour_view.php @@ -19,6 +19,7 @@ along with this program. If not, see . */ +use Gibbon\Domain\Behaviour\BehaviourGateway; use Gibbon\Forms\Form; use Gibbon\Forms\DatabaseFormFactory; use Gibbon\Tables\DataTable; @@ -75,6 +76,11 @@ $table = DataTable::create('behaviour'); $table->setTitle( __('My Children')); + } else if ($highestAction == 'View Behaviour Records_my') { + $students = $container->get(BehaviourGateway::class)->selectStudentsFromBehaviourByCreator($session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID'))->toDataSet(); + + $table = DataTable::create('behaviour'); + $table->setTitle( __('My Students')); } else { return; } diff --git a/modules/Behaviour/behaviour_view_details.php b/modules/Behaviour/behaviour_view_details.php index 528dd68726..f86c2106ec 100644 --- a/modules/Behaviour/behaviour_view_details.php +++ b/modules/Behaviour/behaviour_view_details.php @@ -52,17 +52,31 @@ if (!empty($search)) { $page->navigator->addSearchResultsAction(Url::fromModuleRoute('Behaviour', 'behaviour_view.php')->withQueryParam('search', $search)); } - try { if ($highestAction == 'View Behaviour Records_all') { $data = array('gibbonPersonID' => $gibbonPersonID, 'gibbonSchoolYearID' => $session->get('gibbonSchoolYearID')); $sql = "SELECT gibbonPerson.gibbonPersonID, gibbonStudentEnrolmentID, surname, preferredName, gibbonYearGroup.nameShort AS yearGroup, gibbonFormGroup.nameShort AS formGroup FROM gibbonPerson JOIN gibbonStudentEnrolment ON (gibbonPerson.gibbonPersonID=gibbonStudentEnrolment.gibbonPersonID) JOIN gibbonYearGroup ON (gibbonStudentEnrolment.gibbonYearGroupID=gibbonYearGroup.gibbonYearGroupID) JOIN gibbonFormGroup ON (gibbonStudentEnrolment.gibbonFormGroupID=gibbonFormGroup.gibbonFormGroupID) WHERE status='Full' AND (dateStart IS NULL OR dateStart<='".date('Y-m-d')."') AND (dateEnd IS NULL OR dateEnd>='".date('Y-m-d')."') AND gibbonPerson.gibbonPersonID=:gibbonPersonID AND gibbonStudentEnrolment.gibbonSchoolYearID=:gibbonSchoolYearID"; - } else { + } else if ($highestAction == 'View Behaviour Records_myChildren') { $data = array('gibbonSchoolYearID' => $session->get('gibbonSchoolYearID'), 'gibbonPersonID' => $session->get('gibbonPersonID'), 'gibbonPersonID2' => $gibbonPersonID); $sql = "SELECT gibbonPerson.gibbonPersonID, gibbonStudentEnrolmentID, surname, preferredName, gibbonYearGroup.nameShort AS yearGroup, gibbonFormGroup.nameShort AS formGroup FROM gibbonPerson JOIN gibbonStudentEnrolment ON (gibbonPerson.gibbonPersonID=gibbonStudentEnrolment.gibbonPersonID) JOIN gibbonYearGroup ON (gibbonStudentEnrolment.gibbonYearGroupID=gibbonYearGroup.gibbonYearGroupID) JOIN gibbonFormGroup ON (gibbonStudentEnrolment.gibbonFormGroupID=gibbonFormGroup.gibbonFormGroupID) JOIN gibbonFamilyChild ON (gibbonPerson.gibbonPersonID=gibbonFamilyChild.gibbonPersonID) JOIN gibbonFamily ON (gibbonFamilyChild.gibbonFamilyID=gibbonFamily.gibbonFamilyID) JOIN gibbonFamilyAdult ON (gibbonFamilyAdult.gibbonFamilyID=gibbonFamily.gibbonFamilyID AND childDataAccess='Y') WHERE gibbonFamilyAdult.gibbonPersonID=:gibbonPersonID AND gibbonStudentEnrolment.gibbonSchoolYearID=:gibbonSchoolYearID AND gibbonPerson.status='Full' AND (dateStart IS NULL OR dateStart<='".date('Y-m-d')."') AND (dateEnd IS NULL OR dateEnd>='".date('Y-m-d')."') AND gibbonPerson.gibbonPersonID=:gibbonPersonID2 ORDER BY surname, preferredName"; + } else if ($highestAction == 'View Behaviour Records_my') { + $data = ['gibbonSchoolYearID' => $session->get('gibbonSchoolYearID'), 'gibbonPersonIDCreator' => $session->get('gibbonPersonID'), 'gibbonPersonID' => $gibbonPersonID, 'today' => date('Y-m-d')]; + $sql = "SELECT gibbonPerson.gibbonPersonID, surname, preferredName, gibbonYearGroup.nameShort AS yearGroup, gibbonFormGroup.nameShort AS formGroup + FROM gibbonBehaviour + JOIN gibbonPerson ON (gibbonBehaviour.gibbonPersonID=gibbonPerson.gibbonPersonID) + JOIN gibbonStudentEnrolment ON (gibbonPerson.gibbonPersonID=gibbonStudentEnrolment.gibbonPersonID) + JOIN gibbonYearGroup ON (gibbonStudentEnrolment.gibbonYearGroupID=gibbonYearGroup.gibbonYearGroupID) + JOIN gibbonFormGroup ON (gibbonStudentEnrolment.gibbonFormGroupID=gibbonFormGroup.gibbonFormGroupID) + WHERE gibbonBehaviour.gibbonPersonIDCreator=:gibbonPersonIDCreator AND gibbonStudentEnrolment.gibbonSchoolYearID=:gibbonSchoolYearID AND gibbonPerson.status='Full' AND (dateStart IS NULL OR dateStart<=:today) AND (dateEnd IS NULL OR dateEnd>=:today) AND gibbonPerson.gibbonPersonID=:gibbonPersonID + GROUP BY gibbonPerson.gibbonPersonID, yearGroup, formGroup + ORDER BY surname, preferredName"; + } else { + return; } + $result = $connection2->prepare($sql); $result->execute($data); + } catch (PDOException $e) { } @@ -79,7 +93,11 @@ echo $table->render([$row]); - echo getBehaviourRecord($container, $gibbonPersonID); + if ($highestAction == 'View Behaviour Records_my') { + echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID')); + } else { + echo getBehaviourRecord($container, $gibbonPersonID, null); + } } } } diff --git a/modules/Behaviour/moduleFunctions.php b/modules/Behaviour/moduleFunctions.php index 042a850bb1..662d43df46 100644 --- a/modules/Behaviour/moduleFunctions.php +++ b/modules/Behaviour/moduleFunctions.php @@ -26,7 +26,7 @@ use Gibbon\Domain\Behaviour\BehaviourGateway; use Gibbon\Domain\Students\StudentGateway; -function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID) +function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gibbonPersonIDCreator) { global $session; @@ -58,7 +58,18 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID) ->sortBy('timestamp', 'DESC') ->fromPOST($schoolYear['gibbonSchoolYearID']); - $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID); + if (empty($gibbonPersonIDCreator)) { + $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID); + } else { + $result = $behaviourGateway->getBehaviourRecordsByPersonAndCreator($schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator); + + $behaviourRecords = $result->fetchAll(); + } + + // echo '
';
+	        // print_r($behaviourRecords);
+	        // echo '
'; + // die(); $table = DataTable::createPaginated('behaviour'.$schoolYear['gibbonSchoolYearID'], $criteria); $table->setTitle($schoolYear['name']); diff --git a/modules/Students/student_view_details.php b/modules/Students/student_view_details.php index ee759942b1..7d5f40ca1b 100644 --- a/modules/Students/student_view_details.php +++ b/modules/Students/student_view_details.php @@ -2428,7 +2428,7 @@ include './modules/Behaviour/moduleFunctions.php'; //Print assessments - echo getBehaviourRecord($container, $gibbonPersonID); + echo getBehaviourRecord($container, $gibbonPersonID, null); } } diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php index 04672552b4..0e4953748b 100644 --- a/src/Domain/Behaviour/BehaviourGateway.php +++ b/src/Domain/Behaviour/BehaviourGateway.php @@ -230,6 +230,13 @@ public function queryBehaviourRecordsByPerson(QueryCriteria $criteria, $gibbonSc return $this->runQuery($query, $criteria); } + public function getBehaviourRecordsByPersonAndCreator($gibbonSchoolYearID, $gibbonPersonID, $gibbonPersonIDCreator) { + $data = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonPersonID' => $gibbonPersonID, 'gibbonPersonIDCreator' => $gibbonPersonIDCreator]; + $sql = 'SELECT gibbonBehaviour.*, creator.title as titleCreator, creator.surname AS surnameCreator, creator.preferredName AS preferredNameCreator FROM gibbonBehaviour JOIN gibbonPerson AS creator ON (gibbonBehaviour.gibbonPersonIDCreator=creator.gibbonPersonID) WHERE gibbonSchoolYearID=:gibbonSchoolYearID AND gibbonBehaviour.gibbonPersonID=:gibbonPersonID AND gibbonBehaviour.gibbonPersonIDCreator=:gibbonPersonIDCreator ORDER BY date DESC'; + + return $this->db()->select($sql, $data); + } + public function getBehaviourDetails($gibbonSchoolYearID, $gibbonBehaviourID) { $data = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonBehaviourID' => $gibbonBehaviourID]; @@ -268,4 +275,13 @@ public function updateMultiIncidentIDByBehaviourID($gibbonBehaviourID, $gibbonMu return $this->db()->update($sql, $data); } + + public function selectStudentsFromBehaviourByCreator($gibbonSchoolYearID, $gibbonPersonID) + { + $data = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonPersonID' => $gibbonPersonID, 'today' => date('Y-m-d')]; + $sql = "SELECT gibbonPerson.gibbonPersonID, title, surname, preferredName, image_240, gibbonYearGroup.nameShort AS yearGroup, gibbonFormGroup.nameShort AS formGroup, 'Student' as roleCategory + FROM gibbonBehaviour JOIN gibbonPerson ON (gibbonBehaviour.gibbonPersonID=gibbonPerson.gibbonPersonID) JOIN gibbonStudentEnrolment ON (gibbonPerson.gibbonPersonID=gibbonStudentEnrolment.gibbonPersonID) JOIN gibbonYearGroup ON (gibbonStudentEnrolment.gibbonYearGroupID=gibbonYearGroup.gibbonYearGroupID) JOIN gibbonFormGroup ON (gibbonStudentEnrolment.gibbonFormGroupID=gibbonFormGroup.gibbonFormGroupID) WHERE gibbonBehaviour.gibbonPersonIDCreator=:gibbonPersonID AND gibbonStudentEnrolment.gibbonSchoolYearID=:gibbonSchoolYearID AND gibbonPerson.status='Full' AND (dateStart IS NULL OR dateStart<=:today) AND (dateEnd IS NULL OR dateEnd>=:today) GROUP BY gibbonPerson.gibbonPersonID, yearGroup, formGroup ORDER BY surname, preferredName"; + + return $this->db()->select($sql, $data); + } } From 720ee5ecafccf22fcaf0ff1fbf697c58a794f424 Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 25 Apr 2024 13:26:36 +0800 Subject: [PATCH 2/9] Bug fixing --- modules/Behaviour/behaviour_manage.php | 1 - modules/Behaviour/behaviour_view.php | 20 +++++++++++--- modules/Behaviour/moduleFunctions.php | 33 ++++++++++------------- src/Domain/Behaviour/BehaviourGateway.php | 4 ++- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/modules/Behaviour/behaviour_manage.php b/modules/Behaviour/behaviour_manage.php index 10364b1b55..18fb77b90e 100644 --- a/modules/Behaviour/behaviour_manage.php +++ b/modules/Behaviour/behaviour_manage.php @@ -95,7 +95,6 @@ ->filterBy('type', $type) ->fromPOST(); - if ($highestAction == 'Manage Behaviour Records_all') { $records = $behaviourGateway->queryBehaviourBySchoolYear($criteria, $session->get('gibbonSchoolYearID')); } else if ($highestAction == 'Manage Behaviour Records_my') { diff --git a/modules/Behaviour/behaviour_view.php b/modules/Behaviour/behaviour_view.php index 890a1a9a41..cc1fce02d4 100644 --- a/modules/Behaviour/behaviour_view.php +++ b/modules/Behaviour/behaviour_view.php @@ -39,11 +39,10 @@ $search = $_GET['search'] ?? ''; - if ($highestAction == 'View Behaviour Records_all') { + if ($highestAction == 'View Behaviour Records_all' || $highestAction == 'View Behaviour Records_my') { $form = Form::create('filter', $session->get('absoluteURL').'/index.php', 'get'); $form->setTitle(__('Search')); $form->setClass('noIntBorder fullWidth'); - $form->addHiddenValue('q', '/modules/Behaviour/behaviour_view.php'); $row = $form->addRow(); @@ -76,11 +75,26 @@ $table = DataTable::create('behaviour'); $table->setTitle( __('My Children')); + } else if ($highestAction == 'View Behaviour Records_my') { + + $criteria = $studentGateway->newQueryCriteria(true) + ->searchBy($studentGateway->getSearchableColumns(), $search) + ->sortBy(['surname', 'preferredName']) + ->fromPOST(); + $students = $container->get(BehaviourGateway::class)->selectStudentsFromBehaviourByCreator($session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID'))->toDataSet(); - $table = DataTable::create('behaviour'); + //$students = $studentGateway->queryBehaviourBySchoolYearAndCreator($criteria, $session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID')); + + // echo '
';
+            // print_r($students);
+            // echo '
'; + // die(); + + $table = DataTable::createPaginated('behaviour', $criteria); $table->setTitle( __('My Students')); + } else { return; } diff --git a/modules/Behaviour/moduleFunctions.php b/modules/Behaviour/moduleFunctions.php index 662d43df46..8cea86c067 100644 --- a/modules/Behaviour/moduleFunctions.php +++ b/modules/Behaviour/moduleFunctions.php @@ -65,12 +65,7 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gib $behaviourRecords = $result->fetchAll(); } - - // echo '
';
-	        // print_r($behaviourRecords);
-	        // echo '
'; - // die(); - + $table = DataTable::createPaginated('behaviour'.$schoolYear['gibbonSchoolYearID'], $criteria); $table->setTitle($schoolYear['name']); @@ -97,37 +92,37 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gib $table->addMetaData('hidePagination', true); $table->addExpandableColumn('comment') - ->format(function($beahviour) { + ->format(function($behaviour) { $output = ''; - if (!empty($beahviour['comment'])) { + if (!empty($behaviour['comment'])) { $output .= ''.__('Incident').'
'; - $output .= nl2br($beahviour['comment']).'
'; + $output .= nl2br($behaviour['comment']).'
'; } - if (!empty($beahviour['followup'])) { + if (!empty($behaviour['followup'])) { $output .= '
'.__('Follow Up').'
'; - $output .= nl2br($beahviour['followup']).'
'; + $output .= nl2br($behaviour['followup']).'
'; } return $output; }); $table->addColumn('date', __('Date')) ->context('primary') - ->format(function($beahviour) { - if (substr($beahviour['timestamp'], 0, 10) > $beahviour['date']) { - return __('Updated:').' '.Format::date($beahviour['timestamp']).'
' - . __('Incident:').' '.Format::date($beahviour['date']).'
'; + ->format(function($behaviour) { + if (substr($behaviour['timestamp'], 0, 10) > $behaviour['date']) { + return __('Updated:').' '.Format::date($behaviour['timestamp']).'
' + . __('Incident:').' '.Format::date($behaviour['date']).'
'; } else { - return Format::date($beahviour['timestamp']); + return Format::date($behaviour['timestamp']); } }); $table->addColumn('type', __('Type')) ->context('secondary') ->width('5%') - ->format(function($beahviour) use ($session) { - if ($beahviour['type'] == 'Negative') { + ->format(function($behaviour) use ($session) { + if ($behaviour['type'] == 'Negative') { return " "; - } elseif ($beahviour['type'] == 'Positive') { + } elseif ($behaviour['type'] == 'Positive') { return " "; } }); diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php index 0e4953748b..13ef22832e 100644 --- a/src/Domain/Behaviour/BehaviourGateway.php +++ b/src/Domain/Behaviour/BehaviourGateway.php @@ -23,6 +23,7 @@ use Gibbon\Domain\QueryCriteria; use Gibbon\Domain\QueryableGateway; +use Gibbon\Domain\Traits\SharedUserLogic; use Gibbon\Domain\ScrubbableGateway; use Gibbon\Domain\Traits\Scrubbable; use Gibbon\Domain\Traits\TableAware; @@ -39,11 +40,12 @@ class BehaviourGateway extends QueryableGateway implements ScrubbableGateway use TableAware; use Scrubbable; use ScrubByPerson; + use SharedUserLogic; private static $tableName = 'gibbonBehaviour'; private static $primaryKey = 'gibbonBehaviourID'; - private static $searchableColumns = []; + private static $searchableColumns = ['gibbonBehaviour.gibbonBehaviourID','gibbonBehaviour.type', 'gibbonBehaviour.descriptor', 'gibbonBehaviour.level', 'gibbonBehaviour.date', 'gibbonBehaviour.timestamp', 'gibbonBehaviour.comment']; private static $scrubbableKey = 'gibbonPersonID'; private static $scrubbableColumns = ['descriptor' => null, 'level' => null, 'comment' => '']; From 886270f344807ab39b8e4234df6540d2e624b7d1 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 29 Apr 2024 11:57:37 +0800 Subject: [PATCH 3/9] Behaviour: added the Behaviour Records_my permissions so that teachers are restricted to only view the records created by them --- CHANGELOG.txt | 1 + modules/Behaviour/behaviour_manage.php | 3 +- modules/Behaviour/behaviour_view.php | 13 ++--- modules/Behaviour/behaviour_view_details.php | 2 +- modules/Behaviour/moduleFunctions.php | 6 +-- modules/Students/student_view_details.php | 8 ++- src/Domain/Behaviour/BehaviourGateway.php | 57 +++++++++++++++----- 7 files changed, 62 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cd090253af..f05d5c75a3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -46,6 +46,7 @@ v27.0.00 Behaviour: updated the view so that followups are displayed as conversational logs and stored in a separate table Behaviour: added the ability to able to link a behaviour record to some other existing behaviour record Behaviour: added positive behaviour records to the Daily Behaviour Summary CLI script + Behaviour: Implemented the _my permission so that teachers/staff can only view the behaviours records created by them Library: added ui changes to Library module browsing through library shelves and improved search page Library: added automatic shelf generation by search term, automatic shelf updates, and auto-shuffling Library: added autocomplete to the Vendor and Location Detail fields in Add/Edit under Manage Catalogue diff --git a/modules/Behaviour/behaviour_manage.php b/modules/Behaviour/behaviour_manage.php index 18fb77b90e..fd21cf66cd 100644 --- a/modules/Behaviour/behaviour_manage.php +++ b/modules/Behaviour/behaviour_manage.php @@ -95,7 +95,8 @@ ->filterBy('type', $type) ->fromPOST(); - if ($highestAction == 'Manage Behaviour Records_all') { + + if ($highestAction == 'Manage Behaviour Records_all') { $records = $behaviourGateway->queryBehaviourBySchoolYear($criteria, $session->get('gibbonSchoolYearID')); } else if ($highestAction == 'Manage Behaviour Records_my') { $records = $behaviourGateway->queryBehaviourBySchoolYear($criteria, $session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID')); diff --git a/modules/Behaviour/behaviour_view.php b/modules/Behaviour/behaviour_view.php index cc1fce02d4..3add9e5a97 100644 --- a/modules/Behaviour/behaviour_view.php +++ b/modules/Behaviour/behaviour_view.php @@ -56,6 +56,7 @@ } $studentGateway = $container->get(StudentGateway::class); + $behaviourGateway = $container->get(BehaviourGateway::class); // DATA TABLE if ($highestAction == 'View Behaviour Records_all') { @@ -65,7 +66,8 @@ ->sortBy(['surname', 'preferredName']) ->fromPOST(); - $students = $studentGateway->queryStudentsBySchoolYear($criteria, $session->get('gibbonSchoolYearID'), false); + $students = $behaviourGateway->queryAllBehaviourStudentsBySchoolYear($criteria, $session->get('gibbonSchoolYearID')); + $table = DataTable::createPaginated('behaviour', $criteria); $table->setTitle(__('Choose A Student')); @@ -83,14 +85,7 @@ ->sortBy(['surname', 'preferredName']) ->fromPOST(); - $students = $container->get(BehaviourGateway::class)->selectStudentsFromBehaviourByCreator($session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID'))->toDataSet(); - - //$students = $studentGateway->queryBehaviourBySchoolYearAndCreator($criteria, $session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID')); - - // echo '
';
-            // print_r($students);
-            // echo '
'; - // die(); + $students = $behaviourGateway->queryAllBehaviourStudentsBySchoolYear($criteria, $session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID')); $table = DataTable::createPaginated('behaviour', $criteria); $table->setTitle( __('My Students')); diff --git a/modules/Behaviour/behaviour_view_details.php b/modules/Behaviour/behaviour_view_details.php index f86c2106ec..362ee5571e 100644 --- a/modules/Behaviour/behaviour_view_details.php +++ b/modules/Behaviour/behaviour_view_details.php @@ -96,7 +96,7 @@ if ($highestAction == 'View Behaviour Records_my') { echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID')); } else { - echo getBehaviourRecord($container, $gibbonPersonID, null); + echo getBehaviourRecord($container, $gibbonPersonID); } } } diff --git a/modules/Behaviour/moduleFunctions.php b/modules/Behaviour/moduleFunctions.php index 8cea86c067..2fa9fdfe09 100644 --- a/modules/Behaviour/moduleFunctions.php +++ b/modules/Behaviour/moduleFunctions.php @@ -26,7 +26,7 @@ use Gibbon\Domain\Behaviour\BehaviourGateway; use Gibbon\Domain\Students\StudentGateway; -function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gibbonPersonIDCreator) +function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gibbonPersonIDCreator = null) { global $session; @@ -61,9 +61,7 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gib if (empty($gibbonPersonIDCreator)) { $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID); } else { - $result = $behaviourGateway->getBehaviourRecordsByPersonAndCreator($schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator); - - $behaviourRecords = $result->fetchAll(); + $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator); } $table = DataTable::createPaginated('behaviour'.$schoolYear['gibbonSchoolYearID'], $criteria); diff --git a/modules/Students/student_view_details.php b/modules/Students/student_view_details.php index 7d5f40ca1b..332ad0a460 100644 --- a/modules/Students/student_view_details.php +++ b/modules/Students/student_view_details.php @@ -2426,9 +2426,15 @@ $page->addError(__('Your request failed because you do not have access to this action.')); } else { include './modules/Behaviour/moduleFunctions.php'; + + $highestActionBehaviour = getHighestGroupedAction($guid, '/modules/Behaviour/behaviour_view.php', $connection2); //Print assessments - echo getBehaviourRecord($container, $gibbonPersonID, null); + if ($highestActionBehaviour == 'View Behaviour Records_my') { + echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID')); + } else { + echo getBehaviourRecord($container, $gibbonPersonID); + } } } diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php index 13ef22832e..864eb069c4 100644 --- a/src/Domain/Behaviour/BehaviourGateway.php +++ b/src/Domain/Behaviour/BehaviourGateway.php @@ -45,7 +45,7 @@ class BehaviourGateway extends QueryableGateway implements ScrubbableGateway private static $tableName = 'gibbonBehaviour'; private static $primaryKey = 'gibbonBehaviourID'; - private static $searchableColumns = ['gibbonBehaviour.gibbonBehaviourID','gibbonBehaviour.type', 'gibbonBehaviour.descriptor', 'gibbonBehaviour.level', 'gibbonBehaviour.date', 'gibbonBehaviour.timestamp', 'gibbonBehaviour.comment']; + private static $searchableColumns = ['gibbonBehaviour.gibbonBehaviourID','gibbonBehaviour.type', 'gibbonBehaviour.descriptor', 'gibbonBehaviour.level', 'gibbonBehaviour.date', 'gibbonBehaviour.timestamp', 'gibbonBehaviour.comment', 'gibbonPerson.preferredName']; private static $scrubbableKey = 'gibbonPersonID'; private static $scrubbableColumns = ['descriptor' => null, 'level' => null, 'comment' => '']; @@ -212,7 +212,7 @@ public function queryBehaviourLettersBySchoolYear(QueryCriteria $criteria, $gibb return $this->runQuery($query, $criteria); } - public function queryBehaviourRecordsByPerson(QueryCriteria $criteria, $gibbonSchoolYearID, $gibbonPersonID) + public function queryBehaviourRecordsByPerson(QueryCriteria $criteria, $gibbonSchoolYearID, $gibbonPersonID, $gibbonPersonIDCreator = null) { $query = $this ->newQuery() @@ -229,7 +229,49 @@ public function queryBehaviourRecordsByPerson(QueryCriteria $criteria, $gibbonSc ->where('gibbonBehaviour.gibbonSchoolYearID = :gibbonSchoolYearID') ->bindValue('gibbonSchoolYearID', $gibbonSchoolYearID); - return $this->runQuery($query, $criteria); + if (!empty($gibbonPersonIDCreator)) { + $query + ->where('gibbonBehaviour.gibbonPersonIDCreator = :gibbonPersonIDCreator') + ->bindValue('gibbonPersonIDCreator', $gibbonPersonIDCreator); + } + + return $this->runQuery($query, $criteria); + } + + public function queryAllBehaviourStudentsBySchoolYear(QueryCriteria $criteria, $gibbonSchoolYearID, $gibbonPersonIDCreator = null) + { + $query = $this + ->newQuery() + ->distinct() + ->from('gibbonPerson') + ->cols([ + 'gibbonPerson.gibbonPersonID', 'gibbonStudentEnrolmentID', 'gibbonPerson.title', 'gibbonPerson.preferredName', 'gibbonPerson.surname', 'gibbonPerson.image_240', 'gibbonYearGroup.gibbonYearGroupID', 'gibbonYearGroup.nameShort AS yearGroup', 'gibbonFormGroup.gibbonFormGroupID', 'gibbonFormGroup.nameShort AS formGroup', 'gibbonStudentEnrolment.rollOrder', 'gibbonPerson.dateStart', 'gibbonPerson.dateEnd', 'gibbonPerson.status', "'Student' as roleCategory" + ]) + ->leftJoin('gibbonStudentEnrolment', 'gibbonPerson.gibbonPersonID=gibbonStudentEnrolment.gibbonPersonID AND gibbonStudentEnrolment.gibbonSchoolYearID = :gibbonSchoolYearID') + ->leftJoin('gibbonYearGroup', 'gibbonStudentEnrolment.gibbonYearGroupID=gibbonYearGroup.gibbonYearGroupID') + ->leftJoin('gibbonFormGroup', 'gibbonStudentEnrolment.gibbonFormGroupID=gibbonFormGroup.gibbonFormGroupID') + ->bindValue('gibbonSchoolYearID', $gibbonSchoolYearID); + + if ($criteria->hasFilter('all')) { + $query->innerJoin('gibbonRole', 'FIND_IN_SET(gibbonRole.gibbonRoleID, gibbonPerson.gibbonRoleIDAll)') + ->where("gibbonRole.category='Student'"); + } else { + $query->where("gibbonStudentEnrolment.gibbonStudentEnrolmentID IS NOT NULL") + ->where("gibbonPerson.status = 'Full'") + ->where('(gibbonPerson.dateStart IS NULL OR gibbonPerson.dateStart <= :today)') + ->where('(gibbonPerson.dateEnd IS NULL OR gibbonPerson.dateEnd >= :today)') + ->bindValue('today', date('Y-m-d')); + } + + if (!empty($gibbonPersonIDCreator)) { + $query + ->innerJoin('gibbonBehaviour', 'gibbonBehaviour.gibbonPersonID = gibbonPerson.gibbonPersonID') + ->where('gibbonBehaviour.gibbonPersonIDCreator = :gibbonPersonIDCreator ') + ->bindValue('gibbonPersonIDCreator', $gibbonPersonIDCreator) + ->groupBy(['gibbonPerson.gibbonPersonID']); + } + + return $this->runQuery($query, $criteria); } public function getBehaviourRecordsByPersonAndCreator($gibbonSchoolYearID, $gibbonPersonID, $gibbonPersonIDCreator) { @@ -277,13 +319,4 @@ public function updateMultiIncidentIDByBehaviourID($gibbonBehaviourID, $gibbonMu return $this->db()->update($sql, $data); } - - public function selectStudentsFromBehaviourByCreator($gibbonSchoolYearID, $gibbonPersonID) - { - $data = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonPersonID' => $gibbonPersonID, 'today' => date('Y-m-d')]; - $sql = "SELECT gibbonPerson.gibbonPersonID, title, surname, preferredName, image_240, gibbonYearGroup.nameShort AS yearGroup, gibbonFormGroup.nameShort AS formGroup, 'Student' as roleCategory - FROM gibbonBehaviour JOIN gibbonPerson ON (gibbonBehaviour.gibbonPersonID=gibbonPerson.gibbonPersonID) JOIN gibbonStudentEnrolment ON (gibbonPerson.gibbonPersonID=gibbonStudentEnrolment.gibbonPersonID) JOIN gibbonYearGroup ON (gibbonStudentEnrolment.gibbonYearGroupID=gibbonYearGroup.gibbonYearGroupID) JOIN gibbonFormGroup ON (gibbonStudentEnrolment.gibbonFormGroupID=gibbonFormGroup.gibbonFormGroupID) WHERE gibbonBehaviour.gibbonPersonIDCreator=:gibbonPersonID AND gibbonStudentEnrolment.gibbonSchoolYearID=:gibbonSchoolYearID AND gibbonPerson.status='Full' AND (dateStart IS NULL OR dateStart<=:today) AND (dateEnd IS NULL OR dateEnd>=:today) GROUP BY gibbonPerson.gibbonPersonID, yearGroup, formGroup ORDER BY surname, preferredName"; - - return $this->db()->select($sql, $data); - } } From 9873ab91ab90068df23fab6999582a7d8684853b Mon Sep 17 00:00:00 2001 From: ali-ichk <159099563+ali-ichk@users.noreply.github.com> Date: Mon, 29 Apr 2024 12:11:14 +0800 Subject: [PATCH 4/9] Update CHANGELOG.txt --- CHANGELOG.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 49c49c58c9..ac53d1ebef 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -47,7 +47,7 @@ v27.0.00 Behaviour: updated the view so that followups are displayed as conversational logs and stored in a separate table Behaviour: added the ability to able to link a behaviour record to some other existing behaviour record Behaviour: added positive behaviour records to the Daily Behaviour Summary CLI script - Behaviour-Add-a-new-permission-so-that-teachers-can-only-view-behaviours-created-by-them + Behaviour: added a my_permission so that teachers are restricted to only view behaviours created by them Finance: added a fees list and notes column to the Export option in Manage Invoices Library: added ui changes to Library module browsing through library shelves and improved search page Library: added automatic shelf generation by search term, automatic shelf updates, and auto-shuffling From a8e0e2af89107cc2c5c87029b0729b325264656f Mon Sep 17 00:00:00 2001 From: ali-ichk <159099563+ali-ichk@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:03:35 +0800 Subject: [PATCH 5/9] Update src/Domain/Behaviour/BehaviourGateway.php Co-authored-by: Sandra Kuipers --- src/Domain/Behaviour/BehaviourGateway.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php index 864eb069c4..074ab00156 100644 --- a/src/Domain/Behaviour/BehaviourGateway.php +++ b/src/Domain/Behaviour/BehaviourGateway.php @@ -274,13 +274,6 @@ public function queryAllBehaviourStudentsBySchoolYear(QueryCriteria $criteria, $ return $this->runQuery($query, $criteria); } - public function getBehaviourRecordsByPersonAndCreator($gibbonSchoolYearID, $gibbonPersonID, $gibbonPersonIDCreator) { - $data = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonPersonID' => $gibbonPersonID, 'gibbonPersonIDCreator' => $gibbonPersonIDCreator]; - $sql = 'SELECT gibbonBehaviour.*, creator.title as titleCreator, creator.surname AS surnameCreator, creator.preferredName AS preferredNameCreator FROM gibbonBehaviour JOIN gibbonPerson AS creator ON (gibbonBehaviour.gibbonPersonIDCreator=creator.gibbonPersonID) WHERE gibbonSchoolYearID=:gibbonSchoolYearID AND gibbonBehaviour.gibbonPersonID=:gibbonPersonID AND gibbonBehaviour.gibbonPersonIDCreator=:gibbonPersonIDCreator ORDER BY date DESC'; - - return $this->db()->select($sql, $data); - } - public function getBehaviourDetails($gibbonSchoolYearID, $gibbonBehaviourID) { $data = ['gibbonSchoolYearID' => $gibbonSchoolYearID, 'gibbonBehaviourID' => $gibbonBehaviourID]; From ac9ac82b9316e325c13e69985f3d3c9d5de93887 Mon Sep 17 00:00:00 2001 From: ali-ichk <159099563+ali-ichk@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:04:39 +0800 Subject: [PATCH 6/9] Update modules/Behaviour/moduleFunctions.php Co-authored-by: Sandra Kuipers --- modules/Behaviour/moduleFunctions.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/Behaviour/moduleFunctions.php b/modules/Behaviour/moduleFunctions.php index 2fa9fdfe09..c0e9fc1772 100644 --- a/modules/Behaviour/moduleFunctions.php +++ b/modules/Behaviour/moduleFunctions.php @@ -58,11 +58,7 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID, $gib ->sortBy('timestamp', 'DESC') ->fromPOST($schoolYear['gibbonSchoolYearID']); - if (empty($gibbonPersonIDCreator)) { - $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID); - } else { - $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator); - } + $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator); $table = DataTable::createPaginated('behaviour'.$schoolYear['gibbonSchoolYearID'], $criteria); $table->setTitle($schoolYear['name']); From f7ca320a663ba99317b9aca12b886ad563e01449 Mon Sep 17 00:00:00 2001 From: ali-ichk <159099563+ali-ichk@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:12:01 +0800 Subject: [PATCH 7/9] Update student_view_details.php --- modules/Students/student_view_details.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/Students/student_view_details.php b/modules/Students/student_view_details.php index 332ad0a460..085d65f7c8 100644 --- a/modules/Students/student_view_details.php +++ b/modules/Students/student_view_details.php @@ -2428,12 +2428,12 @@ include './modules/Behaviour/moduleFunctions.php'; $highestActionBehaviour = getHighestGroupedAction($guid, '/modules/Behaviour/behaviour_view.php', $connection2); - + //Print assessments - if ($highestActionBehaviour == 'View Behaviour Records_my') { - echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID')); - } else { + if ($highestActionBehaviour == 'View Behaviour Records_all') { echo getBehaviourRecord($container, $gibbonPersonID); + } else { + echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID')); } } } From c6c1a58fa8c9248c003e649924e1fe244cf56f69 Mon Sep 17 00:00:00 2001 From: ali-ichk <159099563+ali-ichk@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:13:27 +0800 Subject: [PATCH 8/9] Update src/Domain/Behaviour/BehaviourGateway.php Co-authored-by: Sandra Kuipers --- src/Domain/Behaviour/BehaviourGateway.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php index 074ab00156..caa2e78749 100644 --- a/src/Domain/Behaviour/BehaviourGateway.php +++ b/src/Domain/Behaviour/BehaviourGateway.php @@ -23,7 +23,6 @@ use Gibbon\Domain\QueryCriteria; use Gibbon\Domain\QueryableGateway; -use Gibbon\Domain\Traits\SharedUserLogic; use Gibbon\Domain\ScrubbableGateway; use Gibbon\Domain\Traits\Scrubbable; use Gibbon\Domain\Traits\TableAware; From e10c507fbd8ec08263139fe1a712d4741184a387 Mon Sep 17 00:00:00 2001 From: ali-ichk <159099563+ali-ichk@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:13:34 +0800 Subject: [PATCH 9/9] Update src/Domain/Behaviour/BehaviourGateway.php Co-authored-by: Sandra Kuipers --- src/Domain/Behaviour/BehaviourGateway.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php index caa2e78749..c3a611f774 100644 --- a/src/Domain/Behaviour/BehaviourGateway.php +++ b/src/Domain/Behaviour/BehaviourGateway.php @@ -39,7 +39,6 @@ class BehaviourGateway extends QueryableGateway implements ScrubbableGateway use TableAware; use Scrubbable; use ScrubByPerson; - use SharedUserLogic; private static $tableName = 'gibbonBehaviour'; private static $primaryKey = 'gibbonBehaviourID';