Pass regular group array to "create_group" and "update_group" functions

This commit is contained in:
Dmitriy Simushev 2014-10-27 10:19:21 +00:00
parent 816323a154
commit d6084f035f
2 changed files with 76 additions and 92 deletions

View File

@ -168,17 +168,17 @@ class SettingsController extends AbstractController
if (!$group_id) { if (!$group_id) {
// Greate new group // Greate new group
$new_dep = create_group(array( $new_dep = create_group(array(
'name' => $name, 'vclocalname' => $name,
'description' => $description, 'vclocaldescription' => $description,
'commonname' => $common_name, 'vccommonname' => $common_name,
'commondescription' => $common_description, 'vccommondescription' => $common_description,
'email' => $email, 'vcemail' => $email,
'weight' => $weight, 'iweight' => $weight,
'parent' => $parent_group, 'parent' => $parent_group,
'title' => $title, 'vctitle' => $title,
'chattitle' => $chat_title, 'vcchattitle' => $chat_title,
'hosturl' => $host_url, 'vchosturl' => $host_url,
'logo' => $logo)); 'vclogo' => $logo));
// Redirect an operator to group's member page. // Redirect an operator to group's member page.
$redirect_to = $this->generateUrl( $redirect_to = $this->generateUrl(
@ -188,18 +188,18 @@ class SettingsController extends AbstractController
} else { } else {
// Update exisitng group // Update exisitng group
update_group(array( update_group(array(
'id' => $group_id, 'groupid' => $group_id,
'name' => $name, 'vclocalname' => $name,
'description' => $description, 'vclocaldescription' => $description,
'commonname' => $common_name, 'vccommonname' => $common_name,
'commondescription' => $common_description, 'vccommondescription' => $common_description,
'email' => $email, 'vcemail' => $email,
'weight' => $weight, 'iweight' => $weight,
'parent' => $parent_group, 'parent' => $parent_group,
'title' => $title, 'vctitle' => $title,
'chattitle' => $chat_title, 'vcchattitle' => $chat_title,
'hosturl' => $host_url, 'vchosturl' => $host_url,
'logo' => $logo)); 'vclogo' => $logo));
// Redirect an operator to group's page. // Redirect an operator to group's page.
$redirect_to = $this->generateUrl( $redirect_to = $this->generateUrl(

View File

@ -269,17 +269,17 @@ function get_group_description($group)
function check_group_params($group, $extra_params = null) function check_group_params($group, $extra_params = null)
{ {
$obligatory_params = array( $obligatory_params = array(
'name', 'vclocalname',
'description', 'vclocaldescription',
'commonname', 'vccommonname',
'commondescription', 'vccommondescription',
'email', 'vcemail',
'weight', 'iweight',
'parent', 'parent',
'title', 'vctitle',
'chattitle', 'vcchattitle',
'hosturl', 'vchosturl',
'logo', 'vclogo',
); );
$params = is_null($extra_params) $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 * @param array $group Operators' group. The $group array must contains the
* following keys: * following keys:
* - name, * - vclocalname,
* - description, * - vclocaldescription,
* - commonname, * - vccommonname,
* - commondescription, * - vccommondescription,
* - email, * - vcemail,
* - weight, * - iweight,
* - parent, * - parent,
* - title, * - vctitle,
* - chattitle, * - vcchattitle,
* - hosturl, * - vchosturl,
* - logo * - vclogo,
* @return array Created group * @return array Created group
*/ */
function create_group($group) function create_group($group)
@ -327,16 +327,16 @@ function create_group($group)
. ":logo, :weight)"), . ":logo, :weight)"),
array( array(
':parent' => ($group['parent'] ? (int) $group['parent'] : null), ':parent' => ($group['parent'] ? (int) $group['parent'] : null),
':name' => $group['name'], ':name' => $group['vclocalname'],
':desc' => $group['description'], ':desc' => $group['vclocaldescription'],
':common_name' => $group['commonname'], ':common_name' => $group['vccommonname'],
':common_desc' => $group['commondescription'], ':common_desc' => $group['vccommondescription'],
':email' => $group['email'], ':email' => $group['vcemail'],
':title' => $group['title'], ':title' => $group['vctitle'],
':chat_title' => $group['chattitle'], ':chat_title' => $group['vcchattitle'],
':url' => $group['hosturl'], ':url' => $group['vchosturl'],
':logo' => $group['logo'], ':logo' => $group['vclogo'],
':weight' => $group['weight'], ':weight' => $group['iweight'],
) )
); );
$id = $db->insertedId(); $id = $db->insertedId();
@ -358,25 +358,25 @@ function create_group($group)
* *
* @param array $group Operators' group. The $group array must contains the * @param array $group Operators' group. The $group array must contains the
* following keys: * following keys:
* - id, * - groupid,
* - name, * - vclocalname,
* - description, * - vclocaldescription,
* - commonname, * - vccommonname,
* - commondescription, * - vccommondescription,
* - email, * - vcemail,
* - weight, * - iweight,
* - parent, * - parent,
* - title, * - vctitle,
* - chattitle, * - vcchattitle,
* - hosturl, * - vchosturl,
* - logo * - vclogo,
*/ */
function update_group($group) 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. // 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 = Database::getInstance();
$db->query( $db->query(
@ -388,17 +388,17 @@ function update_group($group)
. "where groupid = ?"), . "where groupid = ?"),
array( array(
($group['parent'] ? (int) $group['parent'] : null), ($group['parent'] ? (int) $group['parent'] : null),
$group['name'], $group['vclocalname'],
$group['description'], $group['vclocaldescription'],
$group['commonname'], $group['vccommonname'],
$group['commondescription'], $group['vccommondescription'],
$group['email'], $group['vcemail'],
$group['title'], $group['vctitle'],
$group['chattitle'], $group['vcchattitle'],
$group['hosturl'], $group['vchosturl'],
$group['logo'], $group['vclogo'],
$group['weight'], $group['iweight'],
$group['id'] $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( $args = array(
'group' => $current_group, 'group' => $group,
'original_group' => $original_group, 'original_group' => $original_group,
); );
EventDispatcher::getInstance()->triggerEvent(Events::GROUP_UPDATE, $args); EventDispatcher::getInstance()->triggerEvent(Events::GROUP_UPDATE, $args);