Beispiel #1
0
 /**
  * Complete an offer if both ratings have been completed
  *
  * @param $id
  */
 static function completeOffer($id)
 {
     $offer = self::getOfferSingle($id);
     $advertisement = Advertisement::getAdvertisement($offer['advertisement']);
     if (Rating::getRating($id, $offer['owner']) != null && Rating::getRating($id, $advertisement['owner']) != null) {
         $mysql = new MySQL();
         $results = $mysql->query('UPDATE offer SET status = 3 WHERE id = :id', [':id' => $id]);
     }
 }
Beispiel #2
0
<?php

$advertisement = Advertisement::getAdvertisement($page['parameters']['id']);
if ($advertisement != null) {
    $page['advertisement'] = $advertisement;
    // Format dates
    $page['advertisement']['startdate'] = date("jS M Y - g:ia", $page['advertisement']['startdate']);
    $page['advertisement']['enddate'] = date("jS M Y - g:ia", $page['advertisement']['enddate']);
    $page['advertisement']['created'] = date("jS M Y - g:ia", $page['advertisement']['created']);
    // split tags
    $page['advertisement']['tags'] = explode(',', $page['advertisement']['tags']);
    foreach ($page['advertisement']['tags'] as &$tag) {
        $tag = trim($tag);
    }
    // get the parent owners details
    $page['advertisement']['parentOwner'] = User::getUser($advertisement['owner']);
} else {
    $page['advertisement'] = null;
}
Beispiel #3
0
<?php

/**
 * @var $page
 */
if ($page['user']['usertype'] != "1") {
    Session::setError('You are not able to accept an Offer');
    Session::redirect('/');
}
$offer = Offer::getOfferSingle($page['parameters']['id']);
if ($offer == null) {
    Session::setError('Offer does not exist');
    Session::redirect('/');
}
$advertisement = Advertisement::getAdvertisement($offer['advertisement']);
if ($advertisement['owner'] != $page['user']['id']) {
    Session::setError('You do not own this offers parent advertisement');
    Session::redirect('/');
}
if ($offer['status'] != "0") {
    Session::setError('Offer can not be accepted.');
    Session::redirect('/');
}
$accepted = Offer::acceptOffer($page['parameters']['id']);
if ($accepted) {
    Session::setSuccess('Successfully accepted offer');
    Session::redirect('/offers/view/' . $offer['advertisement']);
}
Session::setError('Something went wrong, please try again.');
Session::redirect('/offers/view/' . $offer['advertisement']);
Beispiel #4
0
$advertisements = Advertisement::getUserAdvertisements(User::getId());
$page['advertisements'] = $advertisements;
foreach ($page['advertisements'] as &$advertisement) {
    // trim the description
    if (strlen($advertisement['description']) > 150) {
        $advertisement['description'] = substr($advertisement['description'], 0, 150) . '...';
    }
}
$offers = Offer::getOffersForUser(User::getId());
$page['offers'] = $offers;
foreach ($page['offers'] as &$offer) {
    // trim the description
    if (strlen($offer['description']) > 150) {
        $offer['description'] = substr($offer['description'], 0, 150) . '...';
    }
    $offer['parentAdvertisement'] = Advertisement::getAdvertisement($offer['advertisement']);
    // get the owner details if the offer has been accepted
    if ($offer['status'] == "1" || $offer['status'] == "3") {
        $offer['ownerDetails'] = User::getUser($offer['parentAdvertisement']['owner']);
    }
    if ($offer['status'] == "3") {
        $offer['yourRating'] = Rating::getRating($offer['id'], User::getId());
        if ($offer['yourRating'] != null) {
            $offer['yourRating']['rating'] = Rating::getStarsArray($offer['yourRating']['rating']);
        }
        $offer['theirRating'] = Rating::getRating($offer['id'], $offer['ownerDetails']['id']);
        if ($offer['theirRating'] != null) {
            $offer['theirRating']['rating'] = Rating::getStarsArray($offer['theirRating']['rating']);
        }
    }
}