Add new category and custom page into Site Administration menu - moodle

I'm trying to add a new feature into site administration menu of moodle as part of a project that I am working on. Right now our customer only needs to integrate OnePay gateway into moodle. But in the future, they may require integration of other payment gateways (like PayPal) as well. So I need to create a category just for website administrators to input different types of payment. A new category should be somewhere in the "Advanced Features" menu (something like in the following screenshots)
Where to add new category
Example for onepay integration
With "Settings" page is a page that site administrator to input all necessary payment information (including customer's card number, access code, etc.). Right now I'm testing with using two of my testing pages for domestic and international payments.
Here is my code in file /lang/en/admin.php:
$string['payment'] = 'Payment';
$string['onepay'] = 'OnePay';
$string['test_onepay_domestic'] = 'Test Domestic Payment using OnePay';
$string['test_onepay_international'] = 'Test International Payment using OnePay';
In admin_custom directory, I created a path like this /payment/onepay/test/ and add 2 my testing pages into it. In folder /payment/, I added a file named menu.php. Here is my code in it.
<?php
$ADMIN->add('advancedfeatures', new admin_category('payment', get_string('payment', 'admin')));
$ADMIN->add('payment', new admin_category('payment', get_string('onepay', 'admin')));
//$domestic = new admin_settingpage('onepay', new lang_string('test_onepay_domestic', 'admin'), new moodle_url("/admin_custom/payment/onepay/test/domestic/index.php"));
//$international = new admin_settingpage('onepay', new lang_string('test_onepay_international', 'admin'), new moodle_url("/admin_custom/payment/onepay/test/international/index.php"));
$domestic = new admin_externalpage('test_onepay_domestic', get_string('test_onepay_domestic'), "$CFG->wwwroot/admin_custom/payment/onepay/test/domestic/index.php");
$international = new admin_externalpage('test_onepay_international', get_string('test_onepay_international'), "$CFG->wwwroot/admin_custom/payment/onepay/test/international/index.php");
$ADMIN->add('onepay', $domestic);
$ADMIN->add('onepay', $international);
I have attempted to include file menu.php in both files
/admin/settings/top.php
/admin/settings/server.php
But none of these works. Can anyone please tell me what should I do to get this works? Thank you very much. I really appreciate that.

Moodle doesn't have any sort of plugin type called 'payment', so by creating a hierarchy starting '/payment', you're already at odds with the way that Moodle works (as shown by needing to edit core files in order to add language strings and menu items).
I would recommend that you start again by creating an admin tool or a local plugin. Both of these types can have their own language strings and can add entries to the site admin menu (have a look at the settings.php inside any of the standard admin tool plugins or, for local plugins, an additional option is to create a local_MYPLUGIN_extend_settings_navigation() function). If you want to support multiple payment options, then your plugin could define a new subplugin type for each of the payment options.

Related

Support multi-site approval based workflow on wagtail

Objective
We would like to setup multi-site wagtail with approval chain.
Develop -> QA -> Release -> Production
Description
A develop / content editor goes to the wagtail admin and creates the content. Once done, sends the request for approval to move to QA site.
QA moderator reviews the content on develop site. If approved, the content gets moved to QA site. The content carries over to next stage approval (release).
Same process ahead for next sites in approval chain.
Questions
Is it possible to setup a publish chain with approval policy in wagtail? I tried to research a bit but could only find "workflow" and "workflow tasks". Do I need to custom code a workflow task to be able to achieve this?
This should be possible but you will need to consider what you really want to do in regards to the 'move' step, do you want to actually move the Page instance to a new site in a new tree or copy the current (and its history) and move that copy Page OR make a copy to put in place of the Page that was moved.
Nonetheless, the documentation on how to add a new Task type is the best place to start, it walks you through custom Task types.
In the solution below however, I thought it would be simplest to create a new model that behaves exactly like GroupApprovalTask (the default task included, used for moderation) but add a field that links it to the Site model.
This way, in the admin UI the admin users can now create as many PublishSiteTask as you want, one for each Site (QA/Dev/Prod etc) and then each of those could be linked to different user groups. It is important to differentiate between the database model (a task type with some fields) and the instances (a task created in the UI) and the actual task instances that are created against each page revision (not page) as the workflow steps progress.
Code Example
models.py
from django.db import models, transaction
from wagtail.core.models import GroupApprovalTask, Page, Site
# ... other imports
class PublishSiteTask(GroupApprovalTask):
site = models.OneToOneField(Site, on_delete=models.CASCADE)
admin_form_fields = ['site'] + GroupApprovalTask.admin_form_fields
#transaction.atomic
def on_action(self, task_state, user, action_name, **kwargs):
"""Performs an action on a task state determined by the ``action_name`` string passed"""
if action_name == 'approve':
# get the page that this action is referring to via the task_state.page_revision
page = task_state.page_revision.as_page_object()
# find the new parent target at this task's site
# how this is done depends on the site/page structure
new_parent_target = self.site.root_page
# move the page to a new location
# note: this will actually move it from its current tree, you may want to make a copy first
page.move(new_parent_target)
# be sure to preserve any existing task behaviour
super().on_action(task_state, user, action_name, **kwargs)
Additional Links
Task class definition
GroupApprovalTask class definition
You may want to do some pre-work in the code to check that the page can actually move to the different Site, each Page has a method can_move_to that could help.
The move method referenced above is part of the Wagtail code but the full docs for that method can be found in the Treebeard API docs which Wagtail uses to manage the tree structure.

Sitecore - WFFM : Link contact facet with user profile field

I'm working on a Sitecore 8 Update 2 site.
I'm also using the web forms for marketers.
I've set up a login and register form using WFFM. I was able to link fields on the form with the fields of the user profile ( the one used in User Management )
However when i want to make a "Update Contact Details" i can't link the fields on the form with the profile fields as before. Now i have to select a "contact facet". I added one of these and WFFM picked up on this, so now i can link the field on the form with a facet.
The last link i'm missing is linking this facet ( stored in Analytics - MongoDB ) to the profile field.
Does anyone know how to achieve this ?
Bonus: This started off as a slighty different question, you can read more about this issue here:
How to update sitecore user with webforms for marketers ( Update Contact Details )
First you need to add the Create User Save Action and setup the email address as the username.
Then you need to add the User login Save Action straight after that. This is because the Update Contact Details Save action only applies to logged in users.
Then you can use the Update Contact Details Save Action. This action will create data in MongoDB under the logged in user name - so if you go to the Identifiers collection MongoDB a new entry will be created (See screen shot below).
So in short the aspnet_membership data and the MongoDB data is linked via the username in WFFM. In aspnet_users - UserName and in MongoDB by way of an identifier. You can't mix the MongoDB and aspnet_profile data they belong in two separate places.
So once you have created this user in WFFM you could call up their details using the analytics API using the identifier:
Tracker.Current.Session.Identify(username);
var personalInfo = Tracker.Current.Contact.GetFacet<IContactPersonalInfo>("Personal");
Hope that makes sense :)

