|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Emergence\Mueller; |
| 4 | + |
| 5 | +use DB; |
| 6 | +use Emergence\People\IUser; |
| 7 | +use Emergence\Slack\API as SlackAPI; |
| 8 | + |
| 9 | +Investigator::$tests['email-invalid'] = false; |
| 10 | + |
| 11 | +Investigator::$tests['has-about'] = [ |
| 12 | + 'points' => -10, |
| 13 | + 'function' => [Investigator::class, 'testHasUserField'], |
| 14 | + 'userField' => 'About' |
| 15 | +]; |
| 16 | + |
| 17 | +Investigator::$tests['has-comment'] = [ |
| 18 | + 'points' => -10, |
| 19 | + 'function' => function (IUser $User, array &$userCache) { |
| 20 | + return count(Investigator::getUserComments($User, $userCache)) > 0; |
| 21 | + } |
| 22 | +]; |
| 23 | + |
| 24 | +Investigator::$tests['has-project'] = [ |
| 25 | + 'points' => 1000, |
| 26 | + 'function' => function (IUser $User) { |
| 27 | + static $projectMemberIds; |
| 28 | + |
| 29 | + if ($projectMemberIds === null) { |
| 30 | + $projectMemberIds = array_map( |
| 31 | + 'intval', |
| 32 | + DB::allValues( |
| 33 | + 'MemberID', |
| 34 | + 'SELECT DISTINCT MemberID FROM `project_members`' |
| 35 | + ) |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + return in_array(strtolower($User->ID), $projectMemberIds); |
| 40 | + }, |
| 41 | +]; |
| 42 | + |
| 43 | +if (SlackAPI::isAvailable()) { |
| 44 | + Investigator::$tests['has-slack-account'] = [ |
| 45 | + 'points' => 1000, |
| 46 | + 'function' => function (IUser $User) { |
| 47 | + static $slackUsernames; |
| 48 | + |
| 49 | + if ($slackUsernames === null) { |
| 50 | + $slackMembersResponse = SlackAPI::request('users.list'); |
| 51 | + $slackUsernames = []; |
| 52 | + |
| 53 | + foreach ($slackMembersResponse['members'] as $member) { |
| 54 | + $slackUsernames[] = strtolower($member['name']); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return in_array(strtolower($User->Username), $slackUsernames); |
| 59 | + } |
| 60 | + ]; |
| 61 | +} |
0 commit comments