function ad_weight_percent_settings_validate in Advertisement 5.2
Same name and namespace in other branches
- 5 weight/percent/ad_weight_percent.module \ad_weight_percent_settings_validate()
- 6.3 weight/percent/ad_weight_percent.module \ad_weight_percent_settings_validate()
- 6 weight/percent/ad_weight_percent.module \ad_weight_percent_settings_validate()
- 6.2 weight/percent/ad_weight_percent.module \ad_weight_percent_settings_validate()
- 7 weight/percent/ad_weight_percent.module \ad_weight_percent_settings_validate()
Be sure that all enabled groups add up to a total of 100%.
File
- weight/
percent/ ad_weight_percent.module, line 97 - A plug in for the ad.module, providing a percentage based weighting mechanism for the random selection of ads.
Code
function ad_weight_percent_settings_validate($form_id, $form_values) {
$groups = module_invoke('ad', 'groups_list', TRUE);
foreach ($groups as $tid => $group) {
if ($form_values["enable-{$tid}"]) {
$result = db_query('SELECT nid FROM {term_node} WHERE tid = %d', $group->tid);
$total = 0;
// Add up total percentages for all nids in group, confirm equals 100%.
$first = 0;
while ($nid = db_fetch_object($result)) {
if (!$first) {
$first = $nid->nid;
}
$total = $total + (int) $form_values["percent-{$tid}-{$nid->nid}"];
}
// Confirmed that total equals 100%.
if ($total != 100) {
form_set_error("percent-{$tid}-{$first}", t('The total percentage for all ads in the %group group combined must equal 100%. It currently equals %percent.', array(
'%group' => $group->name,
'%percent' => "{$total}%",
)));
}
}
}
}