Documentation and remove duplicate code.
Add a bit Doxygen documentation and remove some duplicate code from account.php.
This commit is contained in:
parent
792e475a78
commit
864116805b
@ -523,9 +523,7 @@ function downgrade_accounts() {
|
|||||||
|
|
||||||
$basic = get_config('system','default_service_class');
|
$basic = get_config('system','default_service_class');
|
||||||
|
|
||||||
|
|
||||||
foreach($r as $rr) {
|
foreach($r as $rr) {
|
||||||
|
|
||||||
if(($basic) && ($rr['account_service_class']) && ($rr['account_service_class'] != $basic)) {
|
if(($basic) && ($rr['account_service_class']) && ($rr['account_service_class'] != $basic)) {
|
||||||
$x = q("UPDATE account set account_service_class = '%s', account_expires = '%s'
|
$x = q("UPDATE account set account_service_class = '%s', account_expires = '%s'
|
||||||
where account_id = %d",
|
where account_id = %d",
|
||||||
@ -550,97 +548,96 @@ function downgrade_accounts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
// check service_class restrictions. If there are no service_classes defined, everything is allowed.
|
* @brief Check service_class restrictions.
|
||||||
// if $usage is supplied, we check against a maximum count and return true if the current usage is
|
*
|
||||||
// less than the subscriber plan allows. Otherwise we return boolean true or false if the property
|
* If there are no service_classes defined, everything is allowed.
|
||||||
// is allowed (or not) in this subscriber plan. An unset property for this service plan means
|
* If $usage is supplied, we check against a maximum count and return true if
|
||||||
// the property is allowed, so it is only necessary to provide negative properties for each plan,
|
* the current usage is less than the subscriber plan allows. Otherwise we
|
||||||
// or what the subscriber is not allowed to do.
|
* return boolean true or false if the property is allowed (or not) in this
|
||||||
|
* subscriber plan. An unset property for this service plan means the property
|
||||||
|
* is allowed, so it is only necessary to provide negative properties for each
|
||||||
|
* plan, or what the subscriber is not allowed to do.
|
||||||
|
*
|
||||||
|
* Like account_service_class_allows() but queries directly by account rather
|
||||||
|
* than channel. Service classes are set for accounts, so we look up the
|
||||||
|
* account for the channel and fetch the service class restrictions of the
|
||||||
|
* account.
|
||||||
|
*
|
||||||
|
* @see account_service_class_allows() if you have a channel_id already
|
||||||
|
* @see service_class_fetch()
|
||||||
|
*
|
||||||
|
* @param int $uid The channel_id to check
|
||||||
|
* @param string $property The service class property to check for
|
||||||
|
* @param string|boolean $usage (optional) The value to check against
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function service_class_allows($uid, $property, $usage = false) {
|
function service_class_allows($uid, $property, $usage = false) {
|
||||||
$a = get_app();
|
$limit = service_class_fetch($uid, $property);
|
||||||
if($uid == local_channel()) {
|
|
||||||
$service_class = $a->account['account_service_class'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$r = q("select account_service_class as service_class
|
|
||||||
from channel c, account a
|
|
||||||
where c.channel_account_id=a.account_id and c.channel_id= %d limit 1",
|
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
if($r !== false and count($r)) {
|
|
||||||
$service_class = $r[0]['service_class'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(! x($service_class))
|
|
||||||
return true; // everything is allowed
|
|
||||||
|
|
||||||
$arr = get_config('service_class',$service_class);
|
if($limit === false)
|
||||||
if(! is_array($arr) || (! count($arr)))
|
return true; // No service class set => everything is allowed
|
||||||
return true;
|
|
||||||
|
|
||||||
if($usage === false)
|
if($usage === false) {
|
||||||
return ((x($arr[$property])) ? (bool) $arr[$property] : true);
|
// We use negative values for not allowed properties in a subscriber plan
|
||||||
else {
|
return ((x($limit)) ? (bool) $limit : true);
|
||||||
if(! array_key_exists($property,$arr))
|
} else {
|
||||||
return true;
|
return (((intval($usage)) < intval($limit)) ? true : false);
|
||||||
|
|
||||||
return (((intval($usage)) < intval($arr[$property])) ? true : false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks service class restrictions by account_id.
|
* @brief Check service class restrictions by account.
|
||||||
*
|
*
|
||||||
* Like service_class_allows() but queries by account rather than channel.
|
* If there are no service_classes defined, everything is allowed.
|
||||||
|
* If $usage is supplied, we check against a maximum count and return true if
|
||||||
|
* the current usage is less than the subscriber plan allows. Otherwise we
|
||||||
|
* return boolean true or false if the property is allowed (or not) in this
|
||||||
|
* subscriber plan. An unset property for this service plan means the property
|
||||||
|
* is allowed, so it is only necessary to provide negative properties for each
|
||||||
|
* plan, or what the subscriber is not allowed to do.
|
||||||
*
|
*
|
||||||
* @see service_class_allows()
|
* Like service_class_allows() but queries directly by account rather than channel.
|
||||||
*
|
*
|
||||||
* @param int $aid account_id
|
* @see service_class_allows() if you have a channel_id instead of an account_id
|
||||||
* @param string $property
|
* @see account_service_class_fetch()
|
||||||
* @param int|boolean $usage, default false
|
*
|
||||||
|
* @param int $aid The account_id to check
|
||||||
|
* @param string $property The service class property to check for
|
||||||
|
* @param int|boolean $usage, (optional) The value to check against
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*
|
|
||||||
* @todo Can't we use here internally account_service_class_fetch() to reduce duplicate code?
|
|
||||||
*/
|
*/
|
||||||
function account_service_class_allows($aid, $property, $usage = false) {
|
function account_service_class_allows($aid, $property, $usage = false) {
|
||||||
$r = q("select account_service_class as service_class from account where account_id = %d limit 1",
|
|
||||||
intval($aid)
|
|
||||||
);
|
|
||||||
if($r !== false and count($r)) {
|
|
||||||
$service_class = $r[0]['service_class'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(! x($service_class))
|
$limit = account_service_class_fetch($aid, $property);
|
||||||
return true; // everything is allowed
|
|
||||||
|
|
||||||
$arr = get_config('service_class', $service_class);
|
if($limit === false)
|
||||||
if(! is_array($arr) || (! count($arr)))
|
return true; // No service class is set => everything is allowed
|
||||||
return true;
|
|
||||||
|
|
||||||
if($usage === false)
|
if($usage === false) {
|
||||||
return ((x($arr[$property])) ? (bool) $arr[$property] : true);
|
// We use negative values for not allowed properties in a subscriber plan
|
||||||
else {
|
return ((x($limit)) ? (bool) $limit : true);
|
||||||
if(! array_key_exists($property, $arr))
|
} else {
|
||||||
return true;
|
return (((intval($usage)) < intval($limit)) ? true : false);
|
||||||
|
|
||||||
return (((intval($usage)) < intval($arr[$property])) ? true : false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetches a service class for a channel_id and property.
|
* @brief Queries a service class value for a channel and property.
|
||||||
|
*
|
||||||
|
* Service classes are set for accounts, so look up the account for this channel
|
||||||
|
* and fetch the service classe of the account.
|
||||||
*
|
*
|
||||||
* This method not just checks if a service class is allowed like service_class_allows(),
|
|
||||||
* but also returns the service class value.
|
|
||||||
* If no service class is available it returns false and everything should be
|
* If no service class is available it returns false and everything should be
|
||||||
* allowed.
|
* allowed.
|
||||||
*
|
*
|
||||||
* @param int $uid channel_id
|
* @see account_service_class_fetch()
|
||||||
* @param string $property
|
*
|
||||||
|
* @param int $uid The channel_id to query
|
||||||
|
* @param string $property The service property name to check for
|
||||||
* @return boolean|int
|
* @return boolean|int
|
||||||
|
*
|
||||||
|
* @todo Should we merge this with account_service_class_fetch()?
|
||||||
*/
|
*/
|
||||||
function service_class_fetch($uid, $property) {
|
function service_class_fetch($uid, $property) {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
@ -668,8 +665,18 @@ function service_class_fetch($uid, $property) {
|
|||||||
return((array_key_exists($property, $arr)) ? $arr[$property] : false);
|
return((array_key_exists($property, $arr)) ? $arr[$property] : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// like service_class_fetch but queries by account rather than channel
|
/**
|
||||||
|
* @brief Queries a service class value for an account and property.
|
||||||
|
*
|
||||||
|
* Like service_class_fetch() but queries by account rather than channel.
|
||||||
|
*
|
||||||
|
* @see service_class_fetch() if you have channel_id.
|
||||||
|
* @see account_service_class_allows()
|
||||||
|
*
|
||||||
|
* @param int $aid The account_id to query
|
||||||
|
* @param string $property The service property name to check for
|
||||||
|
* @return boolean|int
|
||||||
|
*/
|
||||||
function account_service_class_fetch($aid, $property) {
|
function account_service_class_fetch($aid, $property) {
|
||||||
|
|
||||||
$r = q("select account_service_class as service_class from account where account_id = %d limit 1",
|
$r = q("select account_service_class as service_class from account where account_id = %d limit 1",
|
||||||
@ -692,7 +699,7 @@ function account_service_class_fetch($aid, $property) {
|
|||||||
|
|
||||||
|
|
||||||
function upgrade_link($bbcode = false) {
|
function upgrade_link($bbcode = false) {
|
||||||
$l = get_config('service_class','upgrade_link');
|
$l = get_config('service_class', 'upgrade_link');
|
||||||
if(! $l)
|
if(! $l)
|
||||||
return '';
|
return '';
|
||||||
if($bbcode)
|
if($bbcode)
|
||||||
|
Reference in New Issue
Block a user