public function actionTeam()
 {
     $members = Yii::$app->params['members'];
     $activeMembers = [];
     $pastMembers = [];
     foreach ($members as $member) {
         if ($member['active']) {
             $activeMembers[] = $member;
         } else {
             $pastMembers[] = $member;
         }
     }
     $activeMembers = RowHelper::split($activeMembers, 3);
     $pastMembers = RowHelper::split($pastMembers, 3);
     $contributorLimit = 1000;
     // getting contributors from github
     try {
         $cacheKey = __CLASS__ . ":team:contributors:{$contributorLimit}";
         if (($contributors = Yii::$app->cache->get($cacheKey)) === false) {
             $client = new \Github\Client();
             $api = $client->api('repo');
             $paginator = new \Github\ResultPager($client);
             $parameters = ['yiisoft', 'yii2'];
             $contributors = $paginator->fetch($api, 'contributors', $parameters);
             while ($paginator->hasNext() && count($contributors) < $contributorLimit) {
                 $contributors = array_merge($contributors, $paginator->fetchNext());
             }
             // remove team members
             $teamGithubs = array_filter(array_map(function ($member) {
                 return isset($member['github']) ? $member['github'] : false;
             }, $members));
             foreach ($contributors as $key => $contributor) {
                 if (in_array($contributor['login'], $teamGithubs)) {
                     unset($contributors[$key]);
                 }
             }
             $contributors = array_slice($contributors, 0, $contributorLimit);
             Yii::$app->cache->set($cacheKey, $contributors, 3600 * 12);
             // cache for 12hours
         }
     } catch (\Exception $e) {
         $contributors = false;
     }
     return $this->render('team', ['activeMembers' => $activeMembers, 'pastMembers' => $pastMembers, 'contributors' => $contributors]);
 }
Пример #2
0
 public function actionTeam()
 {
     $members = Yii::$app->params['members'];
     $activeMembers = [];
     $pastMembers = [];
     foreach ($members as $member) {
         if ($member['active']) {
             $activeMembers[] = $member;
         } else {
             $pastMembers[] = $member;
         }
     }
     $activeMembers = RowHelper::split($activeMembers, 6);
     $pastMembers = RowHelper::split($pastMembers, 6);
     $contributors = false;
     try {
         $data_dir = Yii::getAlias('@app/data');
         $contributors = json_decode(file_get_contents($data_dir . '/contributors.json'), true);
     } catch (\Exception $e) {
         $contributors = false;
     }
     return $this->render('team', ['activeMembers' => $activeMembers, 'pastMembers' => $pastMembers, 'contributors' => $contributors]);
 }