forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#9456 Allowing user private editorial notes
- Loading branch information
Showing
16 changed files
with
416 additions
and
15 deletions.
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,54 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/upgrade/v3_5_0/I9456_PrivateNotes.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_PrivateNotes | ||
*/ | ||
|
||
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_PrivateNotes 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('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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/user/PrivateNote.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 PrivateNote | ||
* | ||
* @ingroup user | ||
* | ||
* @see PrivateNotesDAO | ||
* | ||
* @brief Basic class describing user private note existing in the system. | ||
*/ | ||
|
||
namespace PKP\user; | ||
|
||
use PKP\core\DataObject; | ||
|
||
class PrivateNote extends DataObject | ||
{ | ||
/** | ||
* Get private note ID. | ||
* | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->getData('id'); | ||
} | ||
|
||
/** | ||
* Set private note ID. | ||
* | ||
* @param $id int | ||
*/ | ||
public function setId($id): void | ||
{ | ||
$this->setData('id', $id); | ||
} | ||
|
||
/** | ||
* Get private note context ID. | ||
* | ||
* @return int | ||
*/ | ||
public function getContextId(): int | ||
{ | ||
return $this->getData('contextId'); | ||
} | ||
|
||
/** | ||
* Set private note context ID. | ||
* | ||
* @param $contextId int | ||
*/ | ||
public function setContextId(int $contextId): void | ||
{ | ||
$this->setData('contextId', $contextId); | ||
} | ||
|
||
/** | ||
* Get private note user ID. | ||
* | ||
* @return int | ||
*/ | ||
public function getUserId(): int | ||
{ | ||
return $this->getData('userId'); | ||
} | ||
|
||
/** | ||
* Set private note user ID. | ||
* | ||
* @param $userId int | ||
*/ | ||
public function setUserId(int $userId): void | ||
{ | ||
$this->setData('userId', $userId); | ||
} | ||
|
||
|
||
/** | ||
* Get private note value. | ||
* | ||
* @return string | ||
*/ | ||
public function getNote(): string | ||
{ | ||
return $this->getData('note'); | ||
} | ||
|
||
/** | ||
* Set private note value. | ||
* | ||
* @param $note string | ||
*/ | ||
public function setNote(string $note): void | ||
{ | ||
$this->setData('note', $note); | ||
} | ||
} | ||
|
||
if (!PKP_STRICT_MODE) { | ||
class_alias('\PKP\user\PrivateNote', '\PrivateNote'); | ||
} |
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,108 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/user/PrivateNotesDAO.php | ||
* | ||
* Copyright (c) 2014-2021 Simon Fraser University | ||
* Copyright (c) 2003-2021 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class PrivateNotesDAO | ||
* | ||
* @ingroup user | ||
* | ||
* @see PrivateNote | ||
* | ||
* @brief Operations for retrieving and modifying user private notes. | ||
*/ | ||
|
||
namespace PKP\user; | ||
|
||
use PKP\db\DAO; | ||
use PKP\db\DAOResultFactory; | ||
|
||
class PrivateNotesDAO extends DAO | ||
{ | ||
/** | ||
* Construct a new PrivateNote object. | ||
* | ||
* @return PrivateNote | ||
*/ | ||
public function newDataObject(): PrivateNote | ||
{ | ||
return new PrivateNote(); | ||
} | ||
|
||
/** | ||
* Retrieve a user private note value. | ||
* | ||
* @param int $journalId | ||
* @param int $userId | ||
* | ||
* @return PrivateNote|null | ||
*/ | ||
public function getPrivateNote(int $journalId, int $userId): PrivateNote|null | ||
{ | ||
$params = [ | ||
$journalId, | ||
$userId | ||
]; | ||
$result = $this->retrieve( | ||
'SELECT * FROM user_private_notes WHERE context_id = ? AND user_id = ?', | ||
$params | ||
); | ||
$factory = new DAOResultFactory($result, $this, '_fromRow'); | ||
return $factory->toIterator()->current(); | ||
} | ||
|
||
/** | ||
* Set a user private note value. | ||
* | ||
* @param int $journalId | ||
* @param int $userId | ||
* @param string $note | ||
*/ | ||
public function setPrivateNote(int $journalId, int $userId, string $note): void | ||
{ | ||
$params = [ | ||
$note, | ||
$journalId, | ||
$userId | ||
]; | ||
$dbPrivateNote = $this->getPrivateNote($journalId, $userId); | ||
if ($dbPrivateNote) { | ||
$this->update( | ||
'UPDATE user_private_notes SET note = ? WHERE context_id = ? AND user_id = ?', | ||
$params | ||
); | ||
} else { | ||
$this->update( | ||
'INSERT INTO user_private_notes (note, context_id, user_id) VALUES (?, ?, ?)', | ||
$params | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Internal function to return a PrivateNote object from a row. | ||
* | ||
* @param array $row | ||
* | ||
* @return PrivateNote | ||
*/ | ||
function _fromRow(array $row): PrivateNote | ||
{ | ||
$privateNote = $this->newDataObject(); | ||
|
||
$privateNote->setId($row['private_note_id']); | ||
$privateNote->setContextId($row['context_id']); | ||
$privateNote->setUserId($row['user_id']); | ||
$privateNote->setNote($row['note']); | ||
|
||
return $privateNote; | ||
} | ||
} | ||
|
||
if (!PKP_STRICT_MODE) { | ||
class_alias('\PKP\user\PrivateNotesDAO', '\PrivateNotesDAO'); | ||
} |
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
Oops, something went wrong.