Best practice forum (Archived)

Adding a custom entry to the rules menu in Dynamic Audiences

 
Olumuyiwa Taiwo
Adding a custom entry to the rules menu in Dynamic Audiences
بواسطة Friday, 26 May 2017, 11:22 PM - Olumuyiwa Taiwo
مجموعة Partners
I want to add a new entry (rule type) to the dynamic audience menu. The developer documentation at https://help.totaralearning.com/display/DEV/Dynamic+cohorts suggests that should be possible -- it says:


To add a new rule type to the menu:

  1. Identify the sqlhandler and ui you will need for your new rule type. (If no existing ones will work, then you'll need to implement new ones. See below.)

  2. The sqlhandler and ui classes you use must have identical $params values.

  3. Add an entry to $rules

  4. If you've added a new group, define its name string, which will be

get_string(''''rulegroup-\{$group\}''''''''local_cohort'''');

  1. . Define the rule type's name string, which will be

get_string(''''rulename-\{$group\}-\{$name\}'''',''''local_cohort'''');

That's it!


Where it says in step 3 to add an entry to $rules, I'm guessing it's not suggesting that the entry should be added by hacking cohort_rules_list() in  totara/cohorts/rules/setting.php

Can anybody help with information on how to achieve my goal without hacking core code?

Thanks.

me
Re: Adding a custom entry to the rules menu in Dynamic Audiences
بواسطة Sunday, 28 May 2017, 7:20 PM - George Angus
مجموعة Totara

Hi Muyi,

Its not possible at present to do this without modifying core - but we do have Hooks which provides a way for plugins to extend core functionality without needing to modify core code.

We could look at getting your patch included in core if you want to submit it - obviously subject to our QA etc.

cheers,

George.

Olumuyiwa Taiwo
Re: Adding a custom entry to the rules menu in Dynamic Audiences
بواسطة Sunday, 28 May 2017, 10:57 PM - Olumuyiwa Taiwo
مجموعة Partners

Thanks George.

I had assumed that I was missing something blindingly obvious and so hadn't thought of the possibility that a patch might be required. I'll aim to get a patch ready in the next few days and let you know once it's ready.

Thanks again!

Muyi

Olumuyiwa Taiwo
Re: Adding a custom entry to the rules menu in Dynamic Audiences
بواسطة Friday, 2 June 2017, 6:58 PM - Olumuyiwa Taiwo
مجموعة Partners

Hi George,

The attached zip file contains a proposed patch (made against T9.1, Build 20161122.00).

  • The first patch adds a hook call towards the end of totara/cohort/rules/settings.php
  • The second creates the hook class (that will be used by watchers) in totara/cohort/classes/hooks.
me
Re: Adding a custom entry to the rules menu in Dynamic Audiences
بواسطة Monday, 5 June 2017, 6:29 PM - George Angus
مجموعة Totara

Hi Muyi,

Do you have a short spec I can put in our ticket with it? Once I have that Ill submit.

FYI we have a guide here, for any future contributions.

cheers,

George.