Skip to content

Commit

Permalink
v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziven committed Nov 1, 2022
1 parent e29c7dc commit 6d90a25
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
3 changes: 1 addition & 2 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

(new Extend\Locales(__DIR__ . '/locale')),

(new Extend\Policy())
->modelPolicy(User::class, UserPolicy::class),
(new Extend\Policy())->modelPolicy(User::class, UserPolicy::class),

(new Extend\Event())->listen(Saving::class, [doCheckin::class, 'checkinSaved']),
(new Extend\ApiSerializer(UserSerializer::class))->attributes(AddUserCheckinAttributes::class),
Expand Down
60 changes: 31 additions & 29 deletions src/Listeners/doCheckin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,45 @@ public function __construct(SettingsRepositoryInterface $settings, Dispatcher $e
public function checkinSaved(Saving $event){
$actor = $event->actor;
$user = $event->user;
$actor->assertCan('checkin.allowCheckIn', $user);
$allowCheckIn = $actor->can('checkin.allowCheckIn', $user);

$attributes = Arr::get($event->data, 'attributes', []);
if($allowCheckIn){
$attributes = Arr::get($event->data, 'attributes', []);

if (array_key_exists('canCheckin', $attributes)) {
$canCheckin = true;
$timezone = $this->settings->get('ziven-forum-checkin.checkinTimeZone', 0);
$current_timestamp = time()+$timezone*60*60;
$current_data_at_midnight = strtotime(date('Y-m-d', $current_timestamp)." 00:00:00");

$last_checkin_time = $user->last_checkin_time;
if (array_key_exists('canCheckin', $attributes)) {
$canCheckin = true;
$timezone = $this->settings->get('ziven-forum-checkin.checkinTimeZone', 0);
$current_timestamp = time()+$timezone*60*60;
$current_data_at_midnight = strtotime(date('Y-m-d', $current_timestamp)." 00:00:00");
$last_checkin_time = $user->last_checkin_time;

if($last_checkin_time!==null){
$explode_checkin_data = explode(' ', $last_checkin_time);
$checkin_date_at_midnight = strtotime($explode_checkin_data[0]." 00:00:00");
$canCheckin = $current_data_at_midnight>$checkin_date_at_midnight;
}

if($canCheckin){
if(($current_timestamp-$checkin_date_at_midnight)/3600<48){
$user->total_continuous_checkin_count+=1;
}else{
$user->total_continuous_checkin_count=1;
if($last_checkin_time!==null){
$explode_checkin_data = explode(' ', $last_checkin_time);
$checkin_date_at_midnight = strtotime($explode_checkin_data[0]." 00:00:00");
$canCheckin = $current_data_at_midnight>$checkin_date_at_midnight;
}

if($canCheckin){
if(($current_timestamp-$checkin_date_at_midnight)/3600<48){
$user->total_continuous_checkin_count+=1;
}else{
$user->total_continuous_checkin_count=1;
}

$user->last_checkin_time = date('Y-m-d H:i:s', $current_timestamp);
$user->total_checkin_count+=1;
$user->last_checkin_time = date('Y-m-d H:i:s', $current_timestamp);
$user->total_checkin_count+=1;

// app("log")->error($canCheckin);
// app("log")->error($user->total_continuous_checkin_count);
// app("log")->error($canCheckin);
// app("log")->error($user->total_continuous_checkin_count);

if(isset($user->money)===true){
$checkinRewardMoney = (float)$this->settings->get('ziven-forum-checkin.checkinRewardMoney', 0);
$user->money+=$checkinRewardMoney;
}
if(isset($user->money)===true){
$checkinRewardMoney = (float)$this->settings->get('ziven-forum-checkin.checkinRewardMoney', 0);
$user->money+=$checkinRewardMoney;
}

$this->events->dispatch(new checkinUpdated($user));
$this->events->dispatch(new checkinUpdated($user));
}
}
}
}
Expand Down

0 comments on commit 6d90a25

Please sign in to comment.