How to crete New Web Service inside moodle? - moodle

I am go through the service module inside moodle , how can i add my own function and class for handling some operations such as enrolling and register . is it possible or not

You need to create a new plugin (probably a 'local' plugin) and add a webservice within it:
https://docs.moodle.org/dev/Adding_a_web_service_to_a_plugin

this might help
https://docs.moodle.org/dev/Web_service_API_functions
even this---
https://docs.moodle.org/31/en/Using_web_services

I created a new web service "core_completion_override_course_completion_status"
Duplicate any existing web service and replace the words as per your need in the method name, class name etc.
Increate Moodle main version from version.php in root moodle folder.

Related

Creating moodle plugin to accept REST calls and create activities/notice/files

Im quite new to moodle development. Im trying to post activity/notice to a selected course. I could not find any webservice for creating activities within a course. Is there any way i could create a plug-in where i could make a REST call to the plug so that it would create a notice?. An example would help allot.
STEP 1
To create local plugin you can follow following folder structure according to Moodle documentation (https://docs.moodle.org/dev/Local_plugins)-
local/
yourplugin/
db/
access.php
install.php
install.xml
lang/
en/
yourplugin.php
index.php
settings.php
version.php
Meanwhile, creating local plugin does not always really solve all problems as there are limitation depending what you really want to achieve.
what worked for me was editing //moodle_dir/course/modedit.php file, and i was able to make REST Call to add scorm activity to any course i want.

Creating new form in moodle

I have created a new module in moodle from the link New Module. I have installed that as well and it is showing up in the Administration ->Activities.
How to add a new form against that module to get the user inputs?
Please check the mod_form.php in the documentation. This is used to add an instance of the new activity. Please check the existing modules also.

How can I create new Resource in Moodle?

I have to create new Resource in Moodle (currently available resources are Book, File, Label etc). I know how to create an activity module in Moodle. I think both activity and resource are created in similar way. Then how can I align the newly created resource below the RESOURCES section(while adding the activity/resource in course).
Please help me to find any link/suggestion regarding to create resources in Moodle....
In your plugin's PLUGINNAME_supports function, just return MOD_ARCHETYPE_RESOURCE when asked about feature FEATURE_MOD_ARCHETYPE.
See example at the start of the mod/page/lib.php file -https://github.com/moodle/moodle/blob/master/mod/page/lib.php

External access to Magento instances

I've started investigating alternatives to my project and a few questions came out that I couldn't answer by myself.
The problem is: I want to create a web page able to access multiple Magento instances installed in the same server. Currently, I have one Magento instance per client and this project will access several Magneto instances to export reports from each one (for example).
The alternatives I thought til this moment are:
Have another Magento instance, create a new module within it that changes its 'database target' before triggering operations/queries;
Questions until this moment:
Can I 'change the database target' of a Magento instance?
How can I access data from a Magento instance without appeal to SOAP/REST?
I want to re-use some components (grids, tabs, forms..) from Magento, that's why I'm not considering an independent project (Zend, for instance) that can access this code from another projects. Does it make sense?
Any other idea?
==Edited==
Thanks by the tips and sorry by my ignorance. The comments let me believe that I'm able to execute something like this:
// File myScript.php
require '/home/DOMAIN1/app/Mage.php';
Mage::app('default');
// get some products from DOMAIN1
require '/home/DOMAIN2/app/Mage.php';
Mage::app('default');
// get some products from DOMAIN2
Is it right? Can I execute require twice (and override things from first require)?
==Edited2==
I'm still trying to connect to several Magento instances from a single third party file. Is there any tip? I'm facing several/different errors at this moment.
The only thing I know is that I can still rely on SOAP to get the information I need, but this will be expensive.
Thanks!
The easiest way would be to include Mage.php from each shop instance. You would need to use namespaces or some other trickery to be able to load more then one.
Or if that doesn't work - make your own API in a separate file to get what you want from one shop, and combine the results in the PHP-file that calls the API.
Here's a sample on how to use Magento functionality outside of Magento:
require 'app/Mage.php';
if (!Mage::isInstalled()) {
echo "Application is not installed yet, please complete install wizard first.";
exit;
}
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// your custom code here, for example, get the product model..
$productModel = Mage::getModel('catalog/product');

Creating a site in alfresco using open cmis extension

I want to create a alfresco site using open cmis extension. I researched and found an object type 'F:st:sites' and its properties like 'st:siteVisibility' and 'st:sitePreset'. But I am not very sure that using this we can create a site in alfresco and I am not able to find any method for creating a site. It could be something like
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "mySiteName");
properties.put(PropertyIds.OBJECT_TYPE_ID, "F:st:sites");
properties.put("cmis:path", "/Sites");
.
.
properties.put("cmis:createdBy", date);
properties.put("st:siteVisibility", ScriptSiteService.PUBLIC_SITE);
// TODO: add method for creating site with session object
Please reply as soon as possible.
Also, if there is any other way to create a site other than apache's Http api, Please share.
Thanks,
Smita
as long as you don't post your use case, yourfull code & explain in in detail what tools you're using (Apache Chemistry/opencmis? apache's Http api?) you won't get the answer you like to get...
A Site is sth. like a extended folder & there will be an opportunity to create such a folder by using st:site type & adding the relevant properties, BUT:
afaik you won't be able to use this site via Alfresco Share because all SURF objects are not created if you create a site directly in the repo layer (explained here (but a little bit outdated if you use Alfresco 4): http://ecmstuff.blogspot.de/2011/02/creating-alfresco-share-sites-with.html).