if ($page['user']['usertype'] != "1") { Session::setError('You are not able to view offers for an advertisement'); Session::redirect('/'); } // make sure is valid advertisement $advertisement = Advertisement::getAdvertisement($page['parameters']['id']); if ($advertisement == null) { Session::setError('Advertisement does not exist.'); Session::redirect('/'); } // make sure the advertisement is owned by the user if ($advertisement['owner'] != $page['user']['id']) { Session::setError('You do not own this advertisement'); Session::redirect('/'); } $page['advertisement'] = $advertisement; $offers = Offer::getOffersForAdvertisement($advertisement['id']); $page['offers'] = $offers; foreach ($page['offers'] as &$offer) { $offer['ownerDetails'] = User::getUser($offer['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']); } } }
<?php /** * @var $page */ $user = User::getUser($page['parameters']['id']); if ($user != null) { $page['userProfile'] = $user; // get the user's rating $rating = Rating::getUserRating($user['id']); $page['userProfile']['rating'] = Rating::getStarsArray($rating); // Get the user's advertisements if applicable if ($user['usertype'] == "1") { $advertisements = Advertisement::getUserAdvertisements($user['id']); // trim the description foreach ($advertisements as &$advertisement) { if (strlen($advertisement['description']) > 150) { $advertisement['description'] = substr($advertisement['description'], 0, 150) . '...'; } } $page['advertisements'] = $advertisements; } } else { $page['userProfile'] = null; }