diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00cf5ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +.idea +*.swp +*.bak +vendor +composer.phar +composer.lock +ehthumbs.db +config.php +upgrading.php +phpunit.phar +phpunit.xml +_files +local diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff17cec --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ + +Tsugi PHP Sample Module +======================= + +This is a component of the [Tsugi PHP Project](https://github.com/tsugitools/tsugi). + +There are two ways to use the Tsugi library/framework: + +* You can build a "Tsugi Module" from scratch following all of the +Tsugi style guidance, using the Tsugi browser environment, and +making full use of the Tsugi framework - this repository contains +a basic "Tsugi Module" you can use as a starting point. + +* You can use Tsugi more like a library and add it to an existing +application. We also have starting code for +[Using Tsugi With an Existing Application](https://github.com/tsugiproject/tsugi-php-standalone) + +Both of these approaches depend on the +[Tsugi Devloper/Admin Console](https://github.com/tsugiproject/tsugi) +for database configuration, setup, developer test harness, +CASA support, Content Item Support, etc. + +The idea is that when you are starting a new Tsugi Module, you download +the code for this application as your starting point and then edit from there. +It is probably a bad idea to fork this repository as you don't really want to +track updates to this sample code. + +Simple Installation +------------------- + +In the simple installation scenario, you have installed and configured +Tsugi to a folder like: + + htdocs/tsugi + +Since Tsugi can be configured to discover PHP tools in lots of folders, you +could check this code out into one of several places: + + htdocs/tsugi/mod/tsugi-php-module + htdocs/tsugi/tsugi-php-module + htdocs/tsugi-php-module (suggested) + htdocs/php-intro/tools/tsugi-php-module + +Once you have checked this code out, you need to make a config.php that +simply includes the `config.php` from the Tsugi directory. There is +already a `config.php` that paints to the Tsugi configuration if you +are in the suggested location of a peer folder. + + tool_folders` parameter in the +Tsugi `config.php` file to include the relative path to this tool. + + $CFG->tool_folders = array("admin", "mod", ... , + "../tsugi-php-module"); + +Once you have connected this tool to a Tsugi install as described above, +you can use the Admin/Database Upgrade feature to create / maintain database +tables for these tools. You can also use the Developer mode of that Tsugi to +test launch this tool. The LTI 2.0 support, CASA Support, and Content Item +support for the controlling Tsugi will know about this tool. + +Launching and Testing This Code +------------------------------- + +To launch the tools (assuming installed as described above) go to: + + http://localhost/tsugi/dev.php + http://localhost:8888/tsugi/dev.php (for MAMP) + +And all these tools should show up in the drop-down for easy testing +and launching. + +Tsugi Developer List +-------------------- + +Once you start developing Tsugi Applications or Modules, you should join the Tsugi +Developers list so you can get announcements when things change. + + https://groups.google.com/a/apereo.org/forum/#!forum/tsugi-dev + +Once you have joined, you can send mail to tsugi-dev@apereo.org + +Advanced Installation +--------------------- + +If you are going to install this tool in a web server that does not +already have an installed copy of Tsugi, it is a bit trickier. There +is no automatic connection between Tsugi developer tools and Tsugi admin +tools won't know about this tool. + +To run this Tsugi Module as standalone, you should read and adapt the installation +steps in the +[Advanced Installation](https://github.com/tsugiproject/tsugi-php-standalone#advanced-installation) +section of the +[Using Tsugi With an Existing Application](https://github.com/tsugiproject/tsugi-php-standalone) +respository. + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9da6278 --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "curriki/currikitsugi", + "description": "This tool provide Curriki Programs/Playlist/Activity", + "autoload": { + "psr-4": { + "CurrikiTsugi\\":"src/" + } + }, + "require": { + "pimple/pimple": "~3.0", + "symfony/http-foundation": "^5.1" + } +} diff --git a/database.php b/database.php new file mode 100644 index 0000000..b1a569f --- /dev/null +++ b/database.php @@ -0,0 +1,31 @@ +dbprefix}curriki" +); + +// The SQL to create the tables if they don't exist +$DATABASE_INSTALL = array( +array( "{$CFG->dbprefix}curriki", +"create table {$CFG->dbprefix}curriki ( + link_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + entity TEXT NOT NULL, + entity_id INTEGER NOT NULL, + updated_at DATETIME NOT NULL, + + CONSTRAINT `{$CFG->dbprefix}curriki_ibfk_1` + FOREIGN KEY (`link_id`) + REFERENCES `{$CFG->dbprefix}lti_link` (`link_id`) + ON DELETE CASCADE ON UPDATE CASCADE, + + CONSTRAINT `{$CFG->dbprefix}curriki_ibfk_2` + FOREIGN KEY (`user_id`) + REFERENCES `{$CFG->dbprefix}lti_user` (`user_id`) + ON DELETE CASCADE ON UPDATE CASCADE, + + UNIQUE(link_id, user_id) +) ENGINE = InnoDB DEFAULT CHARSET=utf8") +); + diff --git a/index.php b/index.php new file mode 100644 index 0000000..2e3d1df --- /dev/null +++ b/index.php @@ -0,0 +1,54 @@ + 'text/html'] + ); + return $response; +}; + +$container[Launch::class] = function($c){ + $lti_launch = LTIX::requireData(); + return $lti_launch; +}; + +$container[ControllerInterface::class] = function($c){ + $controller = null; + if(isset($_REQUEST['ctrl'])){ + $controller_name = "CurrikiTsugi\Controllers\\"; + $controller_name_parts = explode('-',$_REQUEST['ctrl']); + + $controller_name_parts = array_map(function($item){return ucfirst($item);}, $controller_name_parts); + $controller = $controller_name.implode('',$controller_name_parts); + if (class_exists($controller)) { + $controller = new $controller($c[Request::class], $c[Response::class]); + } + } + return $controller; +}; + +$container[App::class] = function($c){ + return new App($c[Launch::class], $c[ControllerInterface::class]); +}; + +$app = $container[App::class]; +$app->bootstrap(); diff --git a/register.php b/register.php new file mode 100644 index 0000000..b8e8400 --- /dev/null +++ b/register.php @@ -0,0 +1,10 @@ + "Curriki", +"FontAwesome" => "fa-graduation-cap", +"short_name" => "Curriki", +"description" => "This tool provide Curriki Programs/Playlist/Activity", +"messages" => array("launch", "launch_message") +); + diff --git a/src/App.php b/src/App.php new file mode 100644 index 0000000..2ef8ad4 --- /dev/null +++ b/src/App.php @@ -0,0 +1,28 @@ +lti_launch = $lti_launch; + $this->controller = $controller; + } + + public function bootstrap() + { + if(!is_null($this->controller)){ + + if (isset($_GET['act']) && method_exists($this->controller, $_GET['act'])) { + call_user_func(array($this->controller, $_GET['act'])); + }else { + call_user_func(array($this->controller, 'index')); + } + }else { + $this->lti_launch->var_dump(); + } + } +} diff --git a/src/Controllers/RegisterPlatform.php b/src/Controllers/RegisterPlatform.php new file mode 100644 index 0000000..f75b67a --- /dev/null +++ b/src/Controllers/RegisterPlatform.php @@ -0,0 +1,29 @@ +request = $request; + $this->response = $response; + } + + public function index() + { + $issureRespository = new IssureRepository(); + $data = []; + $issureRespository->create($data); + echo "me index...."; + var_dump($this->request->query->get('ctrl')); + } + + public function store() + { + echo 'me store....'; + } +} + diff --git a/src/Interfaces/ControllerInterface.php b/src/Interfaces/ControllerInterface.php new file mode 100644 index 0000000..3136e66 --- /dev/null +++ b/src/Interfaces/ControllerInterface.php @@ -0,0 +1,6 @@ +rowDie("SELECT issuer_id, issuer_key, issuer_client, issuer_sha256, lti13_keyset_url, lti13_token_url, lti13_token_audience, lti13_oidc_auth, lti13_platform_pubkey, lti13_pubkey, lti13_privkey, created_at, updated_at FROM lti_issuer WHERE issuer_key = :KEY", array('KEY' => $key)); + return $row; + } + + public function create($data) + { + $issure = $this->getByKey("http://moodlemac.local:82820"); + if(!$issure){ + die('do create'); + } + } +}