PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.61
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.61
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / admin / class-reviewcontroller.php

class-reviewcontroller.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.61, at public/admin/class-reviewcontroller.php

79 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\admin;
4
5 use Leadin\data\Portal_Options;
6 use Leadin\data\User_Metadata;
7 use Leadin\admin\client\Contacts_Api_Client;
8
9
10 /**
11 * Class responsible for controlling if review banner should show.
12 */
13 class ReviewController {
14
15 const CONTACTS_CREATED_SINCE_ACTIVATION = 5;
16 const REVIEW_BANNER_INTRO_PERIOD = 15;
17 const DAYS_SINCE_LAST_FETCH = 1;
18
19 /**
20 * Checks if user has enough contacts created since plugin activation.
21 */
22 public static function has_contacts_created_since_activation() {
23 if ( self::has_min_contacts() ) {
24 return true;
25 } elseif ( ! self::should_fetch_contacts() ) {
26 return false;
27 }
28 try {
29 User_Metadata::set_review_banner_last_call( time() );
30 $client = new Contacts_Api_Client();
31 $contacts = $client->get_contacts_from_timestamp( Portal_Options::get_activation_time() );
32 $has_min_contacts = count( $contacts->results ) >= self::CONTACTS_CREATED_SINCE_ACTIVATION;
33 User_Metadata::set_has_min_contacts( $has_min_contacts );
34 return $has_min_contacts;
35 } catch ( \Exception $e ) {
36 return false;
37 }
38 }
39
40 /**
41 * Check to see if current time is after introductary period.
42 */
43 public static function is_after_introductary_period() {
44 $activation_time = new \DateTime();
45 $activation_time->setTimestamp( Portal_Options::get_activation_time() );
46 $diff = $activation_time->diff( new \DateTime() );
47 return $diff->days >= self::REVIEW_BANNER_INTRO_PERIOD;
48 }
49
50 /**
51 * Check SKIP_REVIEW meta data for a user.
52 */
53 public static function is_reviewed_or_skipped() {
54 return ! empty( User_Metadata::get_skip_review() );
55 }
56
57 /**
58 * Check if contacts have been fetched at the current day.
59 */
60 public static function should_fetch_contacts() {
61 $last_call_ts = User_Metadata::get_review_banner_last_call();
62 if ( empty( $last_call_ts ) ) {
63 return true;
64 }
65 $last_call_date = new \DateTime();
66 $last_call_date->setTimestamp( $last_call_ts );
67 $diff = $last_call_date->diff( new \DateTime() );
68 return $diff->days >= self::DAYS_SINCE_LAST_FETCH;
69 }
70
71 /**
72 * Check if contacts minimun have already been fulfilled .
73 */
74 public static function has_min_contacts() {
75 return User_Metadata::get_has_min_contacts();
76 }
77
78 }
79