mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-07 16:24:43 +03:00
Refactor "check_group_fields" function
This commit is contained in:
parent
32a134f31a
commit
614f02a108
@ -261,14 +261,15 @@ function get_group_description($group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chaeck availability of chatgroup array params.
|
* Checks that group's array has all necessary fields.
|
||||||
*
|
*
|
||||||
* @param array $group Associative group array.
|
* @param array $group Associative group's array.
|
||||||
* @param array $extra_params extra parameters for chatgroup array.
|
* @return bool Boolean true if all the fields are in place and false otherwise.
|
||||||
*/
|
*/
|
||||||
function check_group_params($group, $extra_params = null)
|
function check_group_fields($group)
|
||||||
{
|
{
|
||||||
$obligatory_params = array(
|
$obligatory_fields = array(
|
||||||
|
'groupid',
|
||||||
'vclocalname',
|
'vclocalname',
|
||||||
'vclocaldescription',
|
'vclocaldescription',
|
||||||
'vccommonname',
|
'vccommonname',
|
||||||
@ -282,13 +283,7 @@ function check_group_params($group, $extra_params = null)
|
|||||||
'vclogo',
|
'vclogo',
|
||||||
);
|
);
|
||||||
|
|
||||||
$params = is_null($extra_params)
|
return (count(array_diff($obligatory_fields, array_keys($group))) == 0);
|
||||||
? $obligatory_params
|
|
||||||
: array_merge($obligatory_params, $extra_params);
|
|
||||||
|
|
||||||
if (count(array_diff($params, array_keys($group))) != 0) {
|
|
||||||
die('Wrong parameters set!');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,10 +305,15 @@ function check_group_params($group, $extra_params = null)
|
|||||||
* - vchosturl,
|
* - vchosturl,
|
||||||
* - vclogo,
|
* - vclogo,
|
||||||
* @return array Created group
|
* @return array Created group
|
||||||
|
* @throws \InvalidArgumentException if not all of the group fields are
|
||||||
|
* specified.
|
||||||
*/
|
*/
|
||||||
function create_group($group)
|
function create_group($group)
|
||||||
{
|
{
|
||||||
check_group_params($group);
|
$group += array('groupid' => false);
|
||||||
|
if (!check_group_fields($group)) {
|
||||||
|
throw new \InvalidArgumentException('Not all group fields are specified');
|
||||||
|
}
|
||||||
|
|
||||||
$db = Database::getInstance();
|
$db = Database::getInstance();
|
||||||
$db->query(
|
$db->query(
|
||||||
@ -372,10 +372,14 @@ function create_group($group)
|
|||||||
* - vcchattitle,
|
* - vcchattitle,
|
||||||
* - vchosturl,
|
* - vchosturl,
|
||||||
* - vclogo,
|
* - vclogo,
|
||||||
|
* @throws \InvalidArgumentException if not all of the group fields are
|
||||||
|
* specified.
|
||||||
*/
|
*/
|
||||||
function update_group($group)
|
function update_group($group)
|
||||||
{
|
{
|
||||||
check_group_params($group, array('groupid'));
|
if (!check_group_fields($group)) {
|
||||||
|
throw new \InvalidArgumentException('Not all group fields are specified');
|
||||||
|
}
|
||||||
|
|
||||||
// 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['groupid']);
|
$original_group = group_by_id($group['groupid']);
|
||||||
|
Loading…
Reference in New Issue
Block a user