Implement Inbox Functionality in custom cq component?

We want to develop a smooth-flowing workflow experience (but still use workflows). Currently, a user needs to use the sidekick to initiate the workflow, then to the inbox, which takes them back to the page to use the sidekick again. When they go to the inbox, they need to restrict to the model and path of the page. It would be nice for the user to only have to go to the content page and from there, launch the different workflow forms that need to happen, like a little "inbox" right on the page that is subject to the workflow.
I have written a custom component that can initiate the custom workflow. The custom component can also query the WorkFlowSession and obtain any active WorkItems for the current page that the component resides (using the WorkItemFilter interface). What I want to do is provide a link to the user to the next step in the workflow from the custom component, just like the inbox does.
Here is an example output from an WorkItem instance toString method:
21.05.2014 09:45:29.300 *ERROR* [0:0:0:0:0:0:0:1%0 [1400679929160] GET /content/test/mailing1.html HTTP/1.1] org.rand.whatcounts.EmailCampaignCoordinator Found workitem: -----------------------------
WorkItem Id: /etc/workflow/instances/2014-05-21/model_1400679794564399000/workItems/node4_etc_workflow_instances_2014-05-21_model_1400679794564399000
Workflow Id: /etc/workflow/instances/2014-05-21/model_1400679794564399000
Payload: /content/test/mailing1
Payload Type: JCR_PATH
key = historyEntryPath value = /etc/workflow/instances/2014-05-21/model_1400679794564399000/history/1400679924113
key = comment value =
My hope is that by using the workflow api items, I can create the link that the user could click on to proceed in the workflow (just like the inbox).
Thanks for listening!
Phillip
There are two ways to implement this
Java-Based Solution
I was able to figure out one way by looking at
http://localhost:4502/libs/cq/workflow/components/inbox/list/json.jsp
The important part of this jsp is that, given a workItem instance, you can get the path for your next step using the JcrPathBuilderManager:
pathBuilder.getPath(wi);
Using this, I was able to output a link to the next step in the workflow to the user (without having user go to their inbox).
Javascript/JSON Based Solution
I didn't go far with this solution (I didn't write any js) but this was my fall back position if I didn't find the java-solution listed above. Once could implement custom JS in CQ Component that would call the json feed for the user inbox, do some client side filtering (to restrict it to only items related to current page). The URL to the feed is
http://localhost:4502/libs/cq/workflow/content/inbox/list.json?start=0&limit=40
Thanks!

