Skip to content
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

Moodle Plugin CI, and Moodle coding style #728

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: Moodle plugin CI
on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-latest'

strategy:
fail-fast: false
matrix:
include:
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: mariadb
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: mariadb
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: mariadb
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_402_STABLE
database: mariadb
- php: 8.1
moodle-branch: MOODLE_402_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_403_STABLE
database: mariadb
- php: 8.1
moodle-branch: MOODLE_403_STABLE
database: pgsql
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: mariadb
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: pgsql
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: mariadb
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: pgsql
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: mariadb
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: pgsql
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: mariadb
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: pgsql
- php: 8.2
moodle-branch: MOODLE_405_STABLE
database: mariadb
- php: 8.2
moodle-branch: MOODLE_405_STABLE
database: pgsql
- php: 8.3
moodle-branch: MOODLE_405_STABLE
database: mariadb
- php: 8.3
moodle-branch: MOODLE_405_STABLE
database: pgsql

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432

mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV

- name: Install Moodle
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
IGNORE_PATHS: 'vendor'
PHPCS_IGNORE_PATHS: '/^vendor/'
PHPDOCCHECKER_IGNORE_PATHS: '/^vendor/'

- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Mess Detector
continue-on-error: true
if: ${{ always() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 1000

- name: Validating
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ always() }}
run: moodle-plugin-ci mustache || true

- name: Grunt
if: ${{ matrix.moodle-branch == 'MOODLE_400_STABLE' }}
run: moodle-plugin-ci grunt --max-lint-warnings 1000

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat
58 changes: 33 additions & 25 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Turnitin ajax file
*
* @package plagiarism_turnitin
* @copyright 2013 iParadigms LLC
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use Integrations\PhpSdk\TiiClass;

require_once(__DIR__.'/../../config.php');
Expand Down Expand Up @@ -45,7 +53,7 @@

$pathnamehash = optional_param('pathnamehash', "", PARAM_ALPHANUM);
$submissiontype = optional_param('submission_type', "", PARAM_ALPHAEXT);
$return = array();
$return = [];

// Initialise plugin class.
$pluginturnitin = new plagiarism_plugin_turnitin();
Expand Down Expand Up @@ -79,7 +87,7 @@
$userrole,
''
),
array('style' => 'display: none')
['style' => 'display: none']
);
}
break;
Expand All @@ -102,7 +110,7 @@

// If we have a turnitin timestamp stored then update it, otherwise create it.
if ($timestampid = $DB->get_record('plagiarism_turnitin_config',
array('cm' => $cm->id, 'name' => 'grades_last_synced'), 'id')) {
['cm' => $cm->id, 'name' => 'grades_last_synced'], 'id')) {
$moduleconfigvalue->id = $timestampid->id;
$DB->update_record('plagiarism_turnitin_config', $moduleconfigvalue);
} else {
Expand All @@ -122,7 +130,7 @@
throw new moodle_exception('invalidsesskey', 'error');
}

$tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid'));
$tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']);
$pluginturnitin->refresh_peermark_assignments($cm, $tiiassignment->value);
break;

Expand All @@ -132,7 +140,7 @@
$plagiarismpluginturnitin = new plagiarism_plugin_turnitin();
$coursedata = $plagiarismpluginturnitin->get_course_data($cm->id, $cm->course);

$tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid'));
$tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']);

