@@ -1559,22 +1559,32 @@ public static function hasTopcoderAdminRole($user) {
1559
1559
1560
1560
1561
1561
/**
1562
- * Get a photo url from Topcoder Member Profile
1563
- * @param $name vanilla user name
1564
- * @return null|string photo url
1562
+ * Check if the list of Topcoder roles includes Topcoder admin roles
1563
+ * @param false $topcoderRoles
1564
+ * @return bool true, if the list of Topcoder roles includes at least one Topcoder admin role
1565
1565
*/
1566
- //TODO: remove , not found usages
1567
- /*
1568
- public static function getTopcoderPhotoUrl($name) {
1569
- $topcoderProfile = self::getTopcoderProfile($name);
1570
- if($topcoderProfile !== null) {
1571
- return $topcoderProfile->photoURL;
1566
+ private static function isTopcoderAdmin ($ topcoderRoles = false ) {
1567
+ if ($ topcoderRoles ) {
1568
+ $ roleNames = array_column ($ topcoderRoles , 'roleName ' );
1569
+ $ lowerRoleNames = array_map ('strtolower ' , $ roleNames );
1570
+ return count (array_intersect ($ lowerRoleNames , ["connect manager " , "admin " , "administrator " ])) > 0 ;
1572
1571
}
1573
- return null;
1572
+
1573
+ return false ;
1574
+ }
1575
+
1576
+ /**
1577
+ * Get Topcoder Role names
1578
+ * @param false $topcoderRoles
1579
+ * @return array|false|null
1580
+ */
1581
+ private static function getTopcoderRoleNames ($ topcoderRoles = false ) {
1582
+ return $ topcoderRoles ? array_column ($ topcoderRoles , 'roleName ' ) : [];
1574
1583
}
1575
- */
1584
+
1576
1585
/**
1577
1586
* Load Topcoder User Details from Topcoder API.
1587
+ * User is registered in Vanilla
1578
1588
* Data is cached if a cache is enabled
1579
1589
* @param $vanillaUser
1580
1590
* @return array|void
@@ -1593,13 +1603,8 @@ private static function loadTopcoderUserDetails($vanillaUser) {
1593
1603
$ cachedUser ['TopcoderUserID ' ] = $ topcoderProfile ->userId ;
1594
1604
$ cachedUser ['PhotoUrl ' ] = $ topcoderProfile ->photoURL ;
1595
1605
$ topcoderRoles = self ::loadTopcoderRoles ($ topcoderProfile ->userId );
1596
- if ($ topcoderRoles ) {
1597
- $ roleNames = array_column ($ topcoderRoles , 'roleName ' );
1598
- $ lowerRoleNames = array_map ('strtolower ' , $ roleNames );
1599
- $ cachedUser ['Roles ' ] = $ roleNames ;
1600
- $ cachedUser ['IsAdmin ' ] = in_array ("admin " , $ lowerRoleNames ) || in_array ("administrator " , $ lowerRoleNames );
1601
- }
1602
-
1606
+ $ cachedUser ['Roles ' ] = self ::getTopcoderRoleNames ($ topcoderRoles );
1607
+ $ cachedUser ['IsAdmin ' ] = self ::isTopcoderAdmin ($ topcoderRoles );
1603
1608
$ topcoderRating = self ::loadTopcoderRating ($ username ); //loaded by handle
1604
1609
if ($ topcoderRating ) {
1605
1610
$ cachedUser ['Rating ' ] = $ topcoderRating ;
@@ -1815,7 +1820,8 @@ private static function getTopcoderUserFromTopcoderCache($topcoderHandle) {
1815
1820
}
1816
1821
1817
1822
/**
1818
- * Load Topcoder User Details from Topcoder API.
1823
+ * Load Topcoder User Details by Topcoder handle from Topcoder API and add data in Topcoder User cache.
1824
+ * Topcoder handles are used in mentions but Topcoder Users may not register in Vanilla.
1819
1825
* Data is cached if a cache is enabled
1820
1826
* @param $topcoderHandle
1821
1827
* @return array|void
@@ -1831,13 +1837,8 @@ private static function loadTopcoderUserDetailsByHandle($topcoderHandle) {
1831
1837
$ cachedUser ['TopcoderUserID ' ] = $ topcoderProfile ->userId ;
1832
1838
$ cachedUser ['PhotoUrl ' ] = $ topcoderProfile ->photoURL ;
1833
1839
$ topcoderRoles = self ::loadTopcoderRoles ($ topcoderProfile ->userId );
1834
- if ($ topcoderRoles ) {
1835
- $ roleNames = array_column ($ topcoderRoles , 'roleName ' );
1836
- $ lowerRoleNames = array_map ('strtolower ' , $ roleNames );
1837
- $ cachedUser ['Roles ' ] = $ roleNames ;
1838
- $ cachedUser ['IsAdmin ' ] = count (array_intersect ($ lowerRoleNames , ["connect manager " , "admin " , "administrator " ])) > 0 ;
1839
- }
1840
-
1840
+ $ cachedUser ['Roles ' ] = self ::getTopcoderRoleNames ($ topcoderRoles );
1841
+ $ cachedUser ['IsAdmin ' ] = self ::isTopcoderAdmin ($ topcoderRoles );
1841
1842
$ topcoderRating = self ::loadTopcoderRating ($ topcoderHandle ); //loaded by handle
1842
1843
if ($ topcoderRating ) {
1843
1844
$ cachedUser ['Rating ' ] = $ topcoderRating ;
0 commit comments