Skip to content

Commit

Permalink
WPOS-51
Browse files Browse the repository at this point in the history
Changed the show_shareonlinkedin setting from checkbox to select, so you can specify what certificate url you would like to have users use on their linkedin.
  • Loading branch information
frederikmillingpytlick committed Nov 2, 2023
1 parent 9dce557 commit 2f45b9f
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 10 deletions.
36 changes: 35 additions & 1 deletion classes/my_certificates_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class my_certificates_table extends \table_sql {
/**
* The value of the show share on linkedin setting, when the share on linkedin column should not be shown
*/
public const DO_NOT_SHOW = 0;

/**
* The value of the show share on linkedin setting, when the share on linkedin column should be shown
* and the link should go to the certificate verification page
*/
public const SHOW_LINK_TO_VERIFICATION_PAGE = 1;

/**
* The value of the show share on linkedin setting, when the share on linkedin column should be shown
* and the link should go to the certificate page
*/
public const SHOW_LINK_TO_CERTIFICATE_PAGE = 2;

/**
* @var int $userid The user id
Expand Down Expand Up @@ -203,6 +219,24 @@ public function download() {
exit;
}

/**
* Get the certificate url to show
*
* @param string $issuecode
* @return string
*/
private function get_shareonlinkedincerturl($issuecode) {
$showshareonlinkedin = (int)get_config('tool_certificate', 'show_shareonlinkedin');
switch ($showshareonlinkedin) {
case self::SHOW_LINK_TO_VERIFICATION_PAGE:
return template::verification_url($issuecode);
case self::SHOW_LINK_TO_CERTIFICATE_PAGE:
return template::view_url($issuecode);
default:
return '';
}
}

/**
* Generate the LinkedIn column
*
Expand All @@ -217,7 +251,7 @@ public function col_linkedin($issue) {
'issueYear' => date('Y', $issue->timecreated),
'issueMonth' => date('m', $issue->timecreated),
'certId' => $issue->code,
'certUrl' => template::verification_url($issue->code),
'certUrl' => $this->get_shareonlinkedincerturl($issue->code),
];

if ($issue->expires !== '0') {
Expand Down
3 changes: 3 additions & 0 deletions lang/en/tool_certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
$string['shareonlinkedin'] = 'Share on LinkedIn';
$string['show_shareonlinkedin'] = 'Show share on LinkedIn';
$string['show_shareonlinkedin_desc'] = 'If the "Share on LinkedIn" button should be shown on the my certificates page';
$string['do_not_show'] = 'Do not show';
$string['show_link_to_verification_page'] = 'Show link to verification page';
$string['show_link_to_certificate_page'] = 'Show link to certificate page';
$string['status'] = 'Status';
$string['subplugintype_certificateelement_plural'] = 'Certificate element plugins';
$string['template'] = 'Template';
Expand Down
19 changes: 16 additions & 3 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use tool_certificate\my_certificates_table;

defined('MOODLE_INTERNAL') || die;

require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/certificate/adminlib.php');
Expand Down Expand Up @@ -72,17 +74,28 @@
new lang_string('issuelangdesc', 'tool_certificate'),
false
));
$settings->add(new admin_setting_configcheckbox('tool_certificate/show_shareonlinkedin',
$settings->add(new admin_setting_configselect('tool_certificate/show_shareonlinkedin',
new lang_string('show_shareonlinkedin', 'tool_certificate'),
new lang_string('show_shareonlinkedin_desc', 'tool_certificate'),
false
my_certificates_table::DO_NOT_SHOW,
[
my_certificates_table::DO_NOT_SHOW => new lang_string('do_not_show', 'tool_certificate'),
my_certificates_table::SHOW_LINK_TO_VERIFICATION_PAGE => new lang_string('show_link_to_verification_page',
'tool_certificate'),
my_certificates_table::SHOW_LINK_TO_CERTIFICATE_PAGE => new lang_string('show_link_to_certificate_page',
'tool_certificate'),
]
));
$settings->add(new admin_setting_configtext('tool_certificate/linkedinorganizationid',
new lang_string('linkedinorganizationid', 'tool_certificate'),
new lang_string('linkedinorganizationid_desc', 'tool_certificate'),
''
));
$settings->hide_if('tool_certificate/linkedinorganizationid', 'tool_certificate/show_shareonlinkedin');
$settings->hide_if(
'tool_certificate/linkedinorganizationid',
'tool_certificate/show_shareonlinkedin',
'eq',
my_certificates_table::DO_NOT_SHOW);

$settings->add(new admin_setting_pickfilters('tool_certificate/allowfilters',
new lang_string('allowfilters', 'tool_certificate'),
Expand Down
83 changes: 77 additions & 6 deletions tests/my_certificates_table_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ public function test_col_name(): void {
* @param object $issue
* @param array $params
* @param ?int $organizationid
* @param int $showshareonlinkedin
* @return void
* @throws \moodle_exception
*/
public function test_col_linkedin($issue, $params, $organizationid): void {
public function test_col_linkedin($issue, $params, $organizationid, $showshareonlinkedin): void {
if ($organizationid) {
set_config('linkedinorganizationid', $organizationid, 'tool_certificate');
}

if ($showshareonlinkedin) {
set_config('show_shareonlinkedin', $showshareonlinkedin, 'tool_certificate');
}

$user = self::getDataGenerator()->create_user();
$issue->userid = $user->id;

Expand All @@ -86,7 +91,7 @@ public function test_col_linkedin($issue, $params, $organizationid): void {
$anchortag = $table->col_linkedin($issue);

$link = $this->get_href_value_from_anchor_tag($anchortag);
$url = new \moodle_url(\tool_certificate\my_certificates_table::LINKEDIN_ADD_TO_PROFILE_URL, $params);
$url = new \moodle_url(my_certificates_table::LINKEDIN_ADD_TO_PROFILE_URL, $params);

self::assertEquals($url->out(false), $link);
}
Expand All @@ -112,7 +117,7 @@ public static function col_linkedin_provider(): array {
'issueMonth' => '10',
'certId' => '0123456789SS',
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS',
], null, ],
], null, my_certificates_table::SHOW_LINK_TO_VERIFICATION_PAGE, ],
[(object)[
'id' => '6',
'expires' => '0',
Expand All @@ -128,7 +133,7 @@ public static function col_linkedin_provider(): array {
'certId' => '0123456789SS',
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS',
'organizationId' => '123',
], 123, ],
], 123, my_certificates_table::SHOW_LINK_TO_VERIFICATION_PAGE, ],
[(object)[
'id' => '6',
'expires' => '123',
Expand All @@ -145,7 +150,7 @@ public static function col_linkedin_provider(): array {
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS',
'expirationYear' => '1970',
'expirationMonth' => '01',
], null, ],
], null, my_certificates_table::SHOW_LINK_TO_VERIFICATION_PAGE, ],
[(object)[
'id' => '6',
'expires' => '123',
Expand All @@ -163,7 +168,73 @@ public static function col_linkedin_provider(): array {
'expirationYear' => '1970',
'expirationMonth' => '01',
'organizationId' => '123',
], 123, ],
], 123, my_certificates_table::SHOW_LINK_TO_VERIFICATION_PAGE, ],
[(object)[
'id' => '6',
'expires' => '0',
'code' => '0123456789SS',
'timecreated' => 1634376554,
'templateid' => '1',
'contextid' => '1',
'name' => 'Certificate demo template',
], [
'name' => 'Certificate demo template',
'issueYear' => '2021',
'issueMonth' => '10',
'certId' => '0123456789SS',
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/view.php?code=0123456789SS',
], null, my_certificates_table::SHOW_LINK_TO_CERTIFICATE_PAGE, ],
[(object)[
'id' => '6',
'expires' => '0',
'code' => '0123456789SS',
'timecreated' => 1500370154,
'templateid' => '1',
'contextid' => '1',
'name' => 'Certificate demo template',
], [
'name' => 'Certificate demo template',
'issueYear' => '2017',
'issueMonth' => '07',
'certId' => '0123456789SS',
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/view.php?code=0123456789SS',
'organizationId' => '123',
], 123, my_certificates_table::SHOW_LINK_TO_CERTIFICATE_PAGE, ],
[(object)[
'id' => '6',
'expires' => '123',
'code' => '0123456789SS',
'timecreated' => 1568626154,
'templateid' => '1',
'contextid' => '1',
'name' => 'Certificate demo template',
], [
'name' => 'Certificate demo template',
'issueYear' => '2019',
'issueMonth' => '09',
'certId' => '0123456789SS',
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/view.php?code=0123456789SS',
'expirationYear' => '1970',
'expirationMonth' => '01',
], null, my_certificates_table::SHOW_LINK_TO_CERTIFICATE_PAGE, ],
[(object)[
'id' => '6',
'expires' => '123',
'code' => '0123456789SS',
'timecreated' => 1705573754,
'templateid' => '1',
'contextid' => '1',
'name' => 'Certificate demo template',
], [
'name' => 'Certificate demo template',
'issueYear' => '2024',
'issueMonth' => '01',
'certId' => '0123456789SS',
'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/view.php?code=0123456789SS',
'expirationYear' => '1970',
'expirationMonth' => '01',
'organizationId' => '123',
], 123, my_certificates_table::SHOW_LINK_TO_CERTIFICATE_PAGE, ],
];
}

Expand Down

0 comments on commit 2f45b9f

Please sign in to comment.