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;
9 * Abstract implementation for database user content provider.
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
17 abstract class AbstractDatabaseUserContentProvider implements IUserContentProvider {
19 * Returns the database object class for the object.
23 abstract public static function getDatabaseObjectClass();
26 * Returns the database object list class for the object.
30 public static function getDatabaseObjectListClass() {
31 return static::getDatabaseObjectClass() . 'List';
35 * Returns the database object action class for the object.
39 public static function getDatabaseObjectActionClass() {
40 return static::getDatabaseObjectClass() . 'Action';
46 public function getContentListForUser(User $user) {
47 if ($user->userID == 0) {
48 throw new \RuntimeException('Removing content for guests is not allowed.');
51 $className = static::getDatabaseObjectListClass();
53 if (!is_subclass_of($className, DatabaseObjectList::class)) {
54 throw new ImplementationException($className, DatabaseObjectList::class);
57 /** @var DatabaseObjectList $databaseObjectList */
58 $databaseObjectList = new $className;
59 $tableAlias = call_user_func([static::getDatabaseObjectClass(), 'getDatabaseTableAlias']);
60 $databaseObjectList->getConditionBuilder()->add($tableAlias . '.userID = ?', [$user->userID]);
62 return $databaseObjectList;
68 public function deleteContent(array $objectIDs) {
69 $className = self::getDatabaseObjectActionClass();
71 if (!is_subclass_of($className, AbstractDatabaseObjectAction::class)) {
72 throw new ImplementationException($className, AbstractDatabaseObjectAction::class);
75 /** @var AbstractDatabaseObjectAction $objectAction */
76 $objectAction = new $className($objectIDs, 'delete');
77 $objectAction->executeAction();