LLMS_User_Postmeta
LLMS_User_Postmeta model class
Source Source
File: includes/models/model.llms.user.postmeta.php
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | class LLMS_User_Postmeta extends LLMS_Abstract_Database_Store { /** * Created date column key. * * Disabled for this record type. * * @var null */ protected $date_created = null; /** * Updated date column key. * * @var string */ protected $date_updated = 'updated_date' ; /** * Array of table column name => format. * * @var array */ protected $columns = array ( 'user_id' => '%d' , 'post_id' => '%d' , 'meta_key' => '%s' , 'meta_value' => '%s' , 'updated_date' => '%s' , ); /** * Primary Key column name => format. * * @var array */ protected $primary_key = array ( 'meta_id' => '%d' , ); /** * Database Table Name. * * @var string */ protected $table = 'user_postmeta' ; /** * The record type. * * @var string */ protected $type = 'user_postmeta' ; /** * Constructor * * @since 3.15.0 * @since 3.21.0 Unknown. * * @param mixed $item Meta_id of a user postmeta item or an object with at least an "id". * @param boolean $hydrate If true, hydrates the object on instantiation (if an ID was found via $item). */ public function __construct( $item = null, $hydrate = true ) { if ( is_numeric ( $item ) ) { $this ->id = $item ; } elseif ( is_object ( $item ) && isset( $item ->id ) ) { $this ->id = $item ->id; } parent::__construct(); if ( $this ->id && $hydrate ) { $this ->hydrate(); } } /** * Get a string used to describe the postmeta item. * * @since 3.15.0 * * @param string $context Display context either "course" or "student". * @return string */ public function get_description( $context = 'course' ) { $key = $this ->get( 'meta_key' ); $student = $this ->get_student(); $name = $student ? $student ->get( 'display_name' ) : __( '[Deleted]' , 'lifterlms' ); $post = llms_get_post( $this ->get( 'post_id' ) ); $label = is_a ( $post , 'LLMS_Post_Model' ) ? strtolower ( $post ->get_post_type_label() ) : __( 'quiz' , 'lifterlms' ); $post_name = ( 'course' === $context ) ? $label : sprintf( '%1$s "%2$s"' , $label , get_the_title( $this ->get( 'post_id' ) ) ); $string = '' ; switch ( $key ) { case '_achievement_earned' : $string = sprintf( __( '%1$s earned the achievement "%2$s"' , 'lifterlms' ), $name , get_the_title( $this ->get( 'meta_value' ) ) ); break ; case '_certificate_earned' : $string = sprintf( __( '%1$s earned the certificate "%2$s"' , 'lifterlms' ), $name , get_the_title( $this ->get( 'meta_value' ) ) ); break ; case '_email_sent' : $string = sprintf( __( 'Email "%1$s" was sent to %2$s' , 'lifterlms' ), get_the_title( $this ->get( 'meta_value' ) ), $name ); break ; case '_enrollment_trigger' : $string = sprintf( __( '%1$s purchased the %2$s' , 'lifterlms' ), $name , $post_name ); break ; case '_status' : if ( 'enrolled' === $this ->get( 'meta_value' ) ) { $string = sprintf( __( '%1$s enrolled into the %2$s' , 'lifterlms' ), $name , $post_name ); } else { $string = sprintf( __( '%1$s unenrolled from the %2$s' , 'lifterlms' ), $name , $post_name ); } break ; case '_is_complete' : $string = sprintf( __( '%1$s completed the %2$s' , 'lifterlms' ), $name , $post_name ); break ; } // End switch(). return $string ; } /** * Retrieve a link for the item on the admin panel * * @since 3.15.0 * @since 6.0.0 Don't use deprecated achievement and certificate meta data. * Combined redundant cases into a single case. * Fixed return value. * * @param string $context Display context either "course" or "student". * @return string */ public function get_link( $context = 'course' ) { $url = '' ; switch ( $this ->get( 'meta_key' ) ) { case '_achievement_earned' : case '_certificate_earned' : case '_email_sent' : $url = get_edit_post_link( $this ->get( 'meta_value' ) ); break ; case '_enrollment_trigger' : $url = get_edit_post_link( str_replace ( 'order_' , '' , $this ->get( 'meta_value' ) ) ); break ; default : $student = $this ->get_student(); if ( ! $student ) { return '' ; } $course = false; if ( 'course' === get_post_type( $this ->get( 'post_id' ) ) ) { $course = llms_get_post( $this ->get( 'post_id' ) ); } else { $course = llms_get_post_parent_course( $this ->get( 'post_id' ) ); } if ( $course ) { $url = LLMS_Admin_Reporting::get_current_tab_url( array ( 'course_id' => $course ->get( 'id' ), 'stab' => 'courses' , 'student_id' => $student ->get_id(), 'tab' => 'students' , ) ); } } return $url ; } /** * Retrieve a student obj for the meta item. * * @since 3.15.0 * * @return LLMS_Student|false */ public function get_student() { return llms_get_student( $this ->get( 'user_id' ) ); } } |
Expand full source code Collapse full source code View on GitHub
Methods Methods
- __construct — Constructor
- get_description — Get a string used to describe the postmeta item.
- get_link — Retrieve a link for the item on the admin panel
- get_student — Retrieve a student obj for the meta item.
Changelog Changelog
Version | Description |
---|---|
4.3.0 | Added $type property declaration. |
3.15.0 | Introduced. |