Permalink
Browse files

merging results into one list - who cares about where the offers come…

… from anyway?
  • Loading branch information...
FlominatorTM committed Oct 6, 2015
1 parent 6d1c09e commit d3c97cdf7dbe32684ed22ab7cf27f1350eae55fd
Showing with 81 additions and 88 deletions.
  1. +2 −16 foto_range.php
  2. +12 −42 next_inc/OfferPage.php
  3. +56 −23 next_inc/OfferPages.php
  4. +11 −7 next_inc/OfferingUser.php
View
@@ -80,22 +80,8 @@
if($locTo->IsValid())
{
$allOfferPages = new OfferPages($server);
foreach($allOfferPages->Items as $offerPage)
{
echo "<h2>$offerPage->Link</h2>";
if($offerPage->HasUsers())
{
$offerPage->ListUsersToRequest($locTo);
}
else
{
echo "no users found";
}
}
$homeOfferPage = $allOfferPages->Items[0];
$footNote = str_replace('_OFFER_PAGE_', $homeOfferPage->Link, $messages['you_on_list']);
$allOfferPages->MergeOffers($locTo);
$allOfferPages->ListUsersToRequest();
}
else
{
View
@@ -178,58 +178,28 @@ function IsCachedVersionUpToDate()
public function HasUsers()
{
return count($this->userOffers) > 0;
return $this->GetNumberOfUsers() > 0;
}
function ListUsersToRequest($locTo)
public function CalculateDistance($locTo)
{
global $messages;
print_debug("locTo->ToString()=>" . $locTo->ToString());
foreach($this->userOffers as $usr)
{
$usr->SetDistance($locTo);
$usr->LinkToUser($this->server, $this->Link);
}
usort($this->userOffers , array("OfferingUser", "CompareDistance"));
foreach($this->userOffers as $usr)
{
$resLine = $usr->LinkToUser($this->server) . " (" . sprintf("%01.1f",$usr->distance) . " km)";
if($usr->IsInRange())
{
echo "<b>$resLine</b>";
}
else
{
echo "$resLine";
}
if($usr->HasDuration())
{
echo " ";
$now = time();
if($usr->dateFrom < $now)
{
if($usr->dateTo < $now)
{
echo str_replace('_DATE_', strftime("%x", $usr->dateTo), $messages['until_date_over']);
}
else
{
echo str_replace('_DATE_', strftime("%x", $usr->dateTo), $messages['until_date']);
}
}
else
{
$out = str_replace('_FIRST_DATE_', strftime("%x", $usr->dateFrom), $messages['between_dates']);
echo str_replace('_SECOND_DATE_', strftime("%x", $usr->dateTo), $out);
}
}
echo "<br>";
}
}
}
public function GetNumberOfUsers()
{
return count($this->userOffers);
}
public function GetUserAt($i)
{
return $this->userOffers[$i];
}
}
View
@@ -4,6 +4,7 @@ class OfferPages
{
public $Items;
public $HomeOfferPage;
private $AllOffers;
private static $CONFIG_DIR = 'next_inc/proj';
public function __construct($homeServer)
@@ -13,8 +14,6 @@ public function __construct($homeServer)
//then I fucked up by checking in development code
//$allServers = array("fr.wikipedia.org");
$indexOfMyServer = -1;
$indexOfEnWp = -1;
$i=0;
foreach($allServers as $oneServer)
{
@@ -28,34 +27,68 @@ public function __construct($homeServer)
include($ConfigFile);
}
$this->Items[]= $createdPage;
if($oneServer == $homeServer)
{
$indexOfMyServer = $i;
}
if($oneServer == "en.wikipedia.org")
{
$indexOfEnWp = $i;
}
$i++;
}
$this->PutHomeServerFirst($indexOfMyServer, $indexOfEnWp);
}
function PutHomeServerFirst ($indexOfMyServer, $indexOfEnWp)
{ if($indexOfMyServer==-1)
{
$indexOfMyServer = $indexOfEnWp;
}
if($indexOfMyServer!=-1)
function MergeOffers($locTo)
{
foreach($this->Items as $oneOfferPage)
{
$firstServer = $this->Items[0];
$this->Items[0] = $this->Items[$indexOfMyServer];
$this->Items[$indexOfMyServer] = $firstServer;
$oneOfferPage->CalculateDistance($locTo);
for($i=0;$i<$oneOfferPage->GetNumberOfUsers();$i++)
{
$oneUser = $oneOfferPage->GetUserAt($i);
if($oneUser->IsValid())
{
$this->AllOffers[] = $oneUser;
}
}
}
usort($this->AllOffers , array("OfferingUser", "CompareDistance"));
}
public function ListUsersToRequest()
{
global $messages;
foreach($this->AllOffers as $usr)
{
$resLine = $usr->Link . " (" . sprintf("%01.1f",$usr->distance) . " km)";
if($usr->IsInRange())
{
echo "<b>$resLine</b>";
}
else
{
echo "$resLine";
}
echo " <small>" . $usr->LinkHome . "</small>";
if($usr->HasDuration())
{
echo " ";
$now = time();
if($usr->dateFrom < $now)
{
if($usr->dateTo < $now)
{
echo str_replace('_DATE_', strftime("%x", $usr->dateTo), $messages['until_date_over']);
}
else
{
echo str_replace('_DATE_', strftime("%x", $usr->dateTo), $messages['until_date']);
}
}
else
{
$out = str_replace('_FIRST_DATE_', strftime("%x", $usr->dateFrom), $messages['between_dates']);
echo str_replace('_SECOND_DATE_', strftime("%x", $usr->dateTo), $out);
}
}
echo "<br>";
}
}
}
View
@@ -3,11 +3,13 @@
class OfferingUser
{
public $location;
public $range =-1;
public $name ="";
public $distance =-1;
public $dateFrom;
public $dateTo;
public $range =-1;
public $name ="";
public $distance =-1;
public $dateFrom;
public $dateTo;
public $Link;
public $LinkHome;
public function ToString() {
$loc = $this->location;
@@ -60,11 +62,13 @@ static function CompareDistance($a, $b)
return ($a->distance > $b->distance) ? +1 : -1;
}
public function LinkToUser($server)
public function LinkToUser($server, $homeLink)
{
return "<a href=\"http://$server/wiki/User:" . $this->name . "\">" . $this->name . "</a>";
$this->Link = "<a href=\"http://$server/wiki/User:" . $this->name . "\">" . $this->name . "</a>";
$this->LinkHome = $homeLink;
}
public function SetDateRangeISO($from, $to)
{
$fromParts = explode('-', $from);

0 comments on commit d3c97cd

Please sign in to comment.