Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour: add a new permission so that teachers can only view behaviours created by them #1825

1 change: 1 addition & 0 deletions CHANGEDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
";
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/Behaviour/behaviour_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
21 changes: 18 additions & 3 deletions modules/Behaviour/behaviour_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Domain\Behaviour\BehaviourGateway;
use Gibbon\Forms\Form;
use Gibbon\Forms\DatabaseFormFactory;
use Gibbon\Tables\DataTable;
Expand All @@ -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();
Expand All @@ -56,6 +56,7 @@
}

$studentGateway = $container->get(StudentGateway::class);
$behaviourGateway = $container->get(BehaviourGateway::class);

// DATA TABLE
if ($highestAction == 'View Behaviour Records_all') {
Expand 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'));
Expand All @@ -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;
}
Expand Down
24 changes: 21 additions & 3 deletions modules/Behaviour/behaviour_view_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand All @@ -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);
}
}
}
}
36 changes: 20 additions & 16 deletions modules/Behaviour/moduleFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -58,8 +58,12 @@ 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 {
$behaviourRecords = $behaviourGateway->queryBehaviourRecordsByPerson($criteria, $schoolYear['gibbonSchoolYearID'], $gibbonPersonID, $gibbonPersonIDCreator);
}
ali-ichk marked this conversation as resolved.
Show resolved Hide resolved

$table = DataTable::createPaginated('behaviour'.$schoolYear['gibbonSchoolYearID'], $criteria);
$table->setTitle($schoolYear['name']);

Expand All @@ -86,37 +90,37 @@ function getBehaviourRecord(ContainerInterface $container, $gibbonPersonID)
$table->addMetaData('hidePagination', true);

$table->addExpandableColumn('comment')
->format(function($beahviour) {
->format(function($behaviour) {
ali-ichk marked this conversation as resolved.
Show resolved Hide resolved
$output = '';
if (!empty($beahviour['comment'])) {
if (!empty($behaviour['comment'])) {
$output .= '<strong>'.__('Incident').'</strong><br/>';
$output .= nl2br($beahviour['comment']).'<br/>';
$output .= nl2br($behaviour['comment']).'<br/>';
}
if (!empty($beahviour['followup'])) {
if (!empty($behaviour['followup'])) {
$output .= '<br/><strong>'.__('Follow Up').'</strong><br/>';
$output .= nl2br($beahviour['followup']).'<br/>';
$output .= nl2br($behaviour['followup']).'<br/>';
}
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']).'<br/>'
. __('Incident:').' '.Format::date($beahviour['date']).'<br/>';
->format(function($behaviour) {
if (substr($behaviour['timestamp'], 0, 10) > $behaviour['date']) {
return __('Updated:').' '.Format::date($behaviour['timestamp']).'<br/>'
. __('Incident:').' '.Format::date($behaviour['date']).'<br/>';
} 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 "<img src='./themes/".$session->get('gibbonThemeName')."/img/iconCross.png'/> ";
} elseif ($beahviour['type'] == 'Positive') {
} elseif ($behaviour['type'] == 'Positive') {
return "<img src='./themes/".$session->get('gibbonThemeName')."/img/iconTick.png'/> ";
}
});
Expand Down
8 changes: 7 additions & 1 deletion modules/Students/student_view_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_my') {
ali-ichk marked this conversation as resolved.
Show resolved Hide resolved
echo getBehaviourRecord($container, $gibbonPersonID, $session->get('gibbonPersonID'));
} else {
echo getBehaviourRecord($container, $gibbonPersonID);
}
}
}

Expand Down
57 changes: 54 additions & 3 deletions src/Domain/Behaviour/BehaviourGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Gibbon\Domain\QueryCriteria;
use Gibbon\Domain\QueryableGateway;
use Gibbon\Domain\Traits\SharedUserLogic;
ali-ichk marked this conversation as resolved.
Show resolved Hide resolved
use Gibbon\Domain\ScrubbableGateway;
use Gibbon\Domain\Traits\Scrubbable;
use Gibbon\Domain\Traits\TableAware;
Expand All @@ -39,11 +40,12 @@ class BehaviourGateway extends QueryableGateway implements ScrubbableGateway
use TableAware;
use Scrubbable;
use ScrubByPerson;
use SharedUserLogic;
ali-ichk marked this conversation as resolved.
Show resolved Hide resolved

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' => ''];
Expand Down Expand Up @@ -210,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()
Expand All @@ -227,7 +229,56 @@ 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) {
$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);
}

ali-ichk marked this conversation as resolved.
Show resolved Hide resolved
public function getBehaviourDetails($gibbonSchoolYearID, $gibbonBehaviourID)
Expand Down