| 1 |
<?php |
| 2 |
/** |
| 3 |
* Triggers |
| 4 |
* |
| 5 |
* @package GamiPress\H5P\Triggers |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Register plugin specific triggers |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @param array $triggers |
| 18 |
* @return mixed |
| 19 |
*/ |
| 20 |
function gamipress_h5p_activity_triggers( $triggers ) { |
| 21 |
|
| 22 |
$triggers[__( 'H5P', 'gamipress' )] = array( |
| 23 |
|
| 24 |
// Complete content |
| 25 |
'gamipress_h5p_complete_content' => __( 'Complete any interactive content', 'gamipress' ), |
| 26 |
'gamipress_h5p_complete_specific_content' => __( 'Complete a specific interactive content', 'gamipress' ), |
| 27 |
'gamipress_h5p_complete_specific_content_type' => __( 'Complete any interactive content of a specific type', 'gamipress' ), |
| 28 |
'gamipress_h5p_complete_content_tag' => __( 'Complete any interactive content of a tag', 'gamipress' ), |
| 29 |
|
| 30 |
// At 100% |
| 31 |
'gamipress_h5p_max_complete_content' => __( 'Complete any interactive content at maximum score', 'gamipress' ), |
| 32 |
'gamipress_h5p_max_complete_specific_content' => __( 'Complete a specific interactive content at maximum score', 'gamipress' ), |
| 33 |
'gamipress_h5p_max_complete_specific_content_type' => __( 'Complete any interactive content of a specific type at maximum score', 'gamipress' ), |
| 34 |
'gamipress_h5p_max_complete_content_tag' => __( 'Complete any interactive content at maximum score of a tag', 'gamipress' ), |
| 35 |
|
| 36 |
// Min Score |
| 37 |
'gamipress_h5p_complete_content_min_score' => __( 'Complete any interactive content with a minimum score', 'gamipress' ), |
| 38 |
'gamipress_h5p_complete_specific_content_min_score' => __( 'Complete a specific interactive content with a minimum score', 'gamipress' ), |
| 39 |
'gamipress_h5p_complete_specific_content_type_min_score' => __( 'Complete any interactive content of a specific type with a minimum score', 'gamipress' ), |
| 40 |
'gamipress_h5p_complete_content_min_score_tag' => __( 'Complete any interactive content with a minimum score of a tag', 'gamipress' ), |
| 41 |
|
| 42 |
// Max Score |
| 43 |
'gamipress_h5p_complete_content_max_score' => __( 'Complete any interactive content with a maximum score', 'gamipress' ), |
| 44 |
'gamipress_h5p_complete_specific_content_max_score' => __( 'Complete a specific interactive content with a maximum score', 'gamipress' ), |
| 45 |
'gamipress_h5p_complete_specific_content_type_max_score' => __( 'Complete any interactive content of a specific type with a maximum score', 'gamipress' ), |
| 46 |
'gamipress_h5p_complete_content_max_score_tag' => __( 'Complete any interactive content with a maximum score of a tag', 'gamipress' ), |
| 47 |
|
| 48 |
// Between Score |
| 49 |
'gamipress_h5p_complete_content_between_score' => __( 'Complete any interactive content on a range of scores', 'gamipress' ), |
| 50 |
'gamipress_h5p_complete_specific_content_between_score' => __( 'Complete a specific interactive content on a range of scores', 'gamipress' ), |
| 51 |
'gamipress_h5p_complete_specific_content_type_between_score' => __( 'Complete any interactive content of a specific type on a range of scores', 'gamipress' ), |
| 52 |
'gamipress_h5p_complete_content_between_score_tag' => __( 'Complete any interactive content on a range of scores of a tag', 'gamipress' ), |
| 53 |
|
| 54 |
// Min percentage |
| 55 |
'gamipress_h5p_complete_content_min_percentage' => __( 'Complete any interactive content with a minimum percentage score', 'gamipress' ), |
| 56 |
'gamipress_h5p_complete_specific_content_min_percentage' => __( 'Complete a specific interactive content with a minimum percentage score', 'gamipress' ), |
| 57 |
'gamipress_h5p_complete_specific_content_type_min_percentage' => __( 'Complete any interactive content of a specific type with a minimum percentage score', 'gamipress' ), |
| 58 |
'gamipress_h5p_complete_content_min_percentage_tag' => __( 'Complete any interactive content with a minimum percentage score of a tag', 'gamipress' ), |
| 59 |
|
| 60 |
// Max percentage |
| 61 |
'gamipress_h5p_complete_content_max_percentage' => __( 'Complete any interactive content with a maximum percentage score', 'gamipress' ), |
| 62 |
'gamipress_h5p_complete_specific_content_max_percentage' => __( 'Complete a specific interactive content with a maximum percentage score', 'gamipress' ), |
| 63 |
'gamipress_h5p_complete_specific_content_type_max_percentage' => __( 'Complete any interactive content of a specific type with a maximum percentage score', 'gamipress' ), |
| 64 |
'gamipress_h5p_complete_content_max_percentage_tag' => __( 'Complete any interactive content with a maximum percentage score of a tag', 'gamipress' ), |
| 65 |
|
| 66 |
// Between percentage |
| 67 |
'gamipress_h5p_complete_content_between_percentage' => __( 'Complete any interactive content on a range of percentages scores', 'gamipress' ), |
| 68 |
'gamipress_h5p_complete_specific_content_between_percentage' => __( 'Complete a specific interactive content on a range of percentages scores', 'gamipress' ), |
| 69 |
'gamipress_h5p_complete_specific_content_type_between_percentage' => __( 'Complete any interactive content of a specific type on a range of percentages scores', 'gamipress' ), |
| 70 |
'gamipress_h5p_complete_content_between_percentage_tag' => __( 'Complete any interactive content on a range of percentages scores of a tag', 'gamipress' ), |
| 71 |
); |
| 72 |
|
| 73 |
return $triggers; |
| 74 |
|
| 75 |
} |
| 76 |
add_filter( 'gamipress_activity_triggers', 'gamipress_h5p_activity_triggers' ); |
| 77 |
|
| 78 |
/** |
| 79 |
* Build custom activity trigger label |
| 80 |
* |
| 81 |
* @since 1.0.0 |
| 82 |
* |
| 83 |
* @param string $title |
| 84 |
* @param integer $requirement_id |
| 85 |
* @param array $requirement |
| 86 |
* |
| 87 |
* @return string |
| 88 |
*/ |
| 89 |
function gamipress_h5p_activity_trigger_label( $title, $requirement_id, $requirement ) { |
| 90 |
|
| 91 |
global $wpdb; |
| 92 |
|
| 93 |
$content_type = ( isset( $requirement['h5p_content_type'] ) ) ? $requirement['h5p_content_type'] : ''; |
| 94 |
$score = ( isset( $requirement['h5p_score'] ) ) ? absint( $requirement['h5p_score'] ) : 0; |
| 95 |
$min_score = ( isset( $requirement['h5p_min_score'] ) ) ? absint( $requirement['h5p_min_score'] ) : 0; |
| 96 |
$max_score = ( isset( $requirement['h5p_max_score'] ) ) ? absint( $requirement['h5p_max_score'] ) : 0; |
| 97 |
$percentage = ( isset( $requirement['h5p_percentage'] ) ) ? absint( $requirement['h5p_percentage'] ) : 0; |
| 98 |
$min_percentage = ( isset( $requirement['h5p_min_percentage'] ) ) ? absint( $requirement['h5p_min_percentage'] ) : 0; |
| 99 |
$max_percentage = ( isset( $requirement['h5p_max_percentage'] ) ) ? absint( $requirement['h5p_max_percentage'] ) : 0; |
| 100 |
|
| 101 |
switch( $requirement['trigger_type'] ) { |
| 102 |
|
| 103 |
// Complete specific content type event |
| 104 |
case 'gamipress_h5p_complete_specific_content_type': |
| 105 |
if( $content_type !== '' ) |
| 106 |
return sprintf( __( 'Complete a %s', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ) ); |
| 107 |
break; |
| 108 |
// Complete specific content type at maximum score event |
| 109 |
case 'gamipress_h5p_max_complete_specific_content_type': |
| 110 |
if( $content_type !== '' ) |
| 111 |
return sprintf( __( 'Complete a %s at maximum score', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ) ); |
| 112 |
break; |
| 113 |
|
| 114 |
// Min score |
| 115 |
case 'gamipress_h5p_complete_content_min_score': |
| 116 |
return sprintf( __( 'Completed an interactive content with a score of %d or higher', 'gamipress' ), $score ); |
| 117 |
break; |
| 118 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 119 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 120 |
return sprintf( __( 'Complete %s with a score of %d or higher', 'gamipress' ), gamipress_h5p_get_content_title( $achievement_post_id ), $score ); |
| 121 |
break; |
| 122 |
case 'gamipress_h5p_complete_specific_content_type_min_score': |
| 123 |
if( $content_type !== '' ) |
| 124 |
return sprintf( __( 'Complete a %s with a score of %d or higher', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ), $score ); |
| 125 |
break; |
| 126 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 127 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 128 |
return sprintf( __( 'Completed an interactive content with a score of %d or higher of %s tag', 'gamipress' ), $score, gamipress_h5p_get_tag_title( $achievement_post_id ) ); |
| 129 |
break; |
| 130 |
|
| 131 |
// Max score |
| 132 |
case 'gamipress_h5p_complete_content_max_score': |
| 133 |
return sprintf( __( 'Completed an interactive content with a score of %d or lower', 'gamipress' ), $score ); |
| 134 |
break; |
| 135 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 136 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 137 |
return sprintf( __( 'Complete %s with a score of %d or lower', 'gamipress' ), gamipress_h5p_get_content_title( $achievement_post_id ), $score ); |
| 138 |
break; |
| 139 |
case 'gamipress_h5p_complete_specific_content_type_max_score': |
| 140 |
if( $content_type !== '' ) |
| 141 |
return sprintf( __( 'Complete a %s with a score of %d or lower', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ), $score ); |
| 142 |
break; |
| 143 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 144 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 145 |
return sprintf( __( 'Completed an interactive content with a score of %d or lower of %s tag', 'gamipress' ), $score, gamipress_h5p_get_tag_title( $achievement_post_id ) ); |
| 146 |
break; |
| 147 |
|
| 148 |
// Between score |
| 149 |
case 'gamipress_h5p_complete_content_between_score': |
| 150 |
return sprintf( __( 'Completed an interactive content with a score between %d and %d', 'gamipress' ), $min_score, $max_score ); |
| 151 |
break; |
| 152 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 153 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 154 |
return sprintf( __( 'Complete %s with a score between %d and %d', 'gamipress' ), gamipress_h5p_get_content_title( $achievement_post_id ), $min_score, $max_score ); |
| 155 |
break; |
| 156 |
case 'gamipress_h5p_complete_specific_content_type_between_score': |
| 157 |
if( $content_type !== '' ) |
| 158 |
return sprintf( __( 'Complete a %s with a score between %d and %d', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ), $min_score, $max_score ); |
| 159 |
break; |
| 160 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 161 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 162 |
return sprintf( __( 'Completed an interactive content with a score between %d and %d of %s tag', 'gamipress' ), $min_score, $max_score, gamipress_h5p_get_tag_title( $achievement_post_id ) ); |
| 163 |
break; |
| 164 |
|
| 165 |
// Min percentage |
| 166 |
case 'gamipress_h5p_complete_content_min_percentage': |
| 167 |
return sprintf( __( 'Completed an interactive content with a percentage score of %d or higher', 'gamipress' ), $percentage ); |
| 168 |
break; |
| 169 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 170 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 171 |
return sprintf( __( 'Complete %s with a percentage score of %d or higher', 'gamipress' ), gamipress_h5p_get_content_title( $achievement_post_id ), $percentage ); |
| 172 |
break; |
| 173 |
case 'gamipress_h5p_complete_specific_content_type_min_percentage': |
| 174 |
if( $content_type !== '' ) |
| 175 |
return sprintf( __( 'Complete a %s with a percentage score of %d or higher', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ), $percentage ); |
| 176 |
break; |
| 177 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 178 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 179 |
return sprintf( __( 'Completed an interactive content with a percentage score of %d or higher of %s tag', 'gamipress' ), $percentage, gamipress_h5p_get_tag_title( $achievement_post_id ) ); |
| 180 |
break; |
| 181 |
|
| 182 |
// Max percentage |
| 183 |
case 'gamipress_h5p_complete_content_max_percentage': |
| 184 |
return sprintf( __( 'Completed an interactive content with a percentage score of %d or lower', 'gamipress' ), $percentage ); |
| 185 |
break; |
| 186 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 187 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 188 |
return sprintf( __( 'Complete %s with a percentage score of %d or lower', 'gamipress' ), gamipress_h5p_get_content_title( $achievement_post_id ), $percentage ); |
| 189 |
break; |
| 190 |
case 'gamipress_h5p_complete_specific_content_type_max_percentage': |
| 191 |
if( $content_type !== '' ) |
| 192 |
return sprintf( __( 'Complete a %s with a percentage score of %d or lower', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ), $percentage ); |
| 193 |
break; |
| 194 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 195 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 196 |
return sprintf( __( 'Completed an interactive content with a percentage score of %d or lower of %s tag', 'gamipress' ), $percentage, gamipress_h5p_get_tag_title( $achievement_post_id ) ); |
| 197 |
break; |
| 198 |
|
| 199 |
// Between percentages |
| 200 |
case 'gamipress_h5p_complete_content_between_percentage': |
| 201 |
return sprintf( __( 'Completed an interactive content with a percentage score between %d and %d', 'gamipress' ), $min_percentage, $max_percentage ); |
| 202 |
break; |
| 203 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 204 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 205 |
return sprintf( __( 'Complete %s with a percentage score between %d and %d', 'gamipress' ), gamipress_h5p_get_content_title( $achievement_post_id ), $min_percentage, $max_percentage ); |
| 206 |
break; |
| 207 |
case 'gamipress_h5p_complete_specific_content_type_between_percentage': |
| 208 |
if( $content_type !== '' ) |
| 209 |
return sprintf( __( 'Complete a %s with a percentage score between %d and %d', 'gamipress' ), gamipress_h5p_get_content_type_title( $content_type ), $min_percentage, $max_percentage ); |
| 210 |
break; |
| 211 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 212 |
$achievement_post_id = absint( $requirement['achievement_post'] ); |
| 213 |
return sprintf( __( 'Completed an interactive content with a percentage score between %d and %d of %s tag', 'gamipress' ), $min_percentage, $max_percentage, gamipress_h5p_get_tag_title( $achievement_post_id ) ); |
| 214 |
break; |
| 215 |
|
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
return $title; |
| 220 |
} |
| 221 |
add_filter( 'gamipress_activity_trigger_label', 'gamipress_h5p_activity_trigger_label', 10, 3 ); |
| 222 |
|
| 223 |
/** |
| 224 |
* Register plugin specific activity triggers |
| 225 |
* |
| 226 |
* @since 1.0.0 |
| 227 |
* |
| 228 |
* @param array $specific_activity_triggers |
| 229 |
* @return array |
| 230 |
*/ |
| 231 |
function gamipress_h5p_specific_activity_triggers( $specific_activity_triggers ) { |
| 232 |
|
| 233 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content'] = array( 'h5p_contents' ); |
| 234 |
$specific_activity_triggers['gamipress_h5p_max_complete_specific_content'] = array( 'h5p_contents' ); |
| 235 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content_min_score'] = array( 'h5p_contents' ); |
| 236 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content_max_score'] = array( 'h5p_contents' ); |
| 237 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content_between_score'] = array( 'h5p_contents' ); |
| 238 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content_min_percentage'] = array( 'h5p_contents' ); |
| 239 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content_max_percentage'] = array( 'h5p_contents' ); |
| 240 |
$specific_activity_triggers['gamipress_h5p_complete_specific_content_between_percentage'] = array( 'h5p_contents' ); |
| 241 |
// Tags |
| 242 |
$specific_activity_triggers['gamipress_h5p_complete_content_tag'] = array( 'h5p_tags' ); |
| 243 |
$specific_activity_triggers['gamipress_h5p_max_complete_content_tag'] = array( 'h5p_tags' ); |
| 244 |
$specific_activity_triggers['gamipress_h5p_complete_content_min_score_tag'] = array( 'h5p_tags' ); |
| 245 |
$specific_activity_triggers['gamipress_h5p_complete_content_max_score_tag'] = array( 'h5p_tags' ); |
| 246 |
$specific_activity_triggers['gamipress_h5p_complete_content_between_score_tag'] = array( 'h5p_tags' ); |
| 247 |
$specific_activity_triggers['gamipress_h5p_complete_content_min_percentage_tag'] = array( 'h5p_tags' ); |
| 248 |
$specific_activity_triggers['gamipress_h5p_complete_content_max_percentage_tag'] = array( 'h5p_tags' ); |
| 249 |
$specific_activity_triggers['gamipress_h5p_complete_content_between_percentage_tag'] = array( 'h5p_tags' ); |
| 250 |
|
| 251 |
return $specific_activity_triggers; |
| 252 |
|
| 253 |
} |
| 254 |
add_filter( 'gamipress_specific_activity_triggers', 'gamipress_h5p_specific_activity_triggers' ); |
| 255 |
|
| 256 |
/** |
| 257 |
* Register plugin specific activity triggers labels |
| 258 |
* |
| 259 |
* @since 1.0.0 |
| 260 |
* |
| 261 |
* @param array $specific_activity_trigger_labels |
| 262 |
* @return array |
| 263 |
*/ |
| 264 |
function gamipress_h5p_specific_activity_trigger_label( $specific_activity_trigger_labels ) { |
| 265 |
|
| 266 |
$specific_activity_trigger_labels['gamipress_h5p_complete_specific_content'] = __( 'Complete %s', 'gamipress' ); |
| 267 |
$specific_activity_trigger_labels['gamipress_h5p_max_complete_specific_content'] = __( 'Complete %s at maximum score', 'gamipress' ); |
| 268 |
$specific_activity_trigger_labels['gamipress_h5p_complete_content_tag'] = __( 'Complete content of %s tag', 'gamipress' ); |
| 269 |
$specific_activity_trigger_labels['gamipress_h5p_max_complete_content_tag'] = __( 'Complete content at maximum score of %s tag', 'gamipress' ); |
| 270 |
|
| 271 |
return $specific_activity_trigger_labels; |
| 272 |
} |
| 273 |
add_filter( 'gamipress_specific_activity_trigger_label', 'gamipress_h5p_specific_activity_trigger_label' ); |
| 274 |
|
| 275 |
/** |
| 276 |
* Get plugin specific activity trigger post title |
| 277 |
* |
| 278 |
* @since 1.0.0 |
| 279 |
* |
| 280 |
* @param string $post_title |
| 281 |
* @param integer $specific_id |
| 282 |
* @param string $trigger_type |
| 283 |
* |
| 284 |
* @return string |
| 285 |
*/ |
| 286 |
function gamipress_h5p_specific_activity_trigger_post_title( $post_title, $specific_id, $trigger_type ) { |
| 287 |
|
| 288 |
switch( $trigger_type ) { |
| 289 |
case 'gamipress_h5p_complete_specific_content': |
| 290 |
case 'gamipress_h5p_max_complete_specific_content': |
| 291 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 292 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 293 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 294 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 295 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 296 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 297 |
if( absint( $specific_id ) !== 0 ) { |
| 298 |
|
| 299 |
// Get the content title |
| 300 |
$content_title = gamipress_h5p_get_content_title( $specific_id ); |
| 301 |
|
| 302 |
$post_title = $content_title; |
| 303 |
} |
| 304 |
break; |
| 305 |
case 'gamipress_h5p_complete_content_tag': |
| 306 |
case 'gamipress_h5p_max_complete_content_tag': |
| 307 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 308 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 309 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 310 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 311 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 312 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 313 |
if( absint( $specific_id ) !== 0 ) { |
| 314 |
|
| 315 |
// Get the tag title |
| 316 |
$tag_title = gamipress_h5p_get_tag_title( $specific_id ); |
| 317 |
|
| 318 |
$post_title = $tag_title; |
| 319 |
} |
| 320 |
break; |
| 321 |
} |
| 322 |
|
| 323 |
return $post_title; |
| 324 |
|
| 325 |
} |
| 326 |
add_filter( 'gamipress_specific_activity_trigger_post_title', 'gamipress_h5p_specific_activity_trigger_post_title', 10, 3 ); |
| 327 |
|
| 328 |
/** |
| 329 |
* Get plugin specific activity trigger permalink |
| 330 |
* |
| 331 |
* @since 1.0.0 |
| 332 |
* |
| 333 |
* @param string $permalink |
| 334 |
* @param integer $specific_id |
| 335 |
* @param string $trigger_type |
| 336 |
* @param integer $site_id |
| 337 |
* |
| 338 |
* @return string |
| 339 |
*/ |
| 340 |
function gamipress_h5p_specific_activity_trigger_permalink( $permalink, $specific_id, $trigger_type, $site_id ) { |
| 341 |
|
| 342 |
switch( $trigger_type ) { |
| 343 |
case 'gamipress_h5p_complete_specific_content': |
| 344 |
case 'gamipress_h5p_max_complete_specific_content': |
| 345 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 346 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 347 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 348 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 349 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 350 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 351 |
case 'gamipress_h5p_complete_content_tag': |
| 352 |
case 'gamipress_h5p_max_complete_content_tag': |
| 353 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 354 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 355 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 356 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 357 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 358 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 359 |
$permalink = ''; |
| 360 |
break; |
| 361 |
} |
| 362 |
|
| 363 |
return $permalink; |
| 364 |
|
| 365 |
} |
| 366 |
add_filter( 'gamipress_specific_activity_trigger_permalink', 'gamipress_h5p_specific_activity_trigger_permalink', 10, 4 ); |
| 367 |
|
| 368 |
/** |
| 369 |
* Get user for a h5pn trigger action. |
| 370 |
* |
| 371 |
* @since 1.0.0 |
| 372 |
* |
| 373 |
* @param integer $user_id user ID to override. |
| 374 |
* @param string $trigger Trigger name. |
| 375 |
* @param array $args Passed trigger args. |
| 376 |
* @return integer User ID. |
| 377 |
*/ |
| 378 |
function gamipress_h5p_trigger_get_user_id( $user_id, $trigger, $args ) { |
| 379 |
|
| 380 |
switch ( $trigger ) { |
| 381 |
// Complete content |
| 382 |
case 'gamipress_h5p_complete_content': |
| 383 |
case 'gamipress_h5p_complete_specific_content': |
| 384 |
case 'gamipress_h5p_complete_specific_content_type': |
| 385 |
case 'gamipress_h5p_complete_content_tag': |
| 386 |
// At 100% |
| 387 |
case 'gamipress_h5p_max_complete_content': |
| 388 |
case 'gamipress_h5p_max_complete_specific_content': |
| 389 |
case 'gamipress_h5p_max_complete_specific_content_type': |
| 390 |
case 'gamipress_h5p_max_complete_content_tag': |
| 391 |
// Min score |
| 392 |
case 'gamipress_h5p_complete_content_min_score': |
| 393 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 394 |
case 'gamipress_h5p_complete_specific_content_type_min_score': |
| 395 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 396 |
// Max score |
| 397 |
case 'gamipress_h5p_complete_content_max_score': |
| 398 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 399 |
case 'gamipress_h5p_complete_specific_content_type_max_score': |
| 400 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 401 |
// Between score |
| 402 |
case 'gamipress_h5p_complete_content_between_score': |
| 403 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 404 |
case 'gamipress_h5p_complete_specific_content_type_between_score': |
| 405 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 406 |
// Min percentage |
| 407 |
case 'gamipress_h5p_complete_content_min_percentage': |
| 408 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 409 |
case 'gamipress_h5p_complete_specific_content_type_min_percentage': |
| 410 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 411 |
// Max percentage |
| 412 |
case 'gamipress_h5p_complete_content_max_percentage': |
| 413 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 414 |
case 'gamipress_h5p_complete_specific_content_type_max_percentage': |
| 415 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 416 |
// Between percentage |
| 417 |
case 'gamipress_h5p_complete_content_between_percentage': |
| 418 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 419 |
case 'gamipress_h5p_complete_specific_content_type_between_percentage': |
| 420 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 421 |
|
| 422 |
$user_id = $args[1]; |
| 423 |
break; |
| 424 |
} |
| 425 |
|
| 426 |
return $user_id; |
| 427 |
|
| 428 |
} |
| 429 |
add_filter( 'gamipress_trigger_get_user_id', 'gamipress_h5p_trigger_get_user_id', 10, 3 ); |
| 430 |
|
| 431 |
/** |
| 432 |
* Get the id for a h5pn specific trigger action. |
| 433 |
* |
| 434 |
* @since 1.0.0 |
| 435 |
* |
| 436 |
* @param integer $specific_id Specific ID. |
| 437 |
* @param string $trigger Trigger name. |
| 438 |
* @param array $args Passed trigger args. |
| 439 |
* |
| 440 |
* @return integer Specific ID. |
| 441 |
*/ |
| 442 |
function gamipress_h5p_specific_trigger_get_id( $specific_id, $trigger = '', $args = array() ) { |
| 443 |
|
| 444 |
switch ( $trigger ) { |
| 445 |
case 'gamipress_h5p_complete_specific_content': |
| 446 |
case 'gamipress_h5p_max_complete_specific_content': |
| 447 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 448 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 449 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 450 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 451 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 452 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 453 |
$specific_id = $args[2]; |
| 454 |
break; |
| 455 |
case 'gamipress_h5p_complete_content_tag': |
| 456 |
case 'gamipress_h5p_max_complete_content_tag': |
| 457 |
$specific_id = $args[5]; |
| 458 |
break; |
| 459 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 460 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 461 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 462 |
$specific_id = $args[6]; |
| 463 |
break; |
| 464 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 465 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 466 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 467 |
$specific_id = $args[7]; |
| 468 |
|
| 469 |
} |
| 470 |
|
| 471 |
return $specific_id; |
| 472 |
} |
| 473 |
add_filter( 'gamipress_specific_trigger_get_id', 'gamipress_h5p_specific_trigger_get_id', 10, 3 ); |
| 474 |
|
| 475 |
/** |
| 476 |
* Extended meta data for event trigger logging |
| 477 |
* |
| 478 |
* @since 1.0.0 |
| 479 |
* |
| 480 |
* @param array $log_meta |
| 481 |
* @param integer $user_id |
| 482 |
* @param string $trigger |
| 483 |
* @param integer $site_id |
| 484 |
* @param array $args |
| 485 |
* |
| 486 |
* @return array |
| 487 |
*/ |
| 488 |
function gamipress_h5p_log_event_trigger_meta_data( $log_meta, $user_id, $trigger, $site_id, $args ) { |
| 489 |
|
| 490 |
switch ( $trigger ) { |
| 491 |
// Complete content |
| 492 |
case 'gamipress_h5p_complete_content': |
| 493 |
case 'gamipress_h5p_complete_specific_content': |
| 494 |
case 'gamipress_h5p_complete_specific_content_type': |
| 495 |
// At 100% |
| 496 |
case 'gamipress_h5p_max_complete_content': |
| 497 |
case 'gamipress_h5p_max_complete_specific_content': |
| 498 |
case 'gamipress_h5p_max_complete_specific_content_type': |
| 499 |
// Add the result ID, content ID and the content type |
| 500 |
$log_meta['result_id'] = $args[0]; |
| 501 |
$log_meta['content_id'] = $args[2]; |
| 502 |
$log_meta['content_type'] = $args[3]; |
| 503 |
break; |
| 504 |
// Min score |
| 505 |
case 'gamipress_h5p_complete_content_min_score': |
| 506 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 507 |
case 'gamipress_h5p_complete_specific_content_type_min_score': |
| 508 |
// Max score |
| 509 |
case 'gamipress_h5p_complete_content_max_score': |
| 510 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 511 |
case 'gamipress_h5p_complete_specific_content_type_max_score': |
| 512 |
// Between score |
| 513 |
case 'gamipress_h5p_complete_content_between_score': |
| 514 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 515 |
case 'gamipress_h5p_complete_specific_content_type_between_score': |
| 516 |
// Add the result ID, content ID, the content type and the score |
| 517 |
$log_meta['result_id'] = $args[0]; |
| 518 |
$log_meta['content_id'] = $args[2]; |
| 519 |
$log_meta['content_type'] = $args[3]; |
| 520 |
$log_meta['score'] = $args[4]; |
| 521 |
break; |
| 522 |
// Min percentage |
| 523 |
case 'gamipress_h5p_complete_content_min_percentage': |
| 524 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 525 |
case 'gamipress_h5p_complete_specific_content_type_min_percentage': |
| 526 |
// Max percentage |
| 527 |
case 'gamipress_h5p_complete_content_max_percentage': |
| 528 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 529 |
case 'gamipress_h5p_complete_specific_content_type_max_percentage': |
| 530 |
// Between percentage |
| 531 |
case 'gamipress_h5p_complete_content_between_percentage': |
| 532 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 533 |
case 'gamipress_h5p_complete_specific_content_type_between_percentage': |
| 534 |
// Add the result ID, content ID, the content type, the score and maximum score |
| 535 |
$log_meta['result_id'] = $args[0]; |
| 536 |
$log_meta['content_id'] = $args[2]; |
| 537 |
$log_meta['content_type'] = $args[3]; |
| 538 |
$log_meta['score'] = $args[4]; |
| 539 |
$log_meta['max_score'] = $args[5]; |
| 540 |
$log_meta['percentage'] = ( absint( $args[4] ) / absint( $args[5] ) ) * 100; |
| 541 |
break; |
| 542 |
// Tags |
| 543 |
case 'gamipress_h5p_complete_content_tag': |
| 544 |
case 'gamipress_h5p_max_complete_content_tag': |
| 545 |
// Add the result ID, content ID and the content type |
| 546 |
$log_meta['result_id'] = $args[0]; |
| 547 |
$log_meta['content_id'] = $args[2]; |
| 548 |
$log_meta['content_type'] = $args[3]; |
| 549 |
$log_meta['tag'] = $args[5]; |
| 550 |
break; |
| 551 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 552 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 553 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 554 |
// Add the result ID, content ID, the content type and the score |
| 555 |
$log_meta['result_id'] = $args[0]; |
| 556 |
$log_meta['content_id'] = $args[2]; |
| 557 |
$log_meta['content_type'] = $args[3]; |
| 558 |
$log_meta['score'] = $args[4]; |
| 559 |
$log_meta['tag'] = $args[6]; |
| 560 |
break; |
| 561 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 562 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 563 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 564 |
// Add the result ID, content ID, the content type, the score and maximum score |
| 565 |
$log_meta['result_id'] = $args[0]; |
| 566 |
$log_meta['content_id'] = $args[2]; |
| 567 |
$log_meta['content_type'] = $args[3]; |
| 568 |
$log_meta['score'] = $args[4]; |
| 569 |
$log_meta['max_score'] = $args[5]; |
| 570 |
$log_meta['percentage'] = ( absint( $args[4] ) / absint( $args[5] ) ) * 100; |
| 571 |
$log_meta['tag'] = $args[7]; |
| 572 |
break; |
| 573 |
} |
| 574 |
|
| 575 |
return $log_meta; |
| 576 |
} |
| 577 |
add_filter( 'gamipress_log_event_trigger_meta_data', 'gamipress_h5p_log_event_trigger_meta_data', 10, 5 ); |
| 578 |
|
| 579 |
/** |
| 580 |
* Extra data fields |
| 581 |
* |
| 582 |
* @since 1.0.4 |
| 583 |
* |
| 584 |
* @param array $fields |
| 585 |
* @param int $log_id |
| 586 |
* @param string $type |
| 587 |
* |
| 588 |
* @return array |
| 589 |
*/ |
| 590 |
function gamipress_h5p_log_extra_data_fields( $fields, $log_id, $type ) { |
| 591 |
|
| 592 |
global $wpdb; |
| 593 |
|
| 594 |
$prefix = '_gamipress_'; |
| 595 |
|
| 596 |
if( $type !== 'event_trigger' ) { |
| 597 |
return $fields; |
| 598 |
} |
| 599 |
|
| 600 |
$log = ct_get_object( $log_id ); |
| 601 |
$trigger = $log->trigger_type; |
| 602 |
|
| 603 |
switch( $trigger ) { |
| 604 |
// Complete content |
| 605 |
case 'gamipress_h5p_complete_content': |
| 606 |
case 'gamipress_h5p_complete_specific_content': |
| 607 |
case 'gamipress_h5p_complete_specific_content_type': |
| 608 |
case 'gamipress_h5p_complete_content_tag': |
| 609 |
// At 100% |
| 610 |
case 'gamipress_h5p_max_complete_content': |
| 611 |
case 'gamipress_h5p_max_complete_specific_content': |
| 612 |
case 'gamipress_h5p_max_complete_specific_content_type': |
| 613 |
case 'gamipress_h5p_max_complete_content_tag': |
| 614 |
|
| 615 |
$fields[] = array( |
| 616 |
'name' => __( 'Result', 'gamipress' ), |
| 617 |
'desc' => __( 'Result attached to this log.', 'gamipress' ), |
| 618 |
'id' => $prefix . 'result_id', |
| 619 |
'type' => 'text', |
| 620 |
); |
| 621 |
|
| 622 |
$fields[] = array( |
| 623 |
'name' => __( 'Content', 'gamipress' ), |
| 624 |
'desc' => __( 'Content attached to this log.', 'gamipress' ), |
| 625 |
'id' => $prefix . 'content_id', |
| 626 |
'type' => 'text', |
| 627 |
); |
| 628 |
|
| 629 |
// Get active libraries |
| 630 |
$options = array(); |
| 631 |
$content_types = $wpdb->get_results( |
| 632 |
"SELECT l.name, l.title |
| 633 |
FROM {$wpdb->prefix}h5p_libraries AS l |
| 634 |
WHERE l.runnable = 1" |
| 635 |
); |
| 636 |
|
| 637 |
foreach( $content_types as $content_type ) { |
| 638 |
$options[$content_type->name] = $content_type->title; |
| 639 |
} |
| 640 |
|
| 641 |
$fields[] = array( |
| 642 |
'name' => __( 'Content Type', 'gamipress' ), |
| 643 |
'desc' => __( 'Content type attached to this log.', 'gamipress' ), |
| 644 |
'id' => $prefix . 'content_type', |
| 645 |
'type' => 'select', |
| 646 |
'options' => $options |
| 647 |
); |
| 648 |
|
| 649 |
break; |
| 650 |
// Min score |
| 651 |
case 'gamipress_h5p_complete_content_min_score': |
| 652 |
case 'gamipress_h5p_complete_specific_content_min_score': |
| 653 |
case 'gamipress_h5p_complete_specific_content_type_min_score': |
| 654 |
case 'gamipress_h5p_complete_content_min_score_tag': |
| 655 |
// Max score |
| 656 |
case 'gamipress_h5p_complete_content_max_score': |
| 657 |
case 'gamipress_h5p_complete_specific_content_max_score': |
| 658 |
case 'gamipress_h5p_complete_specific_content_type_max_score': |
| 659 |
case 'gamipress_h5p_complete_content_max_score_tag': |
| 660 |
// Between score |
| 661 |
case 'gamipress_h5p_complete_content_between_score': |
| 662 |
case 'gamipress_h5p_complete_specific_content_between_score': |
| 663 |
case 'gamipress_h5p_complete_specific_content_type_between_score': |
| 664 |
case 'gamipress_h5p_complete_content_between_score_tag': |
| 665 |
// Min percentage |
| 666 |
case 'gamipress_h5p_complete_content_min_percentage': |
| 667 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 668 |
case 'gamipress_h5p_complete_specific_content_type_min_percentage': |
| 669 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 670 |
// Max percentage |
| 671 |
case 'gamipress_h5p_complete_content_max_percentage': |
| 672 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 673 |
case 'gamipress_h5p_complete_specific_content_type_max_percentage': |
| 674 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 675 |
// Between percentage |
| 676 |
case 'gamipress_h5p_complete_content_between_percentage': |
| 677 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 678 |
case 'gamipress_h5p_complete_specific_content_type_between_percentage': |
| 679 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 680 |
|
| 681 |
$fields[] = array( |
| 682 |
'name' => __( 'Result', 'gamipress' ), |
| 683 |
'desc' => __( 'Result attached to this log.', 'gamipress' ), |
| 684 |
'id' => $prefix . 'result_id', |
| 685 |
'type' => 'text', |
| 686 |
); |
| 687 |
|
| 688 |
$fields[] = array( |
| 689 |
'name' => __( 'Content', 'gamipress' ), |
| 690 |
'desc' => __( 'Content attached to this log.', 'gamipress' ), |
| 691 |
'id' => $prefix . 'content_id', |
| 692 |
'type' => 'text', |
| 693 |
); |
| 694 |
|
| 695 |
// Get active libraries |
| 696 |
$options = array(); |
| 697 |
$content_types = $wpdb->get_results( |
| 698 |
"SELECT l.name, l.title |
| 699 |
FROM {$wpdb->prefix}h5p_libraries AS l |
| 700 |
WHERE l.runnable = 1" |
| 701 |
); |
| 702 |
|
| 703 |
foreach( $content_types as $content_type ) { |
| 704 |
$options[$content_type->name] = $content_type->title; |
| 705 |
} |
| 706 |
|
| 707 |
$fields[] = array( |
| 708 |
'name' => __( 'Content Type', 'gamipress' ), |
| 709 |
'desc' => __( 'Content type attached to this log.', 'gamipress' ), |
| 710 |
'id' => $prefix . 'content_type', |
| 711 |
'type' => 'select', |
| 712 |
'options' => $options |
| 713 |
); |
| 714 |
|
| 715 |
$fields[] = array( |
| 716 |
'name' => __( 'Score', 'gamipress' ), |
| 717 |
'desc' => __( 'Score attached to this log.', 'gamipress' ), |
| 718 |
'id' => $prefix . 'score', |
| 719 |
'type' => 'text', |
| 720 |
); |
| 721 |
|
| 722 |
break; |
| 723 |
|
| 724 |
} |
| 725 |
|
| 726 |
// Percentage field |
| 727 |
switch( $trigger ) { |
| 728 |
// Min percentage |
| 729 |
case 'gamipress_h5p_complete_content_min_percentage': |
| 730 |
case 'gamipress_h5p_complete_specific_content_min_percentage': |
| 731 |
case 'gamipress_h5p_complete_specific_content_type_min_percentage': |
| 732 |
case 'gamipress_h5p_complete_content_min_percentage_tag': |
| 733 |
// Max percentage |
| 734 |
case 'gamipress_h5p_complete_content_max_percentage': |
| 735 |
case 'gamipress_h5p_complete_specific_content_max_percentage': |
| 736 |
case 'gamipress_h5p_complete_specific_content_type_max_percentage': |
| 737 |
case 'gamipress_h5p_complete_content_max_percentage_tag': |
| 738 |
// Between percentage |
| 739 |
case 'gamipress_h5p_complete_content_between_percentage': |
| 740 |
case 'gamipress_h5p_complete_specific_content_between_percentage': |
| 741 |
case 'gamipress_h5p_complete_specific_content_type_between_percentage': |
| 742 |
case 'gamipress_h5p_complete_content_between_percentage_tag': |
| 743 |
$fields[] = array( |
| 744 |
'name' => __( 'Percentage Score', 'gamipress' ), |
| 745 |
'desc' => __( 'Percentage score attached to this log.', 'gamipress' ), |
| 746 |
'id' => $prefix . 'percentage', |
| 747 |
'type' => 'text', |
| 748 |
); |
| 749 |
|
| 750 |
break; |
| 751 |
} |
| 752 |
|
| 753 |
return $fields; |
| 754 |
|
| 755 |
} |
| 756 |
add_filter( 'gamipress_log_extra_data_fields', 'gamipress_h5p_log_extra_data_fields', 10, 3 ); |