/** * Create a Basket instance given a user's id * @param mixed $userId * @return \Basket */ public function constructByUserId($userId) { $basketRows = Model\Basket::selectBasketByUserId($userId); $pets = array(); if (is_array($basketRows)) { foreach ($basketRows as $i => $row) { $parts = explode(':', $row['pet_id']); if (isset($parts[1])) { $pet = Pet::constructById($parts[1]); $pet->loadImages(); $pets[] = $pet; } } } return new Basket($userId, $pets); }
/** * Fetch the userId and username of the poster of a pet and return a JSON formatted string with this data * @return string in JSON format */ public static function getPosterInfo() { $get = Core\Input::get(); if (isset($get['petId'])) { $pet = Pet::constructById($get['petId']); $userId = $pet->getUserId(); $user = User::constructById($userId); $userName = $user->getUsername(); return json_encode(array('userId' => $userId, 'userName' => $userName)); } return '{}'; }