本文整理汇总了PHP中Ad::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::find方法的具体用法?PHP Ad::find怎么用?PHP Ad::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ad
的用法示例。
在下文中一共展示了Ad::find方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pageController
function pageController()
{
session_start();
if (!Auth::check()) {
header('Location: /auth/login');
exit;
}
$username = Auth::user();
$user = User::findUserByUsername($username);
$adid = Input::get('id');
$ad = Ad::find($adid);
$item_name = $ad->attributes['item_name'];
$price = $ad->attributes['price'];
$description = $ad->attributes['description'];
$image_path = $ad->attributes['image_path'];
$contact = $ad->attributes['contact'];
$errors = array();
if (!empty($_POST)) {
if (Input::notEmpty('item_name')) {
$item_name = ValidateAd::getItemName();
}
if (Input::notEmpty('price')) {
$price = ValidateAd::getPrice();
}
if (Input::notEmpty('description')) {
$description = ValidateAd::getDescription();
}
if (Input::notEmpty('contact')) {
$contact = ValidateAd::getContact();
}
$errors = ValidateAd::getErrors();
if (empty($errors)) {
$ad->attributes['item_name'] = $item_name;
$ad->attributes['price'] = $price;
$ad->attributes['description'] = $description;
$ad->attributes['contact'] = $contact;
$ad->attributes['image_path'] = $image_path;
$ad->save();
}
if (!Input::notEmpty('delete-id')) {
//if the form has been submitted
Ad::delete($ad->attributes['id']);
header("Location: /ads");
die;
//delete the specific ad - going to need to somehow tie in the ad id to the delete buttn for that specific id
}
}
return array('ad' => $ad, 'username' => $username, 'item_name' => $item_name, 'price' => $price, 'description' => $description, 'image_path' => $image_path, 'contact' => $contact);
}
示例2: pageController
function pageController()
{
// Gets the current session.
session_start();
if (!isset($_SESSION['Loggedinuser'])) {
$loginstatus = "Members, Log In!";
} else {
$loginstatus = $_SESSION['Loggedinuser'] . " is logged in!";
}
// $adId is set in $_GET to be used to determine which ad will be displayed.
$adId = Input::has('id') ? Input::get('id') : 1;
// Uses $adId to grab all the ad data from the database.
$ad = Ad::find($adId);
// A small array/array_rand section to randomly display ad availability in the ad write up.
$availarray = ['not', 'limited quantities', 'in stock,'];
$availkey = array_rand($availarray, 1);
$avail = $availarray[$availkey];
return array('ad' => $ad, 'adId' => $adId, 'loginstatus' => $loginstatus, 'avail' => $avail);
}
示例3: pageController
function pageController()
{
session_start();
if (!Input::has('id')) {
header('Location: /ads');
exit;
}
if (Auth::check()) {
$username = Auth::user();
$user = User::findUserByUsername($username);
$userid = $user->attributes['id'];
} else {
$userid = null;
}
$adid = Input::get('id');
$ad = Ad::find($adid);
$aduserid = $ad->attributes['user_id'];
$item_name = $ad->attributes['item_name'];
$price = $ad->attributes['price'];
$description = $ad->attributes['description'];
$image_path = $ad->attributes['image_path'];
$contact = $ad->attributes['contact'];
return array('adid' => $adid, 'userid' => $userid, 'aduserid' => $aduserid, 'item_name' => $item_name, 'price' => $price, 'description' => $description, 'image_path' => $image_path, 'contact' => $contact);
}
示例4: ads
public function ads()
{
$o = new Ad();
$o->userId = $this->id;
return $o->find();
}
示例5: Ad
<?php
require_once '../bootstrap.php';
/*edit file is index and show files together*/
$id = Input::get('id');
$ad = Ad::find($id);
/*On each page load, retrieve and display all records from the database; code as in adsWinesellerIndex.php*/
foreach ($ads as $ad) {
$ad['title'];
$ad['vendor'];
$ad['state'];
$ad['zip'];
$ad['category'];
$ad['style'];
$ad['origin'];
$ad['vintage'];
$ad['price'];
$ad['description'];
}
unset($ad);
/*if input has name and location then submit call to update method or call save*/
if (Input::has('title') && Input::has('vendor')) {
$ad = new Ad();
try {
$ad->vendor = Input::getString('vendor', 1, 100);
} catch (Exception $e) {
/*below is the same as calling array push*/
$errors[] = $e->getMessage();
}
try {
$ad->city = Input::getString('city', 1, 100);
示例6:
<?php
/*Shows a single ad that has been clicked from the ads.index.php*/
require_once '../bootstrap.php';
// Retrieve record with id matching the $_GET request in url
$ad = Ad::find($_GET['id']);
$adArray = $ad->attributes[0];
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap.css">
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="../css/wineseller.css">
<meta charset="utf-8">
<title>View of Wineseller Ad</title>
</head>
<body>
<?php
include "../views/partials/header.php";
?>
<?php
include "../views/partials/navbar.php";
示例7: edit
/**
* Show the form for editing the specified ad.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$ad = Ad::find($id);
return View::make('ads.edit', compact('ad'));
}
示例8:
<?php
require_once '../bootstrap.php';
$id = $_GET["id"];
$currentAd = Ad::find($id);
$userId = $currentAd->attributes[0]["user_id"];
$currentUser = User::find($userId);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.png">
<title><?php
echo $currentAd->attributes[0]["title"];
?>
</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.1.3/css/jasny-bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/css/main.css" rel="stylesheet">
<style type="text/css">
示例9: pageController
function pageController()
{
require_once '../db/db_connect.php';
// Gets the current session and session id for logged in users.
session_start();
$sessionId = session_id();
if (!isset($_SESSION['Loggedinuser'])) {
header('location: auth.login.php');
die;
}
$loginstatus = $_SESSION['Loggedinuser'] . " is logged in!";
// This portion of code gets all the ads' categories in one array.
// The categories, which are strings (sometimes with multiple categories in it),
// are then put into the array by themselves. The array is imploded into a string and then exploded into an
// array again. This allows us to split the strings with multiple categories in them.
// The php array_unique removes duplicate category values and sort orders them by first letter.
$arrayCategories = Ad::showJustCategories();
$justCategories = [];
foreach ($arrayCategories as $key => $value) {
array_push($justCategories, $value['categories']);
}
$justCategoriesString = implode(', ', $justCategories);
$justCategoriesArray = explode(', ', $justCategoriesString);
$justCategoriesArrayUnique = array_unique($justCategoriesArray);
sort($justCategoriesArrayUnique);
// Through $_SESSION, gets the logged in user.
$username = Auth::user();
// Returns an object of the user's data.
$user = User::finduserbyusername($username);
// Using the user's id (a foreign key in the ads table), finds all ads by that user.
$userAds = Ad::findAllAdsByUserId($user->id);
// The first form "Select an Ad" sets 'ad_to_edit' in $_POST, which is the variable $adToEdit.
$adToEdit = Input::has('ad_to_edit') ? (int) Input::get('ad_to_edit') : NULL;
// Using $adToEdit, this returns an object of data about that ad.
$adToEditObj = Ad::find($adToEdit);
// Uses the second form of an edited ad to insert the new values into the table and database.
function updateAd($dbc, $user)
{
// Now calls on the Input class's getString and getNumber methods with try catches.
// Try catch create an array of errors for passing to the user in the HTML.
$errorArray = [];
try {
$method = Input::getString('method', 1, 50);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errMethod'] = $error;
}
try {
$title = Input::getString('title', 1, 50);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errTitle'] = $error;
}
try {
$price = Input::getNumber('price', 0, 25000);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errPrice'] = $error;
}
try {
$location = Input::getString('location', 1, 50);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errLoc'] = $error;
}
try {
$description = Input::getString('description', 1, 500);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errDes'] = $error;
}
try {
$adid = Input::getNumber('adid', 1, 5000000);
} catch (Exception $e) {
$error = $e->getMessage();
}
try {
$categoriesArray = Input::get('categories', 1, 50);
$categories = implode(', ', $categoriesArray);
} catch (Exception $e) {
$error = $e->getMessage();
$errorArray['errCats'] = $error;
}
// This portion allows for image uploads.
// If the user does not upload an image, the value in the readonly input of image url is used instead.
if (!isset($_FILES['image_upload'])) {
$filename = Input::get('image_url');
} else {
if ($_FILES['image_upload']['name'] != '') {
$uploads_directory = 'img/uploads/';
$filename = $uploads_directory . basename($_FILES['image_upload']['name']);
if (move_uploaded_file($_FILES['image_upload']['tmp_name'], $filename)) {
// echo 'The file ' . basename($_FILES['image_upload']['name']) . ' has been uploaded.';
} else {
$errorArray['errImage'] = 'Sorry, there was an error uploading your file.';
var_dump($_FILES);
}
} else {
$filename = Input::get('image_url');
}
//.........这里部分代码省略.........
示例10: _performance
protected function _performance($date = null)
{
if (!$date) {
$date = date('Y-m-d', strtotime('-1 day'));
}
$date = date('Y-m-d', strtotime('-1 day'));
// find the publishers
$publishers = \User::all(['type = ?' => 'publisher', 'live = ?' => true], ['_id', 'email', 'meta', 'org_id']);
$dq = ['start' => $date, 'end' => $date];
$dateQuery = Utils::dateQuery($dq);
$start = $dateQuery['start'];
$end = $dateQuery['end'];
// store AD commission info
$commInfo = [];
$orgs = [];
$advPerfs = [];
$advertisers = [];
$adsInfo = [];
foreach ($publishers as $p) {
$org = \Organization::find($orgs, $p->org_id);
// find the clicks for the publisher
$clicks = Db::query('Click', ['pid' => $p->_id, 'is_bot' => false, 'created' => Db::dateQuery($date, $date)], ['adid', 'country', 'device', 'os', 'referer']);
$perf = Performance::exists($p, $date);
// classify the clicks according to AD ID
$classify = \Click::classify($clicks, 'adid');
$countryWise = $deviceWise = $osWise = $refWise = [];
foreach ($classify as $key => $value) {
$ad = \Ad::find($adsInfo, $key, ['user_id', 'url']);
$advert = Usr::find($advertisers, $ad->user_id, ['_id', 'meta', 'email', 'org_id']);
$advertPerf = Usr::findPerf($advPerfs, $advert, $date);
$countries = \Click::classify($value, 'country');
foreach ($countries as $country => $records) {
$updateData = [];
$adClicks = count($records);
ArrayMethods::counter($countryWise, $country, $adClicks);
$pComm = \Commission::campaignRate($key, $commInfo, $country, array_merge(['type' => 'both', 'publisher' => $p], $dq));
$earning = \Ad::earning($pComm, $adClicks);
ArrayMethods::copy($earning, $updateData);
$updateData['profit'] = $updateData['revenue'] - $updateData['payout'];
$updateData['revenue'] = $updateData['payout'];
$perf->update($updateData);
$aComm = \Commission::campaignRate($key, $commInfo, $country, array_merge(['type' => 'advertiser'], $dq));
$updateData = [];
$earning = \Ad::earning($aComm, $adClicks);
ArrayMethods::copy($earning, $updateData);
$advertPerf->update($updateData);
}
$deviceWise = Click::classifyInfo(['clicks' => $value, 'type' => 'device', 'arr' => $deviceWise]);
$osWise = Click::classifyInfo(['clicks' => $value, 'type' => 'os', 'arr' => $osWise]);
$refWise = Click::classifyInfo(['clicks' => $value, 'type' => 'referer', 'arr' => $refWise]);
}
$msg = 'Performance saved for user: ' . $p->email . ' with clicks: ' . $perf->clicks . ' impressions: ' . $perf->impressions;
$this->log($msg);
$splitCountry = ArrayMethods::topValues($countryWise);
$splitCountry['rest'] = array_sum($countryWise) - array_sum($splitCountry);
$meta = ['country' => $splitCountry, 'device' => ArrayMethods::topValues($deviceWise, count($deviceWise)), 'os' => ArrayMethods::topValues($osWise, count($osWise)), 'referer' => ArrayMethods::topValues($refWise, count($refWise))];
$perf->meta = $meta;
$perf->save();
}
foreach ($advPerfs as $key => $perf) {
$msg = 'Saving performance for advertiser: ' . $key . ' with clicks: ' . $perf->clicks . ' earning: ' . $perf->revenue . ' impressions: ' . $perf->impressions;
$this->log($msg);
$perf->save();
}
}