コード例 #1
0
 public function updateMarked()
 {
     $controller = new AppController();
     $fitbit = $controller->loadComponent('Fitbit');
     $lr_table = TableRegistry::get('LinkedRecords');
     $linked_records = $lr_table->find()->contain('SocialAccounts')->where(['marked_for_update' => 1]);
     foreach ($linked_records as $linked_record) {
         $fitbit->_saveSteps($linked_record->social_account, 'steps', $linked_record->associated_date);
     }
 }
コード例 #2
0
ファイル: LoginListener.php プロジェクト: abf6ug/statbro
 public function afterCookieLogin($event, $entity, $options = [])
 {
     $controller = new AppController();
     $auth = $controller->loadComponent('Auth');
     $this->_plusPlusCount($auth->user(), 'cookie_login_count');
 }
コード例 #3
0
ファイル: TestShell.php プロジェクト: abf6ug/statbro
 public function generateAllFriendActivities()
 {
     $controller = new AppController();
     $stream = $controller->loadComponent('Stream');
     $f_table = TableRegistry::get('Friendships');
     $friends = $f_table->find()->where(['status' => 'accepted'])->order(['Friendships.modified' => 'desc'])->all();
     foreach ($friends as $friend) {
         $base_data = $stream->_createStreamData($friend->id, 'Friendship');
         if (!$base_data) {
             continue;
         }
         //            debug($friend->getShortName());
         //            debug($base_data);
         //            if($base_data['game_type_name'] =='Coding')
         //                continue;
         //            debug($base_data);
         //            debug($game->winners);
         //            debug($base_data['display']);
         //            if (!$tm_table->exists(['id'=>$base_data['first_user_id']]))
         $stream->_pushToStream($base_data, $base_data['first_user_id']);
         //            if (!$tm_table->exists(['id'=>$base_data['second_user_id']]))
         $stream->_pushToStream($base_data, $base_data['second_user_id']);
     }
 }
コード例 #4
0
 /**
  * Start the shell and interactive console.
  *
  * @return int|void
  */
 public function main()
 {
     $sa_table = TableRegistry::get('Friendships');
     $fitbit_accounts = $sa_table->find()->matching('Froms.SocialAccounts', function ($q) {
         return $q->where(['provider' => 'Fitbit']);
     })->contain(['Tos']);
     $game = TableRegistry::get('Games');
     $controller = new AppController();
     $stream = $controller->loadComponent('Stream');
     $tm_table = TableRegistry::get('TempMembers');
     debug(Time::now()->i18nFormat('yyyy-MM-dd 00:00:00'));
     $lr_table = TableRegistry::get('LinkedRecords');
     foreach ($fitbit_accounts as $fitbit_account) {
         //find all pairings of fitbit friends
         if (empty($social_accounts = $fitbit_account['to']['social_accounts'])) {
             continue;
         }
         $fitbit_social_account = false;
         foreach ($social_accounts as $social_account) {
             if ($social_account->provider == 'Fitbit') {
                 $fitbit_social_account = $social_account->id;
             }
         }
         if (!$fitbit_social_account) {
             continue;
         }
         //
         //find todays linked record
         $to = $lr_table->find()->where(['social_account_id' => $fitbit_social_account, 'associated_date' => Time::now()->i18nFormat('yyyy-MM-dd 00:00:00')]);
         if (!$to->first()) {
             continue;
         }
         //
         //            debug($to->first());
         //            return;
         $to_mem = ['member_id' => $fitbit_account->to->id, 'points' => null, 'role' => 'member', 'linked_record_id' => $to->first()->id];
         if (empty($social_accounts = $fitbit_account['from']['social_accounts'])) {
             continue;
         }
         $fitbit_social_account = false;
         foreach ($social_accounts as $social_account) {
             if ($social_account->provider == 'Fitbit') {
                 $fitbit_social_account = $social_account->id;
             }
         }
         if (!$fitbit_social_account) {
             continue;
         }
         $from = $lr_table->find()->where(['social_account_id' => $fitbit_social_account, 'associated_date' => Time::now()->i18nFormat('yyyy-MM-dd 00:00:00')]);
         if (!$from->first()) {
             continue;
         }
         $from_mem = ['member_id' => $fitbit_account->from->id, 'points' => null, 'role' => 'member', 'linked_record_id' => $from->first()->id];
         $game_array = ['status' => 'complete', 'score_type' => 'score', 'game_type_id' => '81e376fa-9f08-4814-82e7-00a2cbf1935b', 'game_memberships' => [$to_mem, $from_mem]];
         $new_game = $game->newEntity($game_array);
         if ($game->save($new_game)) {
             $base_data = $stream->_createStreamData($new_game->id, 'Game');
             Debugger::log($base_data);
             if ($base_data) {
                 if (!$tm_table->exists(['id' => $base_data['first_user_id']])) {
                     $stream->_pushToStream($base_data, $base_data['first_user_id']);
                 }
                 if (!$tm_table->exists(['id' => $base_data['second_user_id']])) {
                     $stream->_pushToStream($base_data, $base_data['second_user_id']);
                 }
             }
         }
     }
 }