-- ------------------------------------------
-- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1455
+-- DB_UPDATE_VERSION 1456
-- ------------------------------------------
FOREIGN KEY (`tid`) REFERENCES `tag` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='post relation to categories';
+--
+-- TABLE post-collection
+--
+CREATE TABLE IF NOT EXISTS `post-collection` (
+ `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
+ `type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
+ PRIMARY KEY(`uri-id`,`type`),
+ INDEX `type` (`type`),
+ FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Collection of posts';
+
--
-- TABLE post-content
--
`post-thread-user`.`origin` AS `parent-origin`,
`post-thread-user`.`mention` AS `mention`,
`post-user`.`global` AS `global`,
+ EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`) AS `featured`,
`post-user`.`network` AS `network`,
`post-user`.`vid` AS `vid`,
`post-user`.`psid` AS `psid`,
`post-thread-user`.`origin` AS `origin`,
`post-thread-user`.`mention` AS `mention`,
`post-user`.`global` AS `global`,
+ EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`) AS `featured`,
`post-thread-user`.`network` AS `network`,
`post-user`.`vid` AS `vid`,
`post-thread-user`.`psid` AS `psid`,
`post`.`visible` AS `visible`,
`post`.`deleted` AS `deleted`,
`post`.`global` AS `global`,
+ EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`) AS `featured`,
`post`.`network` AS `network`,
`post`.`vid` AS `vid`,
IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
`post`.`visible` AS `visible`,
`post`.`deleted` AS `deleted`,
`post`.`global` AS `global`,
+ EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`) AS `featured`,
`post-thread`.`network` AS `network`,
`post`.`vid` AS `vid`,
IF (`post`.`vid` IS NULL, '', `verb`.`name`) AS `verb`,
| [photo](help/database/db_photo) | photo storage |
| [post](help/database/db_post) | Structure for all posts |
| [post-category](help/database/db_post-category) | post relation to categories |
+| [post-collection](help/database/db_post-collection) | Collection of posts |
| [post-content](help/database/db_post-content) | Content for all posts |
| [post-delivery-data](help/database/db_post-delivery-data) | Delivery data for items |
| [post-link](help/database/db_post-link) | Post related external links |
--- /dev/null
+Table post-collection
+===========
+
+Collection of posts
+
+Fields
+------
+
+| Field | Description | Type | Null | Key | Default | Extra |
+| ------ | --------------------------------------------------------- | ---------------- | ---- | --- | ------- | ----- |
+| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned | NO | PRI | NULL | |
+| type | | tinyint unsigned | NO | PRI | 0 | |
+
+Indexes
+------------
+
+| Name | Fields |
+| ------- | ------------ |
+| PRIMARY | uri-id, type |
+| type | type |
+
+Foreign Keys
+------------
+
+| Field | Target Table | Target Field |
+|-------|--------------|--------------|
+| uri-id | [item-uri](help/database/db_item-uri) | id |
+
+Return to [database documentation](help/database)
use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD;
use Friendica\Util\Network;
-use Friendica\Util\Strings;
class APContact
{
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Model\Post;
+
+use Friendica\Database\DBA;
+use \BadMethodCallException;
+use Friendica\Database\Database;
+
+class Collection
+{
+ const FEATURED = 0;
+
+ /**
+ * Add a post to a collection
+ *
+ * @param integer $uri_id
+ * @param integer $type
+ */
+ public static function add(int $uri_id, int $type)
+ {
+ if (empty($uri_id)) {
+ throw new BadMethodCallException('Empty URI_id');
+ }
+
+ DBA::insert('post-collection', ['uri-id' => $uri_id, 'type' => $type], Database::INSERT_IGNORE);
+ }
+
+ /**
+ * Remove a post from a collection
+ *
+ * @param integer $uri_id
+ * @param integer $type
+ */
+ public static function remove(int $uri_id, int $type)
+ {
+ if (empty($uri_id)) {
+ throw new BadMethodCallException('Empty URI_id');
+ }
+
+ DBA::delete('post-collection', ['uri-id' => $uri_id, 'type' => $type]);
+ }
+}
Logger::debug('Add post to featured collection', ['uri-id' => $uriid]);
- // @todo Add functionality
+ Post\Collection::add($uriid, Post\Collection::FEATURED);
}
/**
Logger::debug('Remove post from featured collection', ['uri-id' => $uriid]);
- // @todo Add functionality
+ Post\Collection::remove($uriid, Post\Collection::FEATURED);
}
/**
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1455);
+ define('DB_UPDATE_VERSION', 1456);
}
return [
"uid" => ["uid"],
]
],
+ "post-collection" => [
+ "comment" => "Collection of posts",
+ "fields" => [
+ "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+ "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "comment" => ""],
+ ],
+ "indexes" => [
+ "PRIMARY" => ["uri-id", "type"],
+ "type" => ["type"],
+ ]
+ ],
"post-content" => [
"comment" => "Content for all posts",
"fields" => [
"parent-origin" => ["post-thread-user", "origin"],
"mention" => ["post-thread-user", "mention"],
"global" => ["post-user", "global"],
+ "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-user`.`uri-id`)",
"network" => ["post-user", "network"],
"vid" => ["post-user", "vid"],
"psid" => ["post-user", "psid"],
"origin" => ["post-thread-user", "origin"],
"mention" => ["post-thread-user", "mention"],
"global" => ["post-user", "global"],
+ "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread-user`.`uri-id`)",
"network" => ["post-thread-user", "network"],
"vid" => ["post-user", "vid"],
"psid" => ["post-thread-user", "psid"],
"visible" => ["post", "visible"],
"deleted" => ["post", "deleted"],
"global" => ["post", "global"],
+ "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post`.`uri-id`)",
"network" => ["post", "network"],
"vid" => ["post", "vid"],
"verb" => "IF (`post`.`vid` IS NULL, '', `verb`.`name`)",
"visible" => ["post", "visible"],
"deleted" => ["post", "deleted"],
"global" => ["post", "global"],
+ "featured" => "EXISTS(SELECT `type` FROM `post-collection` WHERE `type` = 0 AND `uri-id` = `post-thread`.`uri-id`)",
"network" => ["post-thread", "network"],
"vid" => ["post", "vid"],
"verb" => "IF (`post`.`vid` IS NULL, '', `verb`.`name`)",