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/CHANGELOG.txt b/CHANGELOG.txt
index 45ac9bcdf1..ac53d1ebef 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -47,6 +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: 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
diff --git a/modules/Behaviour/behaviour_manage.php b/modules/Behaviour/behaviour_manage.php
index 10364b1b55..fd21cf66cd 100644
--- a/modules/Behaviour/behaviour_manage.php
+++ b/modules/Behaviour/behaviour_manage.php
@@ -95,8 +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 a7aabad088..3add9e5a97 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;
@@ -38,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();
@@ -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'));
@@ -75,6 +77,19 @@
$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 = $behaviourGateway->queryAllBehaviourStudentsBySchoolYear($criteria, $session->get('gibbonSchoolYearID'), $session->get('gibbonPersonID'));
+
+ $table = DataTable::createPaginated('behaviour', $criteria);
+ $table->setTitle( __('My Students'));
+
} else {
return;
}
diff --git a/modules/Behaviour/behaviour_view_details.php b/modules/Behaviour/behaviour_view_details.php
index 528dd68726..362ee5571e 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);
+ }
}
}
}
diff --git a/modules/Behaviour/moduleFunctions.php b/modules/Behaviour/moduleFunctions.php
index 042a850bb1..c0e9fc1772 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 = null)
{
global $session;
@@ -58,8 +58,8 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID)
->sortBy('timestamp', 'DESC')
->fromPOST($schoolYear['gibbonSchoolYearID']);
- $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID);
-
+ $behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator);
+
$table = DataTable::createPaginated('behaviour'.$schoolYear['gibbonSchoolYearID'], $criteria);
$table->setTitle($schoolYear['name']);
@@ -86,37 +86,37 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID)
$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/modules/Students/student_view_details.php b/modules/Students/student_view_details.php
index ee759942b1..085d65f7c8 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);
+ if ($highestActionBehaviour == 'View Behaviour Records_all') {
+ echo getBehaviourRecord($container, $gibbonPersonID);
+ } else {
+ echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID'));
+ }
}
}
diff --git a/src/Domain/Behaviour/BehaviourGateway.php b/src/Domain/Behaviour/BehaviourGateway.php
index 04672552b4..c3a611f774 100644
--- a/src/Domain/Behaviour/BehaviourGateway.php
+++ b/src/Domain/Behaviour/BehaviourGateway.php
@@ -43,7 +43,7 @@ class BehaviourGateway extends QueryableGateway implements ScrubbableGateway
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', 'gibbonPerson.preferredName'];
private static $scrubbableKey = 'gibbonPersonID';
private static $scrubbableColumns = ['descriptor' => null, 'level' => null, 'comment' => ''];
@@ -210,7 +210,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()
@@ -227,7 +227,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 getBehaviourDetails($gibbonSchoolYearID, $gibbonBehaviourID)