if ($tiiassignment) {
$tiiassignmentid = $tiiassignment->value;
Expand All @@ -148,10 +156,10 @@
echo html_writer::tag(
'div',
turnitin_view::output_lti_form_launch('peermark_manager', 'Instructor', $tiiassignmentid),
array(
[
'class' => 'launch_form',
'style' => 'display:none;'
)
'style' => 'display:none;',
]
);

echo html_writer::script("<!--
Expand All @@ -166,7 +174,7 @@
$isstudent = ($cm->modname == "forum") ? has_capability($replypost, $context) : has_capability($submit, $context);

if ($isstudent) {
$tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid'));
$tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']);

$user = new turnitin_user($USER->id, "Learner");
$coursedata = turnitin_assignment::get_course_data($cm->course);
Expand All @@ -175,10 +183,10 @@
echo html_writer::tag(
'div',
turnitin_view::output_lti_form_launch('rubric_view', 'Learner', $tiiassignment->value),
array(
[
'class' => 'launch_form',
'style' => 'display:none;'
)
'style' => 'display:none;',
]
);

echo html_writer::script("<!--
Expand All @@ -193,7 +201,7 @@
$isstudent = ($cm->modname == "forum") ? has_capability($replypost, $context) : has_capability($submit, $context);

if ($userrole == 'Instructor' || $isstudent) {
$tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid'));
$tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']);

$user = new turnitin_user($USER->id, $userrole);
$coursedata = turnitin_assignment::get_course_data($cm->course);
Expand All @@ -202,10 +210,10 @@
echo html_writer::tag(
'div',
turnitin_view::output_lti_form_launch('peermark_reviews', $userrole, $tiiassignment->value),
array(
[
'class' => 'launch_form',
'style' => 'display:none;'
)
'style' => 'display:none;',
]
);

echo html_writer::script("<!--
Expand All @@ -222,7 +230,7 @@
$message = optional_param('message', '', PARAM_ALPHAEXT);

// Get the id from the plagiarism_turnitin_users table so we can update.
$turnitinuser = $DB->get_record('plagiarism_turnitin_users', array('userid' => $USER->id));
$turnitinuser = $DB->get_record('plagiarism_turnitin_users', ['userid' => $USER->id]);

// Build user object for update.
$eulauser = new stdClass();
Expand Down Expand Up @@ -252,10 +260,10 @@
$submissionid = required_param('submissionid', PARAM_INT);

$tiisubmission = new turnitin_submission($submissionid,
array('forumdata' => $forumdata, 'forumpost' => $forumpost));
['forumdata' => $forumdata, 'forumpost' => $forumpost]);

if ($tiisubmission->recreate_submission_event()) {
$return = array('success' => true);
$return = ['success' => true];
}
break;

Expand All @@ -265,10 +273,10 @@
throw new moodle_exception('invalidsesskey', 'error');
}

$submissionids = optional_param_array('submission_ids', array(), PARAM_INT);
$submissionids = optional_param_array('submission_ids', [], PARAM_INT);

$submissionids = optional_param_array('submission_ids', array(), PARAM_INT);
$errors = array();
$submissionids = optional_param_array('submission_ids', [], PARAM_INT);
$errors = [];
$return['success'] = true;
foreach ($submissionids as $submissionid) {
$tiisubmission = new turnitin_submission($submissionid);
Expand All @@ -284,7 +292,7 @@
if (!confirm_sesskey()) {
throw new moodle_exception('invalidsesskey', 'error');
}
$data = array("connection_status" => "fail", "msg" => get_string('connecttestcommerror', 'plagiarism_turnitin'));
$data = ["connection_status" => "fail", "msg" => get_string('connecttestcommerror', 'plagiarism_turnitin')];

$PAGE->set_context(context_system::instance());
if (is_siteadmin()) {
Expand Down Expand Up @@ -346,7 +354,7 @@
$instructor->set_user_values_from_tii();
$instructorrubrics = $instructor->get_instructor_rubrics();

$options = array(0 => get_string('norubric', 'plagiarism_turnitin')) + $instructorrubrics;
$options = [0 => get_string('norubric', 'plagiarism_turnitin')] + $instructorrubrics;

// Get rubrics that are shared on the Turnitin account.
$turnitinclass = new turnitin_class($courseid);
Expand Down Expand Up @@ -378,7 +386,7 @@
}
}
} else {
$options = array();
$options = [];
}

echo json_encode($options);
Expand Down
Loading