2018-09-03 16:47:08 +00:00
|
|
|
<?php
|
|
|
|
namespace likes;
|
|
|
|
|
2018-09-24 12:39:54 +00:00
|
|
|
require_once plugin_dir_path( __FILE__ ) . '/collections.php';
|
2018-09-24 02:22:30 +00:00
|
|
|
|
2018-09-24 12:39:54 +00:00
|
|
|
function create_local_actor_like( $actor_id, $object_id ) {
|
2018-09-04 02:10:36 +00:00
|
|
|
global $wpdb;
|
|
|
|
return $wpdb->insert(
|
2018-09-24 12:39:54 +00:00
|
|
|
'pterotype_actor_likes',
|
|
|
|
array( 'actor_id' => $actor_id, 'object_id' => $object_id ),
|
|
|
|
'%d'
|
2018-09-04 02:10:36 +00:00
|
|
|
);
|
|
|
|
}
|
2018-09-24 12:39:54 +00:00
|
|
|
|
|
|
|
function record_like ( $object_id, $like_id ) {
|
|
|
|
global $wpdb;
|
|
|
|
return $wpdb->insert(
|
|
|
|
'pterotype_object_likes',
|
|
|
|
array(
|
|
|
|
'object_id' => $object_id,
|
|
|
|
'like_id' => $like_id
|
|
|
|
),
|
|
|
|
'%d'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_likes_collection( $object_id ) {
|
|
|
|
global $wpdb;
|
|
|
|
$likes = $wpdb->get_results(
|
|
|
|
$wpdb->prepare(
|
|
|
|
'
|
|
|
|
SELECT activity FROM pterotype_object_likes
|
|
|
|
JOIN pterotype_activities ON like_id = pterotype_activities.id
|
|
|
|
WHERE object_id = %d
|
|
|
|
',
|
|
|
|
$object_id
|
|
|
|
),
|
|
|
|
ARRAY_A
|
|
|
|
);
|
|
|
|
if ( !$likes ) {
|
|
|
|
$likes = array();
|
|
|
|
}
|
|
|
|
$collection = \collections\make_ordered_collection( $likes );
|
|
|
|
$collection['id'] = get_rest_url( null, sprintf(
|
|
|
|
'/pterotype/v1/object/%d/likes', $object_id
|
|
|
|
) );
|
|
|
|
return $collection;
|
|
|
|
}
|
2018-09-03 16:47:08 +00:00
|
|
|
?>
|