SUGARCRM plugin - webservice client with setup

I have a task to develop plugin for SugarCRM. Plugin should be "hooked" to contacts, leads and/or targets.
After I add contact to SugarCRM plugin should send data (with some fileds) to specific webservice (method to insert new person into DB).
I did create logical hook to contacts and before save I send data to webservice.
My biggest problem are fields. SugarCRM admin should be able to make setup for plugin like this
Plugin gets list of fields from webservice
Admin maps fields from "SugarCRM contacts" to "webservice persons" fields
for example
SugarCRM contact | webservice person
"first_name" => "firstname"
"last_name" => "familyname"
"gender" => "mf"
....
So when contact is added to SugarCRM, plugin should be able to read this setup and match every field before sending to webservice.
Can someone give me tips how to start with this, is there something similar online?
Thanks
You could create a dropdown menu where the left value is the SugarCRM Field name and the right value is the Webservice field name. Then direct users/system administrator to modify this dropdown in the Dropdown Editor, which has a nice and easy interface.
The plugin can then access this menu as a key => value array with $GLOBALS['app_list_strings']['my_list_name']
Alternatively, you can create your own configuration page if you want to develop a custom interface for this. A starting point for that might be this article, although it was written with SugarCRM 6 in mind: http://www.profilingsolutions.com/archive/quick-configuration-pages/
The configuration page would write to the Configurator (stored in config_override.php), as Antonio Musarra pointed out.
Either way, a caveat you'll encounter is that users will mistype field names. You'll need some sort of validation in your webservice call to ensure that all fields actually exist within the web server and within SugarCRM.

Drupal email users

I'm using Drupal 6.16: When a user creates an account on my site I have them select a category (ie children, youth, adult, etc). This is done with the select list box using the content_profile module. I have a content type that posts an announcement. In this content type is a check box that says 'email group'. Right now it does nothing, but what I would like for it to do is e-mail all the users that are associated with the group they chose when signing up for their account. If this will require extra code please be specific as I am not a strong php programmer.
Thanks for the help!!
msindle
There might be some module that do it exactly, but I don't think so.
I would have done it using few building blocks:
Retrieve the list of emails using Views - define a view that gives you the addresses according to a given group argument.
Use Rules module that will send an email notification after node is created.
Combine the two (this is the hard part) - insert the values from the view as the recipients for the email. You might be able to do it using PHP inside the Rule definition, plus view execution.
Try to accomplish it, and if you get into troubles, you are welcome to contact me via shushu.i#gmail.com
I would try http://drupal.org/project/subscriptions module + http://drupal.org/project/messaging module. You can set preferences for automatic subscribing to content type. Maybe Rules module can subscribe users automatically after creating or updating content_profile. Or maybe Rules can flag users after creating or updating content_profile and Subscription module could autosubscribe flagged users.