public static function getByLogin($login) { $user = null; try { $statement = DB::getInstance()->prepare('SELECT login, password, firstName, lastName, sex, email, birthDate AS birthDate, address, postalCode, city, phoneNumber FROM ' . self::getTableName() . ' where login=?'); $statement->bindParam(1, $login); $statement->execute(); if ($rs = $statement->fetch(PDO::FETCH_OBJ)) { $user = new User($rs->login, $rs->password, $rs->firstName, $rs->lastName, $rs->sex, $rs->email, $rs->birthDate, $rs->address, $rs->postalCode, $rs->city, $rs->phoneNumber); } } catch (PDOException $e) { die('Error!: ' . $e->getMessage() . '<br/>'); } return $user; }
/** * getByUser function. Get all Favorite of $user in db. * * @access public * @static * @param User object - $user * @return Favorite Objects Array */ public static function getByUser($user) { $favorites = array(); try { $statement = DB::getInstance()->prepare('SELECT * FROM ' . self::getTableName() . ' where login=?'); $statement->bindValue(1, $user->getLogin()); $statement->execute(); while ($rs = $statement->fetch(PDO::FETCH_OBJ)) { $recipe = RecipeDAO::getById($rs->recipeId); $favorites[$rs->recipeId] = new Favorite($recipe, $user); } } catch (PDOException $e) { die('Error!: ' . $e->getMessage() . '<br/>'); } return $favorites; }