[#42] added stats

This commit is contained in:
B. Endres 2022-05-12 13:25:53 +02:00
parent b5b34ff678
commit 65424ab4bc
3 changed files with 30 additions and 2 deletions

View file

@ -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();
}

View file

@ -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;
}
}