diff --git a/amd/build/referral.min.js.map b/amd/build/referral.min.js.map index e90a9119..bd1b53f5 100644 --- a/amd/build/referral.min.js.map +++ b/amd/build/referral.min.js.map @@ -1 +1 @@ -{"version":3,"file":"referral.min.js","sources":["../src/referral.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * TODO describe module referral\n *\n * @module enrol_wallet/referral\n * @copyright 2024 YOUR NAME \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport {get_strings} from 'core/str';\nimport Prefetch from 'core/prefetch';\n\n// Prefetch required string while the page loading.\nPrefetch.prefetchStrings('enrol_wallet', ['referral_copy_to_clipboard', 'referral_copied']);\n\nlet copyTooltip;\nlet copiedTooltip;\nlet shareUrl;\nlet copyButtonCode;\nlet copyButtonUrl;\nlet uniqueId;\n/**\n *\n */\nfunction shareOnFacebook() {\n let fbBase = 'https://www.facebook.com/sharer/sharer.php?u=';\n window.open(fbBase + encodeURIComponent(shareUrl), 'facebook-share-dialog', 'width=800,height=600');\n}\n\n/**\n *\n */\nfunction shareOnWhatsApp() {\n window.open('https://wa.me/?text=' + encodeURIComponent(shareUrl));\n}\n\n/**\n *\n */\nfunction shareOnTelegram() {\n window.open('https://t.me/share/url?url=' + encodeURIComponent(shareUrl));\n}\n\n/**\n * Copy the text in the input value.\n * @param {string} target\n * @param {DOMElement} element\n */\nfunction copyText(target, element) {\n let input = $('#' + target + '_' + uniqueId);\n\n navigator.clipboard.writeText(input[0].value);\n\n element.setAttribute('tooltip', copiedTooltip);\n}\n\nconst resetTooltip = (element) => {\n element.setAttribute('tooltip', copyTooltip);\n};\n\n/**\n * Add listeners to copy and sharing buttons.\n */\nfunction addListeners() {\n copyButtonUrl.addEventListener('click', () => {\n copyText('url', copyButtonUrl);\n });\n copyButtonUrl.addEventListener('mouseleave', () => {\n resetTooltip(copyButtonUrl);\n });\n copyButtonCode.addEventListener('click', () => {\n copyText('code', copyButtonCode);\n });\n copyButtonCode.addEventListener('mouseleave', () => {\n resetTooltip(copyButtonCode);\n });\n\n $('a[href=\"#shareOnFacebook\"]').on(\"click\", () => {\n shareOnFacebook();\n });\n $('a[href=\"#shareOnTelegram\"]').on(\"click\", () => {\n shareOnTelegram();\n });\n $('a[href=\"#shareOnWhatsApp\"]').on(\"click\", () => {\n shareOnWhatsApp();\n });\n}\n\n/**\n * Initiate the module.\n *\n * @param {string} url the referral url\n * @param {string} id the unique id of the template\n */\nexport const init = (url, id) => {\n var strings = [\n {\n key: 'referral_copy_to_clipboard',\n component: 'enrol_wallet'\n },\n {\n key: 'referral_copied',\n component: 'enrol_wallet',\n }\n ];\n get_strings(strings).then(function(results) {\n copyTooltip = results[0];\n copiedTooltip = results[1];\n return true;\n }).fail(() => {\n return false;\n });\n shareUrl = url;\n uniqueId = id;\n copyButtonUrl = document.getElementById('copy_url_' + id);\n copyButtonCode = document.getElementById('copy_code_' + id);\n\n addListeners();\n};"],"names":["copyTooltip","copiedTooltip","shareUrl","copyButtonCode","copyButtonUrl","uniqueId","copyText","target","element","input","navigator","clipboard","writeText","value","setAttribute","prefetchStrings","resetTooltip","addListeners","addEventListener","on","window","open","encodeURIComponent","url","id","key","component","then","results","fail","document","getElementById"],"mappings":";;;;;;;SA8BIA,YACAC,cACAC,SACAC,eACAC,cACAC,kBA4BKC,SAASC,OAAQC,aAClBC,OAAQ,mBAAE,IAAMF,OAAS,IAAMF,UAEnCK,UAAUC,UAAUC,UAAUH,MAAM,GAAGI,OAEvCL,QAAQM,aAAa,UAAWb,0LAxC3Bc,gBAAgB,eAAgB,CAAC,6BAA8B,0BA2ClEC,aAAgBR,UAClBA,QAAQM,aAAa,UAAWd,uBAM3BiB,eACLb,cAAcc,iBAAiB,SAAS,KACpCZ,SAAS,MAAOF,kBAEpBA,cAAcc,iBAAiB,cAAc,KACzCF,aAAaZ,kBAEjBD,eAAee,iBAAiB,SAAS,KACrCZ,SAAS,OAAQH,mBAErBA,eAAee,iBAAiB,cAAc,KAC1CF,aAAab,uCAGf,8BAA8BgB,GAAG,SAAS,KAnD5CC,OAAOC,KADM,gDACQC,mBAAmBpB,UAAW,wBAAyB,+CAsD1E,8BAA8BiB,GAAG,SAAS,KAxC5CC,OAAOC,KAAK,8BAAgCC,mBAAmBpB,kCA2C7D,8BAA8BiB,GAAG,SAAS,KAlD5CC,OAAOC,KAAK,uBAAyBC,mBAAmBpB,4BA6DxC,CAACqB,IAAKC,2BACR,CACV,CACIC,IAAK,6BACLC,UAAW,gBAEf,CACID,IAAK,kBACLC,UAAW,kBAGEC,MAAK,SAASC,gBAC/B5B,YAAc4B,QAAQ,GACtB3B,cAAgB2B,QAAQ,IACjB,KACRC,MAAK,KACG,IAEX3B,SAAWqB,IACXlB,SAAWmB,GACXpB,cAAgB0B,SAASC,eAAe,YAAcP,IACtDrB,eAAiB2B,SAASC,eAAe,aAAeP,IAExDP"} \ No newline at end of file +{"version":3,"file":"referral.min.js","sources":["../src/referral.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * TODO describe module referral\n *\n * @module enrol_wallet/referral\n * @copyright 2024 YOUR NAME \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\n// eslint-disable-next-line camelcase\nimport {get_strings} from 'core/str';\nimport Prefetch from 'core/prefetch';\n\n// Prefetch required string while the page loading.\nPrefetch.prefetchStrings('enrol_wallet', ['referral_copy_to_clipboard', 'referral_copied']);\n\nlet copyTooltip;\nlet copiedTooltip;\nlet shareUrl;\nlet copyButtonCode;\nlet copyButtonUrl;\nlet uniqueId;\n/**\n *\n */\nfunction shareOnFacebook() {\n let fbBase = 'https://www.facebook.com/sharer/sharer.php?u=';\n window.open(fbBase + encodeURIComponent(shareUrl), 'facebook-share-dialog', 'width=800,height=600');\n}\n\n/**\n *\n */\nfunction shareOnWhatsApp() {\n window.open('https://wa.me/?text=' + encodeURIComponent(shareUrl));\n}\n\n/**\n *\n */\nfunction shareOnTelegram() {\n window.open('https://t.me/share/url?url=' + encodeURIComponent(shareUrl));\n}\n\n/**\n * Copy the text in the input value.\n * @param {string} target\n * @param {DOMElement} element\n */\nfunction copyText(target, element) {\n let input = $('#' + target + '_' + uniqueId);\n\n navigator.clipboard.writeText(input[0].value);\n\n element.setAttribute('tooltip', copiedTooltip);\n}\n\nconst resetTooltip = (element) => {\n element.setAttribute('tooltip', copyTooltip);\n};\n\n/**\n * Add listeners to copy and sharing buttons.\n */\nfunction addListeners() {\n copyButtonUrl.addEventListener('click', () => {\n copyText('url', copyButtonUrl);\n });\n copyButtonUrl.addEventListener('mouseleave', () => {\n resetTooltip(copyButtonUrl);\n });\n copyButtonCode.addEventListener('click', () => {\n copyText('code', copyButtonCode);\n });\n copyButtonCode.addEventListener('mouseleave', () => {\n resetTooltip(copyButtonCode);\n });\n\n $('a[href=\"#shareOnFacebook\"]').on(\"click\", () => {\n shareOnFacebook();\n });\n $('a[href=\"#shareOnTelegram\"]').on(\"click\", () => {\n shareOnTelegram();\n });\n $('a[href=\"#shareOnWhatsApp\"]').on(\"click\", () => {\n shareOnWhatsApp();\n });\n}\n\n/**\n * Initiate the module.\n *\n * @param {string} url the referral url\n * @param {string} id the unique id of the template\n */\nexport const init = (url, id) => {\n var strings = [\n {\n key: 'referral_copy_to_clipboard',\n component: 'enrol_wallet'\n },\n {\n key: 'referral_copied',\n component: 'enrol_wallet',\n }\n ];\n get_strings(strings).then(function(results) {\n copyTooltip = results[0];\n copiedTooltip = results[1];\n return true;\n }).fail(() => {\n return false;\n });\n shareUrl = url;\n uniqueId = id;\n copyButtonUrl = document.getElementById('copy_url_' + id);\n copyButtonCode = document.getElementById('copy_code_' + id);\n\n addListeners();\n};"],"names":["copyTooltip","copiedTooltip","shareUrl","copyButtonCode","copyButtonUrl","uniqueId","copyText","target","element","input","navigator","clipboard","writeText","value","setAttribute","prefetchStrings","resetTooltip","addListeners","addEventListener","on","window","open","encodeURIComponent","url","id","key","component","then","results","fail","document","getElementById"],"mappings":";;;;;;;SA+BIA,YACAC,cACAC,SACAC,eACAC,cACAC,kBA4BKC,SAASC,OAAQC,aAClBC,OAAQ,mBAAE,IAAMF,OAAS,IAAMF,UAEnCK,UAAUC,UAAUC,UAAUH,MAAM,GAAGI,OAEvCL,QAAQM,aAAa,UAAWb,0LAxC3Bc,gBAAgB,eAAgB,CAAC,6BAA8B,0BA2ClEC,aAAgBR,UAClBA,QAAQM,aAAa,UAAWd,uBAM3BiB,eACLb,cAAcc,iBAAiB,SAAS,KACpCZ,SAAS,MAAOF,kBAEpBA,cAAcc,iBAAiB,cAAc,KACzCF,aAAaZ,kBAEjBD,eAAee,iBAAiB,SAAS,KACrCZ,SAAS,OAAQH,mBAErBA,eAAee,iBAAiB,cAAc,KAC1CF,aAAab,uCAGf,8BAA8BgB,GAAG,SAAS,KAnD5CC,OAAOC,KADM,gDACQC,mBAAmBpB,UAAW,wBAAyB,+CAsD1E,8BAA8BiB,GAAG,SAAS,KAxC5CC,OAAOC,KAAK,8BAAgCC,mBAAmBpB,kCA2C7D,8BAA8BiB,GAAG,SAAS,KAlD5CC,OAAOC,KAAK,uBAAyBC,mBAAmBpB,4BA6DxC,CAACqB,IAAKC,2BACR,CACV,CACIC,IAAK,6BACLC,UAAW,gBAEf,CACID,IAAK,kBACLC,UAAW,kBAGEC,MAAK,SAASC,gBAC/B5B,YAAc4B,QAAQ,GACtB3B,cAAgB2B,QAAQ,IACjB,KACRC,MAAK,KACG,IAEX3B,SAAWqB,IACXlB,SAAWmB,GACXpB,cAAgB0B,SAASC,eAAe,YAAcP,IACtDrB,eAAiB2B,SAASC,eAAe,aAAeP,IAExDP"} \ No newline at end of file diff --git a/lib.php b/lib.php index b3da7d90..f9e1973f 100644 --- a/lib.php +++ b/lib.php @@ -402,7 +402,7 @@ public function can_add_instance($courseid) { * @param bool $charge Charge the user to enrol (only false in case of enrol coupons) * @return bool|array true if enrolled else error code and message */ - public function enrol_self(stdClass $instance, \stdClass|null $user = null, $charge = true) { + public function enrol_self(stdClass $instance, $user = null, $charge = true) { global $CFG, $DB, $USER; require_once("$CFG->dirroot/enrol/wallet/locallib.php"); if (empty($user)) { diff --git a/templates/referral.mustache b/templates/referral.mustache index 6ef4b642..448f8338 100644 --- a/templates/referral.mustache +++ b/templates/referral.mustache @@ -21,6 +21,11 @@ Example context (json): { + "amount": "50", + "code": "something123", + "url": "https://something.com/login/signup.php?refcode=something123", + "mail_subject": "You got invitation", + "mail_body": "Hello! You got invitation from me. Please use this link to sign" } }}