Add bookmark exports and sharing + various fixes
This commit is contained in:
@ -62,6 +62,7 @@ class Bookmarks extends DatabaseModel {
|
||||
'color' => $color,
|
||||
'privacy' => $privacy,
|
||||
'createdBy' => $user,
|
||||
'uuid' => generateUuidV4(),
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( !empty( $folderID ) ) {
|
||||
@ -102,6 +103,20 @@ class Bookmarks extends DatabaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function findByUuid( $id ) {
|
||||
$whereClause = ['uuid', '=', $id];
|
||||
if ( empty( $limit ) ) {
|
||||
$bookmarks = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$bookmarks = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$bookmarks->count() ) {
|
||||
Debug::info( 'No Bookmarks found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $bookmarks->first() );
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
@ -132,6 +147,21 @@ class Bookmarks extends DatabaseModel {
|
||||
return $this->filter( $bookmarks->results() );
|
||||
}
|
||||
|
||||
public function publicByFolder( $id, $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID, 'AND'];
|
||||
$whereClause = array_merge( $whereClause, [ 'folderID', '=', $id, 'AND', 'privacy', '=', 'public' ] );
|
||||
if ( empty( $limit ) ) {
|
||||
$bookmarks = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$bookmarks = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$bookmarks->count() ) {
|
||||
Debug::info( 'No Bookmarks found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $bookmarks->results() );
|
||||
}
|
||||
|
||||
public function noFolder( $id = 0, $limit = 10 ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID, 'AND'];
|
||||
if ( !empty( $id ) ) {
|
||||
@ -318,6 +348,12 @@ class Bookmarks extends DatabaseModel {
|
||||
$instance->iconHtml = '<img src="' . $base_url . ltrim( $instance->icon, '/' ) .'" />';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $instance->privacy == 'private' ) {
|
||||
$instance->privacyBadge = '<span class="mx-3 badge bg-success">Private</span>';
|
||||
} else {
|
||||
$instance->privacyBadge = '<span class="mx-3 badge bg-danger">Public</span>';
|
||||
}
|
||||
if ( empty( $instance->hiddenAt ) ) {
|
||||
$instance->hideBtn = '
|
||||
<a href="{ROOT_URL}bookmarks/hideBookmark/'.$instance->ID.'" class="btn btn-sm btn-warning">
|
||||
@ -392,6 +428,38 @@ class Bookmarks extends DatabaseModel {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function publish( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Bookmarks: illegal ID.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'privacy' => 'public',
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'bookmarkUpdate' );
|
||||
Debug::error( "Bookmarks: $id not updated" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function retract( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
Debug::info( 'Bookmarks: illegal ID.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'privacy' => 'private',
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'bookmarkUpdate' );
|
||||
Debug::error( "Bookmarks: $id not updated" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function archive( $id ) {
|
||||
if ( !Check::id( $id ) ) {
|
||||
|
@ -56,6 +56,7 @@ class Bookmarkviews extends DatabaseModel {
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'privacy' => $privacy,
|
||||
'uuid' => generateUuidV4(),
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
|
@ -38,6 +38,20 @@ class Folders extends DatabaseModel {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function findByUuid( $id ) {
|
||||
$whereClause = ['uuid', '=', $id];
|
||||
if ( empty( $limit ) ) {
|
||||
$folders = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$folders = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$folders->count() ) {
|
||||
Debug::info( 'No Folders found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $folders->first() );
|
||||
}
|
||||
|
||||
public function create( $title, $folderID = 0, $description = '', $color = 'default', $privacy = 'private', $user = null ) {
|
||||
if ( empty( $user ) ) {
|
||||
$user = App::$activeUser->ID;
|
||||
@ -51,6 +65,7 @@ class Folders extends DatabaseModel {
|
||||
'description' => $description,
|
||||
'color' => $color,
|
||||
'privacy' => $privacy,
|
||||
'uuid' => generateUuidV4(),
|
||||
'createdBy' => $user,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
|
Reference in New Issue
Block a user