I am working on integration of moodle with openerp.
Is there any function in moodle for create_assignment in moodle webservice. I found moodle_assign_get_assignment function in External service of moodle. But i wants create_assignmet function. Help me about this.
Using Moodle 2.8.x, have you tried assignment_add_instance?
I haven't yet but I use PHPStorm as an IDE and it hooks into all the Moodle API functions. So I just typed "assignment" and found that.
It is located in mod/assigment.lib.php line 36 and looks like this:
function assignment_add_instance($assignment, $mform = null) {
global $DB;
$assignment->timemodified = time();
$assignment->courseid = $assignment->course;
$returnid = $DB->insert_record("assignment", $assignment);
$assignment->id = $returnid;
return $returnid;
}
What I tend to do is I create an assignment on a test version of my Moodle, intercept the form before it submits and var dump the submitted form so you can see what you have to send into the function for it to work.
Good luck.
Of course, it may be:
function assign_add_instance(stdClass $data, mod_assign_mod_form $form = null) {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assignment = new assign(context_module::instance($data->coursemodule), null, null);
return $assignment->add_instance($data, true);
}
That you have to call instead - cant remember which one superseded the other...
Related
I am using PrestaShop 1.6.1.0
I have a field in my module supporting different languages, the postProcess() looks like this:
protected function postProcess()
{
$languages = Language::getLanguages(false);
$values = array();
foreach ($languages as $lang)
{
$values['CUSTOMPAGECONFIGURATION_HEADING_TEXT'][$lang['id_lang']] = Tools::getValue('CUSTOMPAGECONFIGURATION_HEADING_TEXT_'.$lang['id_lang']);
}
Configuration::updateValue('CUSTOMPAGECONFIGURATION_HEADING_TEXT', $values['CUSTOMPAGECONFIGURATION_HEADING_TEXT'], true);
return $this->displayConfirmation($this->l('The settings have been updated.'));
}
Problem:
When I try to get this configuration variable value in a custom controller (path: /controllers/front/CustomPageController.php) like shown below, it is not fetching any results:
$headtxt = Configuration::get('CUSTOMPAGECONFIGURATION_HEADING_TEXT');
print_r($headtxt);
exit;
It is not printing anything. I want to fetch this value in a controller, but it does not work and returns an empty string.
Site is using PrestaShop 1.6.1.0 and I tried many codes available. Am I missing something?
I am using this code in new controller created by me for custom page:
$headtxt = Configuration::get('CUSTOMPAGECONFIGURATION_HEADING_TEXT');
print_r($headtxt);
exit;
I expect to output results of configuration variable which saved by the postProcess() method.
Hi #Ankur and Welcome to SO!
In your postProcess() method, you are saving this Configuration value as a multilingual value.
However, while calling the Configuration::get() static method, it seems to me you forgot to mention the language ID, here's the function prototype:
public static function get($key, $idLang = null, $idShopGroup = null, $idShop = null, $default = false)
This should work:
$id_lang = (int)$this->context->cookie->id_lang
$headtxt = Configuration::get('CUSTOMPAGECONFIGURATION_HEADING_TEXT', $id_lang);
print_r($headtxt);
exit;
I want to get Call Details from Genesys Platform SIP Server.
And Genesys Platform has Platform SDK for .NET .
Anybod has a SIMPLE sample code which shows how to get call details using Platform SDK for .NET [ C# ] from SIP Server?
Extra Notes:
Call Details : especially i wanted to get AgentId for a given call
and
From Sip Server : I am not sure if Sip Server is the best candiate to
take call details. So open to other suggestions/ alternatives
You can build a class that monitor DN actions. Also you watch specific DN or all DN depending what you had to done. If its all about the call, this is the best way to this.
Firstly, you must define a TServerProtocol, then you must connect via host,port and client info.
var endpoint = new Endpoint(host, port, config);
//Endpoint backupEndpoint = new Endpoint("", 0, config);
protocol = new TServerProtocol(endpoint)
{
ClientName = clientName
};
//Sync. way;
protocol.Open();
//Async way;
protocol.BeginOpen();
I always use async way to do this. I got my reason thou :) You can detect when connection open with event that provided by SDK.
protocol.Opened += new EventHandler(OnProtocolOpened);
protocol.Closed += new EventHandler(OnProtocolClosed);
protocol.Received += new EventHandler(OnMessageReceived);
protocol.Error += new EventHandler(OnProtocolError);
Here there is OnMessageReceived event. This event where the magic happens. You can track all of your call events and DN actions. If you go genesys support site. You'll gonna find a SDK reference manual. On that manual quiet easy to understand there lot of information about references and usage.
So in your case, you want agentid for a call. So you need EventEstablished to do this. You can use this in your recieve event;
var message = ((MessageEventArgs)e).Message;
// your event-handling code goes here
switch (message.Id)
{
case EventEstablished.MessageId:
var eventEstablished = message as EventEstablished;
var AgentID = eventEstablished.AgentID;
break;
}
You can lot of this with this usage. Like dialing, holding on a call inbound or outbound even you can detect internal calls and reporting that genesys platform don't.
I hope this is clear enough.
If you have access to routing strategy and you can edit it. You can add some code to strategy to send the details you need to some web server (for example) or to DB. We do such kind of stuff in our strategy. After successful routing block as a post routing strategy sends values of RTargetPlaceSelected and RTargetAgentSelected.
Try this:
>
Genesyslab.Platform.Contacts.Protocols.ContactServer.Requests.JirayuGetInteractionContent
JirayuGetInteractionContent =
Genesyslab.Platform.Contacts.Protocols.ContactServer.Requests.JirayuGetInteractionContent.Create();
JirayuGetInteractionContent.InteractionId = "004N4aEB63TK000P";
Genesyslab.Platform.Commons.Protocols.IMessage respondingEventY =
contactserverProtocol.Request(JirayuGetInteractionContent);
Genesyslab.Platform.Commons.Collections.KeyValueCollection keyValueCollection =
((Genesyslab.Platform.Contacts.Protocols.ContactServer.Events.EventGetInteractionContent)respondingEventY).InteractionAttributes.AllAttributes;
We are getting AgentID and Place as follows,
Step-1:
Create a Custome Command Class and Add Chain of command In ExtensionSampleModule class as follows,
class LogOnCommand : IElementOfCommand
{
readonly IObjectContainer container;
ILogger log;
ICommandManager commandManager;
public bool Execute(IDictionary<string, object> parameters, IProgressUpdater progress)
{
if (Application.Current.Dispatcher != null && !Application.Current.Dispatcher.CheckAccess())
{
object result = Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new ExecuteDelegate(Execute), parameters, progress);
return (bool)result;
}
else
{
// Get the parameter
IAgent agent = parameters["EnterpriseAgent"] as IAgent;
IIdentity workMode = parameters["WorkMode"] as IIdentity;
IAgent agentManager = container.Resolve<IAgent>();
Genesyslab.Desktop.Modules.Core.Model.Agents.IPlace place = agentManager.Place;
if (place != null)
{
string Place = place.PlaceName;
}
else
log.Debug("Place object is null");
CfgPerson person = agentManager.ConfPerson;
if (person != null)
{
string AgentID = person.UserName;
log.DebugFormat("Place: {0} ", AgentID);
}
else
log.Debug("AgentID object is null");
}
}
}
// In ExtensionSampleModule
readonly ICommandManager commandManager;
commandManager.InsertCommandToChainOfCommandAfter("MediaVoiceLogOn", "LogOn", new
List<CommandActivator>() { new CommandActivator()
{ CommandType = typeof(LogOnCommand), Name = "OnEventLogOn" } });
enter code here
IInteractionVoice interaction = (IInteractionVoice)e.Value;
switch (interaction.EntrepriseLastInteractionEvent.Id)
{
case EventEstablished.MessageId:
var eventEstablished = interaction.EntrepriseLastInteractionEvent as EventEstablished;
var genesysCallUuid = eventEstablished.CallUuid;
var genesysAgentid = eventEstablished.AgentID;
.
.
.
.
break;
}
Concerning the new Paypal SDK, there is almost no useful example code, and the Internet is littered with examples of the old SDK. My question concerns making an API request for a third party paypal account for which i have obtained the token and secretToken through the permissions API.
In attempting to construct a PPAPIService object, where is the list of possible sevice names?
ie: $this->serviceName = $serviceName; (in the constructor) What is the string syntax for these?
In regards to the makeRequest method, how do I define the $apiMethod variable, and what is the format of the $params variable? What are the different parameters?
A simple example of how to just obtain the account balance of the authorized third party account would be extremely helpful.
I am using PHP.
from the PPAPIService.php file:
class PPAPIService
{
public $endpoint;
public $serviceName;
private $logger;
public function __construct($serviceName = "")
{
$this->serviceName = $serviceName; //is there ANY documentation about the syntax and types of service names?
$config = PPConfigManager::getInstance();
$this->endpoint = $config->get('service.EndPoint');
$this->logger = new PPLoggingManager(__CLASS__);
}
public function setServiceName($serviceName)
{
$this->serviceName = $serviceName;
}
public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
{
//what are the apiMethod types? syntax? and params? type.. options...??
}
}
Well, you do not have to create a PPAPIService object directly. Let's say you want to use the Invoicing SDK, here's what you would do
$invoiceService = new InvoiceService();
$invoiceService->setAccessToken($accessToken);
$invoiceService->setTokenSecret($tokenSecret);
$createInvoiceResponse = $invoiceService->CreateInvoice($createInvoiceRequest);
There's one service class (such as InvoiceService in this code snippet) per API that you would instantiate as per your needs. The API username/password are picked from the configuration file and the access token/token secret are set via code since they typically tend to be different for different invocations.
Which API are you trying to call, by the way?
To answer on your other concern, the new PayPal SDK's have all the required samples bundled within the SDK itself. The SDK + Samples canbe downloaded from
https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index
When javascript is run in the browser there is no need to try and hide function code because it is downloaded and viewable in source.
When run on the server the situation changes. There are use cases such as api where you want to provide users with functions to call without allowing them to view the code that which is run.
On our specific case we want to execute user submitted javascript inside node. We are able to sandbox node.js api however we would like to add our own api to this sandbox without users being able to toString the function to view the code which is run.
Does anyone have a pattern or know of a way of preventing users from outputting a functions code?
Update:
Here is a full solution (i believe) based on the accepted answer below. Please note that although this is demonstrated using client side code. You would not use this client side as someone can see the contents of your hidden function by simply reading the downloaded code (although it may provide some basic slow down to inspect the code if you have used a minify).
This is meant for server side use where you want to allow users to run api code within a sandbox env but not allow them to view what the api's do. The sandbox in this code is only to demonstrate the point. It is not an actual sandbox implementation.
// function which hides another function by returning an anonymous
// function which calls the hidden function (ie. places the hidden
// function in a closure to enable access when the wraped function is passed to the sandbox)
function wrapFunc(funcToHide) {
var shownFunc = function() {
funcToHide();
};
return shownFunc;
}
// function whose contents you want to hide
function secretFunc() {
alert('hello');
}
// api object (will be passed to the sandbox to enable access to
// the hidden function)
var apiFunc = wrapFunc(secretFunc);
var api = {};
api.apiFunc = apiFunc;
// sandbox (not an actual sandbox implementation - just for demo)
(function(api) {
console.log(api);
alert(api.apiFunc.toString());
api.apiFunc();
})(api);
If you wrap a callback in a function, you can use another function in that scope which is actually hidden from the callback scope, thus:
function hideCall(funcToHide) {
var hiddenFunc = funcToHide;
var shownFunc = function() {
hiddenFunc();
};
return shownFunc;
}
Then run thusly
var shtumCallBack = hideCall(secretSquirrelFunc);
userCode.tryUnwindingThis(shtumCallBack);
The userCode scope will not be able to access secretSquirrelFunc except to call it, because the scope it would need is that of the hideCall function which is not available.
I have 4.5 years experience as a professional PHP developer, I have loads of experience with session handling, etc.
I am wanting to learn how to build Facebook applications. I have gone through the process of downloading the Facebook Developer application, I have used to it Create an App, I have set the canvas URL to where the app is hosted.
I can successfully "install" the app using a Facebook user account, and I can successfully access it. I have noted that when the app is loaded, a whole string of data gets passed to it, with parameter names like fb_sig_user and fb_sig_session_key. Currently, I am doing nothing with these parameters.
On the application end, obviously I am supposed to create a Facebook object by using my own APP ID key and SECRET key, which I have done.
But I can't seem to figure out how to start making API calls from my application back to Facebook.
How do I, at this point, just do something simple like get the person's name and display it to them?
Eg, how do I:
$first_name = $facebook->getUserFirstName();
.. do something like that?
I just want to do a simple test to ensure the API stuff is working.
Any help would be appreciated. Thanks.
The Facebook PHP SDK would probably be your first stop, with some example code as a close runner up.
Making API calls with the Facebook SDK set up alright is as easy as;
$me = $facebook->api('/me'); // Returns array containing data for currently logged in user depending on given permissions
or
$my_friends = $facebook->api('/me/friends'); // Returns array containing information on friends of currently logged in user
and even
$my_profile_img = $facebook->api('/me/picture'); // Returns a string containing URL to users profile picture.
Also, everything within the open graph has unique id's that you can plug in instead of me in /me.
For further and more in-depth description of the Open Graph, I suggest going to the official Graph API Overview page.
Quite easy and fun to work with once you get it set up - albeit a bit slow.
Update:
In order to get the Facebook cookie and set up a session from it I did:
$cookie = get_facebook_cookie($fbconfig['appid'], $fbconfig['secret']);
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
if (isset($cookie)) {
$session = $facebook->getSession($cookie);
}
Then updated Facebook.php line 332 to be
public function getSession($passedCookie) {
and line 373 to be
$this->setSession($passedCookie, $write_cookie);
Lame hacking, but it worked for me at least