-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkp/pkp-lib#9456 Add user private notes #9549
Open
nibou230
wants to merge
6
commits into
pkp:main
Choose a base branch
from
nibou230:9456
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90f4b47
pkp/pkp-lib#9456 Allowing user private editorial notes
nibou230 3d170c7
pkp/pkp-lib#9456 Use the new DAO and refactor for private notes
nibou230 bab692e
pkp/pkp-lib#9456 Fix for the UserPrivateNote schema
nibou230 058b147
pkp/pkp-lib#9456 Add the migration in the installation list
nibou230 b5eca50
pkp/pkp-lib#9456 Remove migration on old XML migration schema
nibou230 58a40e0
pkp/pkp-lib#9456 Removed First from the method name
nibou230 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/install/UserPrivateNotesMigration.php | ||
* | ||
* Copyright (c) 2014-2023 Simon Fraser University | ||
* Copyright (c) 2000-2023 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class UserPrivateNotesMigration | ||
* | ||
* @brief Describe database table structure for user private notes | ||
*/ | ||
|
||
namespace PKP\migration\install; | ||
|
||
use APP\core\Application; | ||
use APP\facades\Repo; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema as Schema; | ||
use PKP\migration\Migration; | ||
|
||
class UserPrivateNotesMigration extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('user_private_notes', function (Blueprint $table) { | ||
$table->comment('User private notes are an addition to the gossip, but this one is private to each context.'); | ||
$table->bigInteger('user_private_note_id')->autoIncrement(); | ||
|
||
$table->bigInteger('context_id'); | ||
$contextDao = Application::getContextDAO(); | ||
$table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade'); | ||
|
||
$table->bigInteger('user_id'); | ||
$userDao = Repo::user()->dao; | ||
$table->foreign('user_id')->references($userDao->primaryKeyColumn)->on($userDao->table)->onDelete('cascade'); | ||
|
||
$table->unique(['context_id', 'user_id'], 'user_private_notes_unique'); | ||
$table->index(['context_id'], 'user_private_notes_context_id_foreign'); | ||
|
||
$table->string('note')->default(''); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::drop('user_private_notes'); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
classes/migration/upgrade/v3_5_0/I9456_UserPrivateNotes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/upgrade/v3_5_0/I9456_UserPrivateNotes.php | ||
* | ||
* Copyright (c) 2014-2023 Simon Fraser University | ||
* Copyright (c) 2000-2023 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class I9456_UserPrivateNotes | ||
*/ | ||
|
||
namespace PKP\migration\upgrade\v3_5_0; | ||
|
||
use APP\core\Application; | ||
use APP\facades\Repo; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use PKP\migration\Migration; | ||
|
||
class I9456_UserPrivateNotes extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('user_private_notes', function (Blueprint $table) { | ||
$table->comment('User private notes are an addition to the gossip, but this one is private to each context.'); | ||
$table->bigInteger('user_private_note_id')->autoIncrement(); | ||
|
||
$table->bigInteger('context_id'); | ||
$contextDao = Application::getContextDAO(); | ||
$table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade'); | ||
|
||
$table->bigInteger('user_id'); | ||
$userDao = Repo::user()->dao; | ||
$table->foreign('user_id')->references($userDao->primaryKeyColumn)->on($userDao->table)->onDelete('cascade'); | ||
|
||
$table->unique(['context_id', 'user_id'], 'user_private_notes_unique'); | ||
$table->index(['context_id'], 'user_private_notes_context_id_foreign'); | ||
|
||
$table->string('note')->default(''); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::drop('user_private_notes'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
/** | ||
* @file classes/userPrivateNote/Collector.php | ||
* | ||
* Copyright (c) 2014-2021 Simon Fraser University | ||
* Copyright (c) 2000-2021 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class \PKP\userPrivateNote\Collector | ||
* | ||
* @brief A helper class to configure a Query Builder to get a collection of UserPrivateNote | ||
*/ | ||
|
||
namespace PKP\userPrivateNote; | ||
|
||
use Illuminate\Database\Query\Builder; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\LazyCollection; | ||
use PKP\core\interfaces\CollectorInterface; | ||
use PKP\plugins\Hook; | ||
|
||
/** | ||
* @template T of UserPrivateNote | ||
*/ | ||
class Collector implements CollectorInterface | ||
{ | ||
public const ORDERBY_ID = 'id'; | ||
|
||
public ?string $orderBy = null; | ||
|
||
/** @var DAO */ | ||
public DAO $dao; | ||
|
||
public ?array $userPrivateNoteIds = null; | ||
|
||
public ?array $contextIds = null; | ||
|
||
public ?array $userIds = null; | ||
|
||
public ?int $count = null; | ||
|
||
public ?int $offset = null; | ||
|
||
public function __construct(DAO $dao) | ||
{ | ||
$this->dao = $dao; | ||
} | ||
|
||
public function getCount(): int | ||
{ | ||
return $this->dao->getCount($this); | ||
} | ||
|
||
/** | ||
* @return Collection<int,int> | ||
*/ | ||
public function getIds(): Collection | ||
{ | ||
return $this->dao->getIds($this); | ||
} | ||
|
||
/** | ||
* @copydoc DAO::getMany() | ||
* | ||
* @return LazyCollection<int,T> | ||
*/ | ||
public function getMany(): LazyCollection | ||
{ | ||
return $this->dao->getMany($this); | ||
} | ||
|
||
/** | ||
* Filter by multiple ids | ||
*/ | ||
public function filterByUserPrivateNoteIds(?array $ids): self | ||
{ | ||
$this->userPrivateNoteIds = $ids; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Filter by context IDs | ||
*/ | ||
public function filterByContextIds(?array $contextIds): self | ||
{ | ||
$this->contextIds = $contextIds; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Filter by user ids | ||
*/ | ||
public function filterByUserIds(?array $userIds): self | ||
{ | ||
$this->userIds = $userIds; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Include orderBy columns to the collector query | ||
*/ | ||
public function orderBy(?string $orderBy): self | ||
{ | ||
$this->orderBy = $orderBy; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Limit the number of objects retrieved | ||
*/ | ||
public function limit(?int $count): self | ||
{ | ||
$this->count = $count; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Offset the number of objects retrieved, for example to | ||
* retrieve the second page of contents | ||
*/ | ||
public function offset(?int $offset): self | ||
{ | ||
$this->offset = $offset; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @copydoc CollectorInterface::getQueryBuilder() | ||
* | ||
* @hook UserGroup::Collector [[&$q, $this]] | ||
*/ | ||
public function getQueryBuilder(): Builder | ||
{ | ||
$q = DB::table('user_private_notes as upn') | ||
->select('upn.*'); | ||
|
||
if (isset($this->userPrivateNoteIds)) { | ||
$q->whereIn('upn.user_private_note_id', $this->userPrivateNoteIds); | ||
} | ||
|
||
if (isset($this->contextIds)) { | ||
$q->whereIn('upn.context_id', $this->contextIds); | ||
} | ||
|
||
if (isset($this->userIds)) { | ||
$q->whereIn('upn.user_id', $this->userIds); | ||
} | ||
|
||
if (isset($this->count)) { | ||
$q->limit($this->count); | ||
} | ||
|
||
if (isset($this->offset)) { | ||
$q->offset($this->offset); | ||
} | ||
|
||
if ($this->orderBy == self::ORDERBY_ID) { | ||
$q->orderBy('upn.user_private_note_id'); | ||
} | ||
|
||
// Add app-specific query statements | ||
Hook::call('UserPrivateNote::Collector', [&$q, $this]); | ||
|
||
return $q; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is probably leftover and not necessary.