/** * Display a specified ad. * * @param int $id * @return Response */ public function show($id) { try { $session = Session::get('user'); $adService = new SoapClient(Config::get('wsdl.ad'), array()); $messageService = new SoapClient(Config::get('wsdl.message'), array()); $result = $adService->getAdById(array("adId" => $id, "includeCreatorStatistics" => true)); $ad = new Ad($result->ad); if ($ad->requested) { $request = $ad->getRequestByUser($session['data']->id); if (isset($request)) { $ad->status = $request->status; $ad->user_request = $request; $ad->user_requested = true; } else { $ad->user_requested = false; } } if (isset($ad->requests->item) && !is_array($ad->requests->item)) { $ad->requests->item = array($ad->requests->item); } $ad->activeReq = 0; if (isset($ad->requests->item)) { foreach ($ad->requests->item as $k => $request) { if ($request->status != 'CANCELED' && $request->status != 'DECLINED' && $request->status != 'UNACCEPTED') { $ad->activeReq++; } } } if (!$ad->online) { if ($ad->approved) { $ad->status = "APPROVED"; } else { if ($ad->approval == null) { $ad->status = "PENDING"; } else { $ad->status = "DECLINED"; } } } elseif ($ad->sold) { $requestor = $ad->getAcceptedRequest()->user; if (isset($requestor->avatar)) { $ad->requestor = $requestor->avatar->id; } else { $ad->requestor = null; } $ad->status = "SOLD"; } elseif ($ad->expired) { $ad->status = "EXPIRED"; } elseif (!$ad->hasActiveRequest()) { $ad->status = "NO_REQUESTS"; } elseif ($ad->hasSentRequest()) { $requestor = $ad->getAcceptedRequest()->user; if (isset($requestor->avatar)) { $ad->requestor = $requestor->avatar->id; } else { $ad->requestor = null; } $ad->status = "SENT"; } elseif ($ad->hasAcceptedRequest()) { $requestor = $ad->getAcceptedRequest()->user; if (isset($requestor->avatar)) { $ad->requestor = $requestor->avatar->id; } else { $ad->requestor = null; } $ad->status = "SELECTED"; } else { $ad->status = "ACTIVE"; } $ad->canEdit = $ad->owner && !$ad->hasActiveRequest() && $ad->statistics->numBookmarks == 0 && $ad->statistics->numComments == 0 && $ad->statistics->numShares == 0; $ad->canDelete = $ad->owner && (!$ad->hasActiveRequest() || $ad->expired); $comments = $messageService->getCommentsByAd(array("adId" => $ad->id, "lastCommentId" => -1, "numComments" => 11)); if (isset($comments->comment)) { if (!is_array($comments->comment)) { $comments = array($comments->comment); } else { $comments = $comments->comment; } } return array('ad' => $ad, 'comments' => $comments); } catch (Exception $ex) { return $ex; } }