|
| 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-url'] = [ |
| 12 | + 'points' => -100, |
| 13 | + 'function' => function (IUser $User, array &$userCache) { |
| 14 | + return $User->About && (stripos($User->About, 'http://') !== false || stripos($User->About, 'https://') !== false); |
| 15 | + } |
| 16 | +]; |
| 17 | + |
| 18 | +Investigator::$tests['has-comment-url'] = [ |
| 19 | + 'points' => -100, |
| 20 | + 'function' => function (IUser $User, array &$userCache) { |
| 21 | + |
| 22 | + foreach (Investigator::getUserComments($User, $userCache) as $Comment) { |
| 23 | + if ( |
| 24 | + stripos($Comment['Message'], 'http://') !== false |
| 25 | + || stripos($Comment['Message'], 'https://') !== false |
| 26 | + ) { |
| 27 | + return true; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + return false; |
| 32 | + } |
| 33 | +]; |
| 34 | + |
| 35 | +Investigator::$tests['has-project'] = [ |
| 36 | + 'points' => 1000, |
| 37 | + 'function' => function (IUser $User) { |
| 38 | + static $projectMemberIds; |
| 39 | + |
| 40 | + if ($projectMemberIds === null) { |
| 41 | + $projectMemberIds = array_map( |
| 42 | + 'intval', |
| 43 | + DB::allValues( |
| 44 | + 'MemberID', |
| 45 | + 'SELECT DISTINCT MemberID FROM `project_members`' |
| 46 | + ) |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + return in_array(strtolower($User->ID), $projectMemberIds); |
| 51 | + }, |
| 52 | +]; |
| 53 | + |
| 54 | +if (SlackAPI::isAvailable()) { |
| 55 | + Investigator::$tests['has-slack-account'] = [ |
| 56 | + 'points' => 1000, |
| 57 | + 'function' => function (IUser $User) { |
| 58 | + static $slackUsernames; |
| 59 | + |
| 60 | + if ($slackUsernames === null) { |
| 61 | + $slackMembersResponse = SlackAPI::request('users.list'); |
| 62 | + $slackUsernames = []; |
| 63 | + |
| 64 | + foreach ($slackMembersResponse['members'] as $member) { |
| 65 | + $slackUsernames[] = strtolower($member['name']); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + return in_array(strtolower($User->Username), $slackUsernames); |
| 70 | + } |
| 71 | + ]; |
| 72 | +} |
0 commit comments