2020-08-23 15:50:11 +00:00
|
|
|
<?php
|
2020-09-21 12:25:50 +00:00
|
|
|
/*
|
2024-02-02 18:27:50 +00:00
|
|
|
* Copyright (c) 2020-2024. The Nextcloud Bookmarks contributors.
|
2020-09-21 12:25:50 +00:00
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
|
|
|
*/
|
2020-08-23 15:50:11 +00:00
|
|
|
|
|
|
|
namespace OCA\Bookmarks\Db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Bookmark
|
|
|
|
*
|
|
|
|
* @package OCA\Bookmarks\Db
|
|
|
|
* @method getTags
|
|
|
|
*/
|
2020-09-01 12:28:26 +00:00
|
|
|
class BookmarkWithTagsAndParent extends Bookmark {
|
2020-08-23 15:50:11 +00:00
|
|
|
protected $tags;
|
2020-09-01 12:28:26 +00:00
|
|
|
protected $folders;
|
2020-08-23 15:50:11 +00:00
|
|
|
|
2021-02-09 08:05:40 +00:00
|
|
|
public static $columns = ['id', 'url', 'title', 'description', 'lastmodified', 'added', 'clickcount', 'last_preview', 'available', 'archived_file', 'user_id', 'tags', 'folders', 'text_content', 'html_content'];
|
|
|
|
public static $fields = ['id', 'url', 'title', 'description', 'lastmodified', 'added', 'clickcount', 'lastPreview', 'available', 'archivedFile', 'userId', 'tags', 'folders', 'textContent', 'htmlContent'];
|
2020-08-23 15:50:11 +00:00
|
|
|
|
|
|
|
public function toArray(): array {
|
|
|
|
$array = [];
|
|
|
|
foreach (self::$fields as $field) {
|
2024-01-03 12:56:52 +00:00
|
|
|
if ($field === 'tags') {
|
|
|
|
if (is_string($this->{$field})) {
|
|
|
|
$array[$field] = $this->{$field} === '' ? [] : array_values(array_unique(explode(',', $this->{$field})));
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-23 15:50:11 +00:00
|
|
|
}
|
2020-09-01 12:28:26 +00:00
|
|
|
if ($field === 'folders') {
|
2024-01-03 15:52:09 +00:00
|
|
|
if ($this->{$field} === '') {
|
2020-09-01 12:28:26 +00:00
|
|
|
$array[$field] = [];
|
|
|
|
} else {
|
2020-11-03 16:22:59 +00:00
|
|
|
$array[$field] = array_values(array_unique(array_map(static function ($id) {
|
2020-09-01 12:28:26 +00:00
|
|
|
return (int) $id;
|
2022-02-15 17:14:49 +00:00
|
|
|
}, explode(',', $this->{$field}))));
|
2020-09-01 12:28:26 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-16 18:19:22 +00:00
|
|
|
if ($field === 'url') {
|
|
|
|
if (!preg_match('/^javascript:/i', $this->url)) {
|
|
|
|
$array['url'] = $this->url;
|
|
|
|
} else {
|
|
|
|
$array['url'] = '';
|
|
|
|
}
|
|
|
|
$array['target'] = $this->url;
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-23 15:50:11 +00:00
|
|
|
$array[$field] = $this->{$field};
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|