Skip to content

Commit

Permalink
Merge pull request #348 from SlateFoundation/develop
Browse files Browse the repository at this point in the history
Release: v2.19.0
  • Loading branch information
themightychris authored May 10, 2022
2 parents f6e5ac4 + 14594df commit 0748b49
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions fixtures/course_section_participants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ INSERT INTO `course_section_participants` VALUES (21,'Slate\\Courses\\SectionPar
INSERT INTO `course_section_participants` VALUES (22,'Slate\\Courses\\SectionParticipant','2021-05-29 13:05:48',5,7,12,'Student',NULL,NULL,NULL);
INSERT INTO `course_section_participants` VALUES (23,'Slate\\Courses\\SectionParticipant','2021-05-29 13:05:58',5,7,8,'Student',NULL,NULL,NULL);
INSERT INTO `course_section_participants` VALUES (24,'Slate\\Courses\\SectionParticipant','2021-05-29 13:06:05',5,7,11,'Student',NULL,NULL,NULL);
INSERT INTO `course_section_participants` VALUES (25,'Slate\\Courses\\SectionParticipant','2022-04-25 15:42:50',3,6,34,'Student',NULL,NULL,NULL);
1 change: 1 addition & 0 deletions fixtures/group_members.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ INSERT INTO `group_members` VALUES (25,'Emergence\\People\\Groups\\GroupMember',
INSERT INTO `group_members` VALUES (26,'Emergence\\People\\Groups\\GroupMember','2021-05-28 13:31:48',2,15,26,'Member',NULL,NULL,'2021-05-28 13:31:48',NULL);
INSERT INTO `group_members` VALUES (29,'Emergence\\People\\Groups\\GroupMember','2021-05-31 01:40:11',2,7,27,'Member',NULL,NULL,'2021-05-31 01:40:11',NULL);
INSERT INTO `group_members` VALUES (30,'Emergence\\People\\Groups\\GroupMember','2021-05-31 11:30:33',2,7,28,'Member',NULL,NULL,'2021-05-31 11:30:33',NULL);
INSERT INTO `group_members` VALUES (31,'Emergence\\People\\Groups\\GroupMember','2022-04-25 15:39:59',3,15,34,'Member',NULL,NULL,'2022-04-25 15:39:59',NULL);
1 change: 1 addition & 0 deletions fixtures/people.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ INSERT INTO `people` VALUES (30,'Emergence\\People\\Person','2021-10-11 17:27:15
INSERT INTO `people` VALUES (31,'Emergence\\People\\Person','2021-10-11 17:27:24',3,NULL,NULL,'Nonguardian','Father',NULL,NULL,'Male',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'User',NULL,NULL,NULL,NULL,NULL);
INSERT INTO `people` VALUES (32,'Emergence\\People\\Person','2021-10-11 17:35:41',3,NULL,NULL,'Basketball','Coach',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'User',NULL,NULL,NULL,NULL,NULL);
INSERT INTO `people` VALUES (33,'Emergence\\People\\Person','2021-10-11 17:53:25',3,NULL,NULL,'Math','Tutor',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'User',NULL,NULL,NULL,NULL,NULL);
INSERT INTO `people` VALUES (34,'Slate\\People\\Student','2022-04-25 15:39:59',NULL,NULL,NULL,'Deactivated','Student',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'dstudent',NULL,'Disabled',NULL,'10023489',5,2024,NULL);

CREATE TABLE `history_people` (
`RevisionID` int(10) unsigned NOT NULL AUTO_INCREMENT,
Expand Down
34 changes: 34 additions & 0 deletions php-classes/Emergence/People/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use VersionedRecord;
use PhotoMedia;
use Exception;
use Cache;

use Emergence\Comments\Comment;
use Emergence\CRM\Message;
Expand All @@ -29,6 +30,9 @@ class Person extends VersionedRecord implements IPerson
public static $pluralNoun = 'people';
public static $collectionRoute = '/people';

// cache keys
public static $deactivatedPeopleCacheKey = 'deactivated-people-ids';

public static $fields = [
'FirstName' => [
'includeInSummary' => true
Expand Down Expand Up @@ -435,6 +439,10 @@ public function save($deep = true)
$this->PrimaryPostal->PersonID = $this->ID;
$this->PrimaryPostal->save(false);
}

if ($this->isFieldDirty('AccountLevel')) {
Cache::delete(self::$deactivatedPeopleCacheKey);
}
}

public static function getGroupConditions($handle, $matchedCondition)
Expand Down Expand Up @@ -498,4 +506,30 @@ public function getGroupIDs()
return $Group->ID;
}, $this->Groups);
}

public static function getDeactivatedIds($forceRefresh = false)
{

if (!$forceRefresh && false !== ($deactivatedIds = Cache::fetch(self::$deactivatedPeopleCacheKey))) {
return $deactivatedIds;
}

try {
$deactivatedIds = DB::allValues(
'ID',
'
SELECT ID
FROM `%s`
WHERE AccountLevel = "Disabled"
',
[ self::$tableName ]
);
} catch (Exception $e) {
$deactivatedIds = [];
}

Cache::store(self::$deactivatedPeopleCacheKey, $deactivatedIds);

return $deactivatedIds;
}
}
10 changes: 10 additions & 0 deletions php-classes/Slate/Courses/SectionParticipantsRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Slate\Courses;

use Emergence\People\Person;

class SectionParticipantsRequestHandler extends \Slate\RecordsRequestHandler
{
Expand Down Expand Up @@ -51,6 +52,15 @@ protected static function buildBrowseConditions(array $conditions = [], array &$
];
}

// apply disabled people filter
if (!static::getRequestedIncludeDeactivated()) {
$disabledPersonIds = Person::getDeactivatedIds();

if (!empty($disabledPersonIds)) {
$conditions[] = 'PersonID NOT IN ('.implode(",",$disabledPersonIds).')';
}
}

return $conditions;
}
}
20 changes: 20 additions & 0 deletions php-classes/Slate/RecordsRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,24 @@ public static function getRequestedDepartment($fieldName = 'department')

return $Schedule;
}

/**
* Examine the current request, determine if the inclusion of
* deactivate records has been explicitly requested
*/
public static function getRequestedIncludeDeactivated($fieldName = 'include_deactivated')
{
// return null if the `include_deactivated` flag was not included with the requestor has no value
if (empty($_REQUEST[$fieldName])) {
return null;
}

// if the flag was explicity set to false, set it to boolean false
// so false will be returned. All other values will return true.
if ($_REQUEST[$fieldName] === 'false') {
$_REQUEST[$fieldName] = false;
}

return !!$_REQUEST[$fieldName];
}
}

0 comments on commit 0748b49

Please sign in to comment.