| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Depicter\Database\Entity; |
| 3 | 3 | |
| 4 | -use Averta\WordPress\Database\Entity\Model; | |
| 5 | 4 | use Averta\WordPress\Utility\Sanitize; |
| 6 | 5 | |
| 7 | 6 | class Document extends Model |
| 8 | 7 | { |
| @@ -48,11 +47,11 @@ | ||
| 48 | 47 | |
| 49 | 48 | protected $cast = []; |
| 50 | 49 | |
| 51 | 50 | protected $format = [ |
| 52 | - 'name' => 'sanitizeName', | |
| 53 | - 'slug' => 'sanitizeSlug', | |
| 54 | - 'modified_at' => 'currentDateTime' | |
| 51 | + 'name' => 'static::sanitizeName', | |
| 52 | + 'slug' => 'static::sanitizeSlug', | |
| 53 | + 'modified_at' => 'static::currentDateTime' | |
| 55 | 54 | ]; |
| 56 | 55 | |
| 57 | 56 | /** |
| 58 | 57 | * Determines what fields should be updated automatically. |
| @@ -63,13 +62,14 @@ | ||
| 63 | 62 | 'modified_at' => '' |
| 64 | 63 | ]; |
| 65 | 64 | |
| 66 | 65 | |
| 67 | - public function sanitizeName( $value ) { | |
| 66 | + | |
| 67 | + public static function sanitizeName( $value ) { | |
| 68 | 68 | return Sanitize::plaintext( $value ); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function sanitizeSlug( $value ) { | |
| 71 | + public static function sanitizeSlug( $value ) { | |
| 72 | 72 | $value = $value ?? 'document 1'; |
| 73 | 73 | return Sanitize::slug( $value ); |
| 74 | 74 | } |
| 75 | 75 | |
| @@ -188,20 +188,8 @@ | ||
| 188 | 188 | return $this->where('status', $type); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | - * Query parent or revision documents | |
| 193 | - * | |
| 194 | - * @param string $revisionOrParent Get revision or parent documents only | |
| 195 | - * | |
| 196 | - * @return $this | |
| 197 | - */ | |
| 198 | - public function parents( $revisionOrParent = 0 ) | |
| 199 | - { | |
| 200 | - return $this->where('parent', $revisionOrParent ); | |
| 201 | - } | |
| 202 | - | |
| 203 | - /** | |
| 204 | 192 | * Get public properties for API |
| 205 | 193 | * |
| 206 | 194 | * @return array |
| 207 | 195 | * @throws \Exception |
| @@ -241,42 +229,8 @@ | ||
| 241 | 229 | * @return mixed |
| 242 | 230 | * @throws \Exception |
| 243 | 231 | */ |
| 244 | 232 | public function getLastPublishedAt(){ |
| 245 | - return \Depicter::documentRepository()->getLastPublishedAt( $this->toArray() ); | |
| 233 | + return \Depicter::documentRepository()->getLastPublishedAt( $this->toArray() ); | |
| 246 | 234 | } |
| 247 | 235 | |
| 248 | - /** | |
| 249 | - * Joins meta table and reselects default or passed columns | |
| 250 | - * | |
| 251 | - * @return Document | |
| 252 | - */ | |
| 253 | - public function withMeta() { | |
| 254 | - global $wpdb; | |
| 255 | - return $this->join( | |
| 256 | - $wpdb->prefix . 'depicter_meta', | |
| 257 | - $wpdb->prefix . 'depicter_meta.relation_id', | |
| 258 | - $wpdb->prefix . $this->resource . '.' . $this->idColumn | |
| 259 | - )->where($wpdb->prefix . 'depicter_meta.relation', 'document' ); | |
| 260 | - } | |
| 261 | - | |
| 262 | - /** | |
| 263 | - * Filters meta key and value | |
| 264 | - * | |
| 265 | - * @throws Document | |
| 266 | - */ | |
| 267 | - public function whereMeta( $metaKey, $metaValue ){ | |
| 268 | - global $wpdb; | |
| 269 | - return $this | |
| 270 | - ->where($wpdb->prefix . 'depicter_meta.meta_key', $metaKey ) | |
| 271 | - ->where($wpdb->prefix . 'depicter_meta.meta_value', $metaValue ); | |
| 272 | - } | |
| 273 | - | |
| 274 | - /** | |
| 275 | - * Retrieves related meta field models | |
| 276 | - * | |
| 277 | - * @return Meta|\TypeRocket\Models\Model|null | |
| 278 | - */ | |
| 279 | - public function meta(){ | |
| 280 | - return $this->hasMany(Meta::class, 'relation_id', $this->idColumn ); | |
| 281 | - } | |
| 282 | 236 | } |