52ff4a328812028ad590c7b31cdf00a15d61422f
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\content\provider;
3 use wcf\data\AbstractDatabaseObjectAction;
4 use wcf\data\DatabaseObjectList;
5 use wcf\data\user\User;
6 use wcf\system\exception\ImplementationException;
7
8 /**
9 * Abstract implementation for database user content provider.
10 *
11 * @author Joshua Ruesweg
12 * @copyright 2001-2018 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\User\Content\Provider
15 * @since 3.2
16 */
17 abstract class AbstractDatabaseUserContentProvider implements IUserContentProvider {
18 /**
19 * Returns the database object class for the object.
20 *
21 * @return string
22 */
23 abstract public static function getDatabaseObjectClass();
24
25 /**
26 * Returns the database object list class for the object.
27 *
28 * @return string
29 */
30 public static function getDatabaseObjectListClass() {
31 return static::getDatabaseObjectClass() . 'List';
32 }
33
34 /**
35 * Returns the database object action class for the object.
36 *
37 * @return string
38 */
39 public static function getDatabaseObjectActionClass() {
40 return static::getDatabaseObjectClass() . 'Action';
41 }
42
43 /**
44 * @inheritDoc
45 */
46 public function getContentListForUser(User $user) {
47 if ($user->userID == 0) {
48 throw new \RuntimeException('Removing content for guests is not allowed.');
49 }
50
51 $className = static::getDatabaseObjectListClass();
52
53 if (!is_subclass_of($className, DatabaseObjectList::class)) {
54 throw new ImplementationException($className, DatabaseObjectList::class);
55 }
56
57 /** @var DatabaseObjectList $databaseObjectList */
58 $databaseObjectList = new $className;
59 $tableAlias = call_user_func([static::getDatabaseObjectClass(), 'getDatabaseTableAlias']);
60 $databaseObjectList->getConditionBuilder()->add($tableAlias . '.userID = ?', [$user->userID]);
61
62 return $databaseObjectList;
63 }
64
65 /**
66 * @inheritDoc
67 */
68 public function deleteContent(array $objectIDs) {
69 $className = self::getDatabaseObjectActionClass();
70
71 if (!is_subclass_of($className, AbstractDatabaseObjectAction::class)) {
72 throw new ImplementationException($className, AbstractDatabaseObjectAction::class);
73 }
74
75 /** @var AbstractDatabaseObjectAction $objectAction */
76 $objectAction = new $className($objectIDs, 'delete');
77 $objectAction->executeAction();
78 }
79 }