Skip to content

ActivityPub: Sprint 2 #3216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Idno/Common/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Idno\Core\Idno;
use Idno\Core\Webmention;
use Idno\Entities\Annotation;
use Idno\Entities\User;

abstract class Entity extends Component implements EntityInterface
Expand Down Expand Up @@ -2670,6 +2671,12 @@ function getAnnotationSubtype($uuid)
*/
function getAnnotation($uuid)
{
// Prioritize Annotation methods
$annotation = Annotation::getByUUID($uuid);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding the internals here allow us to keep using the same getAnnotation() calls used in templates.

if (!$annotation) {
return $annotation;
}

if (!empty($this->annotations) && is_array($this->annotations)) {
foreach ($this->annotations as $subtype => $array) {
if (isset($array[$uuid])) {
Expand Down
98 changes: 98 additions & 0 deletions Idno/Entities/Annotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

/**
* Annotation class
*
* This extends the Entity class to be an
* object in the idno system
*
* @package idno
* @subpackage core
*/

namespace Idno\Entities {

use Idno\Core\Idno;
use Idno\Common\Entity;
use Idno\Common\EntityInterface;
use Idno\Entities\User;

abstract class Annotation extends Entity implements EntityInterface
{
// Which collection should this be stored in?
private $collection = 'annotations';
static $retrieve_collection = 'annotations';


/**
* Retrieve a single record by its UUID
* @param string $uuid
* @param bool $cached Retrieve a cached version if one exists.
* @return bool|Entity
*/

static function getByUUID($uuid, $cached = true)
{
if (!empty(self::$entity_cache[$uuid]) && $cached) return self::$entity_cache[$uuid];
$return = static::getOneFromAll(array('uuid' => $uuid));
if ($return instanceof Entity) self::$entity_cache[$uuid] = $return;
return $return;
}

/**
* Retrieve a single record with certain characteristics, using
* the database getObjects call.
*
* @param array $search List of filter terms (default: none)
* @param array $fields List of fields to return (default: all)
* @return Entity
*/

static function getOneFromAll($search = array(), $fields = array())
{
if ($records = static::getFromAll($search, $fields, 1)) {
foreach ($records as $record)
return $record;
}
return false;
}

/**
* Simple method to get objects of ANY class in reverse
* chronological order, using the database getObjects call.
*
* @param array $search List of filter terms (default: none)
* @param array $fields List of fields to return (default: all)
* @param int $limit Number of items to return (default: 10)
* @param int $offset Number of items to skip (default: 0
* @return array
*/
static function getFromAll($search = array(), $fields = array(), $limit = 10, $offset = 0)
{
$result = static::getFromX(get_called_class(), $search, $fields, $limit, $offset);

return $result;
}

/**
* Simple method to get objects of a specified class or classes
* in reverse chronological order, using the database getObjects call.
*
* @param string|array $class Class name(s) to check in (blank string, null or false for all)
* @param array $search List of filter terms (default: none)
* @param array $fields List of fields to return (default: all)
* @param int $limit Number of items to return (default: 10)
* @param int $offset Number of items to skip (default: 0)
* @param array $readGroups Which ACL groups should we check? (default: everything the user can see)
* @return array
*/
static function getFromX($class, $search = array(), $fields = array(), $limit = 10, $offset = 0, $readGroups = [])
{
$result = \Idno\Core\Idno::site()->db()->getObject($search['uuid'], static::$retrieve_collection);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result here is a different object than was previously received, notably missing are the owner_name, owner_url, owner_image.

I think it would make sense to use JOINs here to recreate the expected structure.

if (is_array($result)) $result = array_filter($result);

return $result;
}
}

}