pterotype/inc/likes.php

71 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace likes;
require_once plugin_dir_path( __FILE__ ) . '/collections.php';
2018-09-24 02:22:30 +00:00
function create_local_actor_like( $actor_id, $object_id ) {
2018-09-04 02:10:36 +00:00
global $wpdb;
return $wpdb->insert(
'pterotype_actor_likes',
array( 'actor_id' => $actor_id, 'object_id' => $object_id ),
'%d'
2018-09-04 02:10:36 +00:00
);
}
2018-09-26 03:46:31 +00:00
function delete_local_actor_like( $actor_id, $object_id ) {
global $wpdb;
return $wpdb->delete(
'pterotype_actor_likes',
array( 'actor_id' => $actor_id, 'object_id' => $object_id ),
'%d'
);
}
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'
);
}
2018-09-26 03:46:31 +00:00
function delete_object_like( $object_id, $like_id ) {
global $wpdb;
return $wpdb->delete(
'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;
}
?>