From d6084f035fc77d7b3718b75d4001ff5d3e5fe00b Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 27 Oct 2014 10:19:21 +0000 Subject: [PATCH] Pass regular group array to "create_group" and "update_group" functions --- .../Controller/Group/SettingsController.php | 42 +++--- src/mibew/libs/groups.php | 126 ++++++++---------- 2 files changed, 76 insertions(+), 92 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Controller/Group/SettingsController.php b/src/mibew/libs/classes/Mibew/Controller/Group/SettingsController.php index e929f6d0..40dc2e70 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Group/SettingsController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Group/SettingsController.php @@ -168,17 +168,17 @@ class SettingsController extends AbstractController if (!$group_id) { // Greate new group $new_dep = create_group(array( - 'name' => $name, - 'description' => $description, - 'commonname' => $common_name, - 'commondescription' => $common_description, - 'email' => $email, - 'weight' => $weight, + 'vclocalname' => $name, + 'vclocaldescription' => $description, + 'vccommonname' => $common_name, + 'vccommondescription' => $common_description, + 'vcemail' => $email, + 'iweight' => $weight, 'parent' => $parent_group, - 'title' => $title, - 'chattitle' => $chat_title, - 'hosturl' => $host_url, - 'logo' => $logo)); + 'vctitle' => $title, + 'vcchattitle' => $chat_title, + 'vchosturl' => $host_url, + 'vclogo' => $logo)); // Redirect an operator to group's member page. $redirect_to = $this->generateUrl( @@ -188,18 +188,18 @@ class SettingsController extends AbstractController } else { // Update exisitng group update_group(array( - 'id' => $group_id, - 'name' => $name, - 'description' => $description, - 'commonname' => $common_name, - 'commondescription' => $common_description, - 'email' => $email, - 'weight' => $weight, + 'groupid' => $group_id, + 'vclocalname' => $name, + 'vclocaldescription' => $description, + 'vccommonname' => $common_name, + 'vccommondescription' => $common_description, + 'vcemail' => $email, + 'iweight' => $weight, 'parent' => $parent_group, - 'title' => $title, - 'chattitle' => $chat_title, - 'hosturl' => $host_url, - 'logo' => $logo)); + 'vctitle' => $title, + 'vcchattitle' => $chat_title, + 'vchosturl' => $host_url, + 'vclogo' => $logo)); // Redirect an operator to group's page. $redirect_to = $this->generateUrl( diff --git a/src/mibew/libs/groups.php b/src/mibew/libs/groups.php index 3997dd11..5416e22b 100644 --- a/src/mibew/libs/groups.php +++ b/src/mibew/libs/groups.php @@ -269,17 +269,17 @@ function get_group_description($group) function check_group_params($group, $extra_params = null) { $obligatory_params = array( - 'name', - 'description', - 'commonname', - 'commondescription', - 'email', - 'weight', + 'vclocalname', + 'vclocaldescription', + 'vccommonname', + 'vccommondescription', + 'vcemail', + 'iweight', 'parent', - 'title', - 'chattitle', - 'hosturl', - 'logo', + 'vctitle', + 'vcchattitle', + 'vchosturl', + 'vclogo', ); $params = is_null($extra_params) @@ -298,17 +298,17 @@ function check_group_params($group, $extra_params = null) * * @param array $group Operators' group. The $group array must contains the * following keys: - * - name, - * - description, - * - commonname, - * - commondescription, - * - email, - * - weight, + * - vclocalname, + * - vclocaldescription, + * - vccommonname, + * - vccommondescription, + * - vcemail, + * - iweight, * - parent, - * - title, - * - chattitle, - * - hosturl, - * - logo + * - vctitle, + * - vcchattitle, + * - vchosturl, + * - vclogo, * @return array Created group */ function create_group($group) @@ -327,16 +327,16 @@ function create_group($group) . ":logo, :weight)"), array( ':parent' => ($group['parent'] ? (int) $group['parent'] : null), - ':name' => $group['name'], - ':desc' => $group['description'], - ':common_name' => $group['commonname'], - ':common_desc' => $group['commondescription'], - ':email' => $group['email'], - ':title' => $group['title'], - ':chat_title' => $group['chattitle'], - ':url' => $group['hosturl'], - ':logo' => $group['logo'], - ':weight' => $group['weight'], + ':name' => $group['vclocalname'], + ':desc' => $group['vclocaldescription'], + ':common_name' => $group['vccommonname'], + ':common_desc' => $group['vccommondescription'], + ':email' => $group['vcemail'], + ':title' => $group['vctitle'], + ':chat_title' => $group['vcchattitle'], + ':url' => $group['vchosturl'], + ':logo' => $group['vclogo'], + ':weight' => $group['iweight'], ) ); $id = $db->insertedId(); @@ -358,25 +358,25 @@ function create_group($group) * * @param array $group Operators' group. The $group array must contains the * following keys: - * - id, - * - name, - * - description, - * - commonname, - * - commondescription, - * - email, - * - weight, + * - groupid, + * - vclocalname, + * - vclocaldescription, + * - vccommonname, + * - vccommondescription, + * - vcemail, + * - iweight, * - parent, - * - title, - * - chattitle, - * - hosturl, - * - logo + * - vctitle, + * - vcchattitle, + * - vchosturl, + * - vclogo, */ function update_group($group) { - check_group_params($group, array('id')); + check_group_params($group, array('groupid')); // Get the original state of the group to trigger the "update" event later. - $original_group = group_by_id($group['id']); + $original_group = group_by_id($group['groupid']); $db = Database::getInstance(); $db->query( @@ -388,17 +388,17 @@ function update_group($group) . "where groupid = ?"), array( ($group['parent'] ? (int) $group['parent'] : null), - $group['name'], - $group['description'], - $group['commonname'], - $group['commondescription'], - $group['email'], - $group['title'], - $group['chattitle'], - $group['hosturl'], - $group['logo'], - $group['weight'], - $group['id'] + $group['vclocalname'], + $group['vclocaldescription'], + $group['vccommonname'], + $group['vccommondescription'], + $group['vcemail'], + $group['vctitle'], + $group['vcchattitle'], + $group['vchosturl'], + $group['vclogo'], + $group['iweight'], + $group['groupid'] ) ); @@ -409,24 +409,8 @@ function update_group($group) ); } - // Get the current state of the group - $current_group = array( - 'groupid' => $group['id'], - 'parent' => ($group['parent'] ? (int) $group['parent'] : null), - 'vclocalname' => $group['name'], - 'vclocaldescription' => $group['description'], - 'vccommonname' => $group['commonname'], - 'vccommondescription' => $group['commondescription'], - 'vcemail' => $group['email'], - 'vctitle' => $group['title'], - 'vcchattitle' => $group['chattitle'], - 'vchosturl' => $group['hosturl'], - 'vclogo' => $group['logo'], - 'iweight' => $group['weight'], - ); - $args = array( - 'group' => $current_group, + 'group' => $group, 'original_group' => $original_group, ); EventDispatcher::getInstance()->triggerEvent(Events::GROUP_UPDATE, $args);