1. Go to this page and download the library: Download nugsoft/retention-extractor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nugsoft / retention-extractor example snippets
'clients' => [
'model' => \App\Models\Business::class,
'external_id' => 'id', // must never change for a given business
'name' => 'business_name',
'contact_phone' => 'phone',
'contact_email' => 'email',
'scope' => fn ($query) => $query->where('is_active', true), // optional
'ended' => 'deleted_at', // optional
],
'via' => 'school_branch_id', // each branch is a client
'pick' => 'current', // started and ends last, else the next to begin
'grace' => 'grace_ends_at', // free access after the end
'deadline' => 'license_expires_at', // payment deadline, caps end and grace
'cancelled' => 'revoked_at', // set once the term was terminated
'where' => ['deleted_at' => null, 'revoked_at' => null],
Event::listen(LicenceApplied::class, function (LicenceApplied $event): void {
// The client is the branch there, so its external id is the branch id.
BranchSubscription::forgetCachesForBranch((int) $event->licence->externalId);
});
'blocks' => ['suspended_at'], // set on any row: they may not work
'term_ends' => ['end_date', 'grace_ends_at'], // rows past these are not asked
'term_starts' => ['start_date'], // rows not yet begun are not asked
'client_blocks' => [ // set on the client's own row: they may not work
'table' => 'school_branches', 'key' => 'id', 'columns' => ['suspended_at'],
],
'login_count_7d' => [
'table' => 'sessions',
'distinct' => 'user_id', // people, not rows
'via' => ['user_id' => ['users', 'id', 'business_id']], // no tenant column of its own
'date' => 'last_activity',
'date_format' => 'timestamp', // a unix integer, not a datetime
],