Commit 58013409 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

fixed method to add the advertisement into array

parent c54fd82a
...@@ -448,9 +448,27 @@ class MetaGer ...@@ -448,9 +448,27 @@ class MetaGer
} }
/**
* Modifies the already filled array of advertisements and
* includes an advertisement for our donation page.
*
* It will do so everytime when there are other advertisments to mix it in
* and only in a percentage of cases when there are no other advertisements.
*
* The Position at which our advertisement is placed is random within the other
* advertisements. In some cases it will be the first ad and in other cases in some
* other place.
*/
public function addDonationAdvertisement() public function addDonationAdvertisement()
{ {
// ToDo: Translate Strings /**
* If there are no other advertisements we will only display our advertisements
* every so often. ~33% in this case
*/
if (sizeof($this->ads) === 0 && rand(1, 100) > 33) {
return;
}
$donationAd = new \App\Models\Result( $donationAd = new \App\Models\Result(
"MetaGer", "MetaGer",
__("metaGer.ads.own.title"), __("metaGer.ads.own.title"),
...@@ -463,11 +481,9 @@ class MetaGer ...@@ -463,11 +481,9 @@ class MetaGer
); );
$adCount = sizeof($this->ads); $adCount = sizeof($this->ads);
// Put Donation Advertisement to random position // Put Donation Advertisement to random position
$position = random_int(1, max($adCount, 1)) - 1; $position = random_int(0, $adCount);
$this->ads = array_slice($this->ads, 0, $position) + array_splice($this->ads, $position, 0, [$donationAd]);
[$donationAd] +
array_slice($this->ads, $position, $adCount - 1);
} }
public function humanVerification(&$results) public function humanVerification(&$results)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment