diff --git a/CRM/Twingle/Page/Profiles.php b/CRM/Twingle/Page/Profiles.php index f9fad8a..eb5bf0c 100644 --- a/CRM/Twingle/Page/Profiles.php +++ b/CRM/Twingle/Page/Profiles.php @@ -18,7 +18,8 @@ use CRM_Twingle_ExtensionUtil as E; class CRM_Twingle_Page_Profiles extends CRM_Core_Page { public function run() { - $profiles = array(); + CRM_Utils_System::setTitle(E::ts("Twingle API Profiles")); + $profiles = []; foreach (CRM_Twingle_Profile::getProfiles() as $profile_name => $profile) { $profiles[$profile_name]['name'] = $profile_name; foreach (CRM_Twingle_Profile::allowedAttributes() as $attribute) { @@ -26,6 +27,7 @@ class CRM_Twingle_Page_Profiles extends CRM_Core_Page { } } $this->assign('profiles', $profiles); + $this->assign('profile_stats', CRM_Twingle_Profile::getProfileStats()); parent::run(); } diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index e5c0faf..58a8352 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -385,7 +385,8 @@ class CRM_Twingle_Profile { * Retrieves the list of all profiles persisted within the current CiviCRM * settings, including the default profile. * - * @return CRM_Twingle_Profile[] + * @return array + * profile_name => CRM_Twingle_Profile */ public static function getProfiles() { // todo: cache? @@ -396,4 +397,25 @@ class CRM_Twingle_Profile { } return $profiles; } + + /** + * Get the stats (access_count, last_access) for all twingle profiles + * + * @return CRM_Twingle_Profile[] + */ + public static function getProfileStats() { + $stats = []; + $profile_data = CRM_Core_DAO::executeQuery("SELECT name, last_access, access_counter FROM civicrm_twingle_profile"); + while ($profile_data->fetch()) { + $stats[$profile_data->name] = [ + 'name' => $profile_data->name, + 'last_access' => $profile_data->last_access, + 'last_access_txt' => $profile_data->last_access ? date('Y-m-d H:i:s', strtotime($profile_data->last_access)) : E::ts("never"), + 'access_counter' => $profile_data->access_counter, + 'access_counter_txt' => $profile_data->access_counter ? ((int) $profile_data->access_counter) . 'x' : E::ts("never"), + ]; + } + return $stats; + } + } diff --git a/templates/CRM/Twingle/Page/Profiles.tpl b/templates/CRM/Twingle/Page/Profiles.tpl index f97b9ed..b5b869e 100644 --- a/templates/CRM/Twingle/Page/Profiles.tpl +++ b/templates/CRM/Twingle/Page/Profiles.tpl @@ -26,6 +26,8 @@ {ts domain="de.systopia.twingle"}Profile name{/ts} {ts domain="de.systopia.twingle"}Properties{/ts} + {ts domain="de.systopia.twingle"}Used{/ts} + {ts domain="de.systopia.twingle"}Last Used{/ts} {ts domain="de.systopia.twingle"}Operations{/ts} @@ -37,6 +39,8 @@
{ts domain="de.systopia.twingle"}Selector{/ts}: {$profile.selector}
+ {ts domain="de.systopia.twingle"}{$profile_stats.$profile_name.access_counter_txt}{/ts} + {ts domain="de.systopia.twingle"}{$profile_stats.$profile_name.last_access_txt}{/ts} {ts domain="de.systopia.twingle"}Edit{/ts} {ts domain="de.systopia.twingle"}Copy{/ts}