Best practice forum (Archived)

Adding a custom entry to the rules menu in Dynamic Audiences

 
TaiwoOlumuyiwa
Adding a custom entry to the rules menu in Dynamic Audiences
TaiwoOlumuyiwa 发表于 2017年05月26日 Friday 23:22
小组 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
AngusGeorge 发表于 2017年05月28日 Sunday 19:20
小组 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.

TaiwoOlumuyiwa
Re: Adding a custom entry to the rules menu in Dynamic Audiences
TaiwoOlumuyiwa 发表于 2017年05月28日 Sunday 22:57
小组 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

TaiwoOlumuyiwa
Re: Adding a custom entry to the rules menu in Dynamic Audiences
TaiwoOlumuyiwa 发表于 2017年06月2日 Friday 18:58
小组 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
AngusGeorge 发表于 2017年06月5日 Monday 18:29
小组 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.