| 1 |
<?php |
| 2 |
|
| 3 |
class WP_Stream_Record { |
| 4 |
|
| 5 |
public $ID; |
| 6 |
public $site_id; |
| 7 |
public $blog_id; |
| 8 |
public $object_id; |
| 9 |
public $author; |
| 10 |
public $author_role; |
| 11 |
public $summary; |
| 12 |
public $visibility; |
| 13 |
public $type; |
| 14 |
public $connector; |
| 15 |
public $context; |
| 16 |
public $action; |
| 17 |
public $created; |
| 18 |
public $ip; |
| 19 |
|
| 20 |
public $stream_meta; |
| 21 |
|
| 22 |
// Deprecated |
| 23 |
public $contexts; |
| 24 |
|
| 25 |
public function __construct( $id = null ) { |
| 26 |
if ( $id ) { |
| 27 |
$this->load( $id ); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function load( $id ) { |
| 32 |
$records = WP_Stream::$db->query( array( 'id' => $id ) ); |
| 33 |
|
| 34 |
if ( $record ) { |
| 35 |
$this->populate( $record ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
public function save() { |
| 40 |
if ( ! $this->validate() ) { |
| 41 |
return new WP_Error( 'validation-error', __( 'Could not validate record data.', 'stream' ) ); |
| 42 |
} |
| 43 |
|
| 44 |
return WP_Stream::$db->store( (array) $this ); |
| 45 |
} |
| 46 |
|
| 47 |
public function populate( array $raw ) { |
| 48 |
$keys = get_class_vars( __CLASS__ ); |
| 49 |
$data = array_intersect_key( $raw, $keys ); |
| 50 |
if ( ! empty( $data['contexts'] ) ) { |
| 51 |
$data['context'] = key( $data['contexts'] ); |
| 52 |
$data['action'] = current( $data['contexts'] ); |
| 53 |
} |
| 54 |
foreach ( $data as $key => $val ) { |
| 55 |
$this->{$key} = $val; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public function validate() { |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
public static function instance( array $data ) { |
| 64 |
$object = new self(); |
| 65 |
$object->populate( $data ); |
| 66 |
return $object; |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|