本文整理汇总了PHP中App\Controller\AppController::loadComponent方法的典型用法代码示例。如果您正苦于以下问题:PHP AppController::loadComponent方法的具体用法?PHP AppController::loadComponent怎么用?PHP AppController::loadComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Controller\AppController
的用法示例。
在下文中一共展示了AppController::loadComponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateMarked
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: afterCookieLogin
public function afterCookieLogin($event, $entity, $options = [])
{
$controller = new AppController();
$auth = $controller->loadComponent('Auth');
$this->_plusPlusCount($auth->user(), 'cookie_login_count');
}
示例3: generateAllFriendActivities
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: main
/**
* 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']);
}
}
}
}
}