From 049580fd3012e7ca61dd6f0499d7baa636926e86 Mon Sep 17 00:00:00 2001 From: koldoa Date: Tue, 1 Sep 2015 18:33:26 +0200 Subject: [PATCH] Random strategy for ring groups --- app/ring_groups/app_languages.php | 11 ++++++++ app/ring_groups/ring_group_edit.php | 1 + .../install/scripts/app/ring_groups/index.lua | 27 ++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/ring_groups/app_languages.php b/app/ring_groups/app_languages.php index 41e87e22f2..4ce8421826 100644 --- a/app/ring_groups/app_languages.php +++ b/app/ring_groups/app_languages.php @@ -88,6 +88,17 @@ $text['option-rollover']['uk'] = ""; $text['option-rollover']['de-at'] = "Überrollen"; $text['option-rollover']['he'] = ""; +$text['option-random']['en-us'] = "Random"; +$text['option-random']['es-cl'] = "Aleatorio"; +$text['option-random']['pt-pt'] = ""; +$text['option-random']['fr-fr'] = ""; +$text['option-random']['pt-br'] = ""; +$text['option-random']['pl'] = ""; +$text['option-random']['sv-se'] = ""; +$text['option-random']['uk'] = ""; +$text['option-random']['de-at'] = ""; +$text['option-random']['he'] = ""; + $text['option-ptring']['en-us'] = "pt-ring"; $text['option-ptring']['es-cl'] = "pt-ring"; $text['option-ptring']['fr-fr'] = "Portugal"; diff --git a/app/ring_groups/ring_group_edit.php b/app/ring_groups/ring_group_edit.php index 9d7083e70e..929f7086d6 100644 --- a/app/ring_groups/ring_group_edit.php +++ b/app/ring_groups/ring_group_edit.php @@ -499,6 +499,7 @@ else { echo " \n"; echo " \n"; echo " \n"; + echo " \n"; echo " \n"; echo "
\n"; echo $text['description-strategy']."\n"; diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index 336f5ace28..b122bc371a 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -160,6 +160,28 @@ --forward the ring group session:execute("transfer", ring_group_forward_destination.." XML "..context); else + --get the strategy of the ring group, if random, we use random() to order the destinations + sql = [[ + SELECT + r.ring_group_strategy + FROM + v_ring_groups as r, v_ring_group_destinations as d + WHERE + d.ring_group_uuid = r.ring_group_uuid + AND d.ring_group_uuid = ']]..ring_group_uuid..[[' + AND r.domain_uuid = ']]..domain_uuid..[[' + AND r.ring_group_enabled = 'true' + ]]; + + --freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n"); + assert(dbh:query(sql, function(row) + if (row.ring_group_strategy == "random") then + sql_order = 'random()' + else + sql_order='d.destination_delay, d.destination_number asc' + end + end)); + --get the ring group destinations sql = [[ SELECT @@ -174,7 +196,7 @@ AND r.domain_uuid = ']]..domain_uuid..[[' AND r.ring_group_enabled = 'true' ORDER BY - d.destination_delay, d.destination_number asc + ]]..sql_order..[[ ]]; --freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n"); destinations = {}; @@ -293,6 +315,9 @@ if (ring_group_strategy == "sequence") then delimiter = "|"; end + if (ring_group_strategy == "random") then + delimiter = "|"; + end if (ring_group_strategy == "simultaneous") then delimiter = ","; end