/** * returns an array of AdModel objects that are all ads associated with the * user */ public function getAds() { $ads = []; $id = $this->id; $query = "SELECT id FROM ads WHERE users_id = {$id}"; $stmt = self::$dbc->prepare($query); $stmt->execute(); $adIds = $stmt->fetchAll(PDO::FETCH_NUM); foreach ($adIds as $adId) { $ads[] = AdModel::find($adId[0]); } return $ads; }
function pageController() { //initializes the session variable if none exists otherwise it resets it //a user id was passed to this page to display if (!empty($_GET['id'])) { $adID = $_GET['id']; $adObject = AdModel::find($adID); } //the form containing only the submit button was submmited - user wants to edit the ad if (!empty($_POST) && !empty($_GET['id'])) { header("Location: /ads.edit.php?id=" . $adID); //this will be the $_GET for the ads.edit.php die; } return array('adObject' => $adObject); }
function pageController() { $errors['count'] = 0; if (!empty($_GET['id'])) { $adID = $_GET['id']; $adObject = AdModel::find($adID); } $imageSuccessMessage = ""; //if an image was submitted - validate it even before validating the rest of the form if (!empty($_POST['upload-image']) && $_FILES['fileToUpload']['name'] != '') { try { $postImage = Input::getImage(); //image was successfully uploaded $imageSuccessMessage = "Image: " . basename($_FILES['fileToUpload']['name']) . " has been uploaded!"; //store image in the session $_SESSION['image'] = $postImage; } catch (Exception $e) { $errors['image'] = 'Image: ' . $e->getMessage(); $errors['count']++; } } //clicked on the upload image button without selecting a photo if (!empty($_POST['upload-image']) && $_FILES['fileToUpload']['name'] == '') { $errors['image'] = "Image: Select an image to upload!"; $errors['count']++; } //an image has been submitted; use the image stored in the $_SESSION if (isset($_SESSION['image'])) { $postImage = $_SESSION['image']; } else { //use the image stored in the database $postImage = "Database Image"; } //if there weren't any errors with the image; then, process then rest of the form if ($errors['count'] == 0) { $errors = processForm($adObject, $postImage); // $errors = processForm($adObject->category, $adObject->date_posted, $postImage); } return array('adObject' => $adObject, 'errorMessages' => $errors); }