forked from moodle/moodle
-
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.
- Loading branch information
Showing
6 changed files
with
226 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
103 changes: 103 additions & 0 deletions
103
lib/editor/tiny/plugins/collaborative/classes/external/set_position.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,103 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace tiny_collaborative\external; | ||
|
||
use core_external\external_api; | ||
use core_external\external_function_parameters; | ||
use core_external\external_single_structure; | ||
use core_external\external_value; | ||
use core_external\external_multiple_structure; | ||
use tiny_collaborative; | ||
|
||
/** | ||
* Web Service to resume an autosave session. | ||
* | ||
* @package tiny_autosave | ||
* @category external | ||
* @copyright 2022 Andrew Lyons <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class get_changes extends external_api { | ||
/** | ||
* Returns description of method parameters | ||
* | ||
* @return external_function_parameters | ||
*/ | ||
public static function execute_parameters(): external_function_parameters { | ||
return new external_function_parameters([ | ||
'contextid' => new external_value(PARAM_INT, 'The context id that owns the editor', VALUE_REQUIRED), | ||
'elementid' => new external_value(PARAM_RAW, 'The ID of the element', VALUE_REQUIRED), | ||
'pageinstance' => new external_value(PARAM_RAW, 'The ID of the pageinstance', VALUE_REQUIRED), | ||
'position' => new external_value(PARAM_RAW, 'The position of the user', VALUE_REQUIRED), | ||
]); | ||
} | ||
|
||
/** | ||
* Reset the autosave entry for this autosave instance. | ||
* | ||
* If not matching autosave area could be found, the function will | ||
* silently return and this is not treated as an error condition. | ||
* | ||
* @param int $contextid The context id of the owner | ||
* @param string $pagehash The hash of the page | ||
* @param string $pageinstance The instance id of the page | ||
* @param string $elementid The id of the element | ||
* @param int $draftid The id of the draftid to resume to | ||
* @return null | ||
*/ | ||
public static function execute( | ||
int $contextid, | ||
string $elementid, | ||
string $pageinstance, | ||
string $position | ||
): array { | ||
|
||
[ | ||
'contextid' => $contextid, | ||
'elementid' => $elementid, | ||
'pageinstance' => $pageinstance, | ||
'position' => $position, | ||
] = self::validate_parameters(self::execute_parameters(), [ | ||
'contextid' => $contextid, | ||
'elementid' => $elementid, | ||
'pageinstance' => $pageinstance, | ||
'position' => $position, | ||
]); | ||
|
||
|
||
// May have been called by a non-logged in user. | ||
if (isloggedin() && !isguestuser()) { | ||
$manager = new \tiny_collaborative\position_manager($contextid,$elementid); | ||
$value = $manager->set_position($pageinstance, $position); | ||
} | ||
return $value; | ||
} | ||
|
||
/** | ||
* Describe the return structure of the external service. | ||
* | ||
* @return external_single_structure | ||
*/ | ||
public static function execute_returns(): external_single_structure { | ||
return new external_single_structure( ['changes' => | ||
new external_multiple_structure(PARAM_RAW, 'Description of the change'), | ||
'positions' => new external_multiple_structure(PARAM_RAW, '') | ||
|
||
// Add other fields related to the change here | ||
); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
lib/editor/tiny/plugins/collaborative/classes/position_manager.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,94 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace tiny_collaborative; | ||
|
||
use stdClass; | ||
|
||
/** | ||
* Autosave Manager. | ||
* | ||
* @package tiny_autosave | ||
* @copyright 2022 Andrew Lyons <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class position_manager { | ||
|
||
/** @var int The contextid */ | ||
protected $contextid; | ||
|
||
/** @var string The page hash reference */ | ||
protected $pagehash; | ||
|
||
/** @var string The elementid for this editor */ | ||
protected $elementid; | ||
|
||
/** | ||
* Constructor for the autosave manager. | ||
* | ||
* @param int $contextid The contextid of the session | ||
* @param string $pageinstance The page instance | ||
* @param string $elementid The element id | ||
* @param null|stdClass $user The user object for the owner of the autosave | ||
*/ | ||
public function __construct( | ||
int $contextid, | ||
string $elementid | ||
) { | ||
global $DB; | ||
$this->contextid = $contextid; | ||
$this->elementid = $elementid; | ||
} | ||
|
||
public function set_position($pageinstance,$position) { | ||
global $DB,$USER; | ||
|
||
$record = $DB->get_record('tiny_collaborative_positions',[ | ||
'contextid' => $this->contextid, | ||
'elementid' => $this->elementid, | ||
'pageinstance' => $pageinstance | ||
]); | ||
if($record) { | ||
$record->position = $position; | ||
$record->timemodified = time(); | ||
$DB->update_record('tiny_collaborative_positions', $record); | ||
} else { | ||
$record = new \stdClass(); | ||
$record->timemodified = time(); | ||
$record->elementid = $this->elementid; | ||
$record->userid = $USER->id; | ||
$record->contextid = $this->contextid; | ||
$record->pageinstance = $pageinstance; | ||
$record->position = $position; | ||
$record = $DB->insert_record('tiny_collaborative_positions', $record); | ||
} | ||
return $record->id; | ||
} | ||
|
||
public function get_user_positions() { | ||
global $DB; | ||
$positions = []; | ||
$records = $DB->get_records('tiny_collaborative_positions', [ | ||
'elementid' => $this->elementid, | ||
'contextid' => $this->contextid]); | ||
$positions = []; | ||
foreach ($records as $record) { | ||
$positions[] = [$record->userid => $record->position]; | ||
} | ||
return $positions; | ||
} | ||
|
||
} |
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