Added counters

HFJ-1610
pull/17/head
Frode Petterson 2016-02-10 11:49:20 +01:00
parent 6580508b1d
commit 58f3617fc1
1 changed files with 53 additions and 13 deletions

View File

@ -71,14 +71,19 @@ class H5PEventBase {
if (self::validLogLevel($type, $sub_type)) { if (self::validLogLevel($type, $sub_type)) {
$this->save(); $this->save();
} }
if (self::validCount($type, $sub_type)) {
$this->count();
}
} }
/** /**
* Determines if the log type should be saved. * Determines if the event type should be saved/logged.
*
* @param string $type * @param string $type
* Name of event type * Name of event type
* @param string $sub_type * @param string $sub_type
* Name of event sub type * Name of event sub type
* @return boolean
*/ */
public static function validLogLevel($type, $sub_type) { public static function validLogLevel($type, $sub_type) {
switch (self::$log_level) { switch (self::$log_level) {
@ -86,24 +91,52 @@ class H5PEventBase {
case self::LOG_NONE: case self::LOG_NONE:
return FALSE; return FALSE;
case self::LOG_ALL: case self::LOG_ALL:
return TRUE; return TRUE; // Log everything
case self::LOG_ACTIONS:
if (self::isAction($type, $sub_type)) {
return TRUE; // Log actions
}
return FALSE;
}
}
case self::LOG_EXTRAS: /**
// Extras help provide H5P with valuable anonymous user data! * Check if event type should be added to counter.
if ( ($type === 'content' && $sub_type === 'shortcode insert') || // Log number of shortcode inserts *
($type === 'library' && $sub_type === NULL) || // Log number of times library is loaded in editor * @param string $type
($type === 'results' && $sub_type === 'content') ) { // Log number of times results page has been opened * Name of event type
* @param string $sub_type
* Name of event sub type
* @return boolean
*/
public static function validCount($type, $sub_type) {
if ( ($type === 'content' && $sub_type === 'shortcode insert') || // Count number of shortcode inserts
($type === 'library' && $sub_type === NULL) || // Count number of times library is loaded in editor
($type === 'results' && $sub_type === 'content') ) { // Count number of times results page has been opened
return TRUE; return TRUE;
} }
// Fall through by intention! elseif (self::isAction($type, $sub_type)) { // Count all actions
case self::LOG_ACTIONS: return TRUE;
}
return FALSE;
}
/**
* Check if event type is action.
*
* @param string $type
* Name of event type
* @param string $sub_type
* Name of event sub type
* @return boolean
*/
public static function isAction($type, $sub_type) {
if ( ($type === 'content' && in_array($sub_type, array('create', 'create upload', 'update', 'update upload', 'upgrade', 'delete'))) || if ( ($type === 'content' && in_array($sub_type, array('create', 'create upload', 'update', 'update upload', 'upgrade', 'delete'))) ||
($type === 'library' && in_array($sub_type, array('create', 'update'))) ) { ($type === 'library' && in_array($sub_type, array('create', 'update'))) ) {
return TRUE; // Log actions return TRUE; // Log actions
} }
return FALSE; return FALSE;
} }
}
/** /**
* A helper which makes it easier for some systems to save the data. * A helper which makes it easier for some systems to save the data.
@ -141,4 +174,11 @@ class H5PEventBase {
protected function save() { protected function save() {
// Does nothing by default, should be overriden by plugin // Does nothing by default, should be overriden by plugin
} }
/**
* Count number of events.
*/
protected function count() {
// Does nothing by default, should be overriden by plugin
}
} }