本文整理汇总了PHP中Ad::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::first方法的具体用法?PHP Ad::first怎么用?PHP Ad::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ad
的用法示例。
在下文中一共展示了Ad::first方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: campaign
/**
* @before _secure
*/
public function campaign($id)
{
$ad = \Ad::first(['_id' => $id, 'org_id' => $this->org->_id]);
if (!$ad) {
$this->_404();
}
$this->seo(["title" => $ad->title]);
$view = $this->getActionView();
if (RM::post("action")) {
// action value already checked in _postback func
$this->_postback('add', ['ad' => $ad]);
}
if (RM::type() === 'DELETE') {
$this->_postback('delete');
}
$start = RM::get("start", date('Y-m-d', strtotime("-7 day")));
$end = RM::get("end", date('Y-m-d'));
$limit = RM::get("limit", 10);
$page = RM::get("page", 1);
$query = ['adid' => Db::convertType($id), 'created' => Db::dateQuery($start, $end)];
$clicks = \Click::all($query, [], 'created', 'desc', $limit, $page);
$count = \Click::count($query);
$cf = Utils::getConfig("cf", "cloudflare");
$view->set("domain", $cf->api->domain)->set("clicks", $clicks)->set("count", $count)->set('advertiser', $this->user);
$comms = Commission::all(["ad_id = ?" => $id], ['model', 'coverage', 'revenue', 'description']);
$models = ArrayMethods::arrayKeys($comms, 'model');
$advertiser = User::first(["id = ?" => $ad->user_id], ['name']);
$categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
$this->_postback('show', ['ad' => $ad]);
$view->set("ad", $ad)->set("comms", $comms)->set("categories", $categories)->set("advertiser", $advertiser)->set('models', $models)->set("start", $start)->set("end", $end);
}
示例2: ad
/**
* @before _secure
* @after _displayData
*/
public function ad($id)
{
$this->seo(array("title" => "AD Report"));
$view = $this->getActionView();
$ad = \Ad::first(['org_id = ?' => $this->org->_id, 'id = ?' => $id]);
$count = Db::count(['created' => Db::dateQuery($this->start, $this->end), 'adid' => $ad->_id, 'is_bot' => false]);
$view->set('ad', $ad)->set('clicks', $count);
}
示例3: displayData
public static function displayData($ads = [])
{
$result = [];
$ads = (array) $ads;
foreach ($ads as $a) {
$a = (object) $a;
$find = \Ad::first(['_id' => $a->_id], ['title', 'image', 'url']);
$result[] = ['_id' => $a->_id, 'clicks' => $a->clicks, 'title' => $find->title, 'image' => $find->image, 'url' => $find->url];
}
return $result;
}
示例4: campaign
/**
* @before _secure
* @after setDate
*/
public function campaign($id = null)
{
$this->seo(["title" => "Campaign Insights"]);
$view = $this->getActionView();
$org = $this->org;
$ad = Ad::first(['_id' => $id, 'org_id' => $org->_id]);
if (!$ad) {
$this->_404();
}
$data = Shared\Services\Campaign::performance($id, ['start' => $this->start, 'end' => $this->end, 'pid' => $this->user_id, 'meta' => true]);
$view->set('stats', $data['stats'])->set('total', $data['total']);
}
示例5: delete
/**
* @before _secure
*/
public function delete($id)
{
parent::delete($id);
$view = $this->getActionView();
$ad = \Ad::first(["_id = ?" => $id, "org_id = ?" => $this->org->_id]);
if (!$ad) {
return $view->set('message', 'Invalid Request!!');
}
$msg = $ad->delete();
$view->set($msg);
}
示例6: createLink
/**
* @before _verified
*/
public function createLink()
{
$this->JSONView();
$view = $this->getActionView();
$adid = RM::post("adid");
if (!$adid) {
return $view->set('message', "Invalid Request");
}
$ad = \Ad::first(["_id = ?" => $adid, "live = ?" => true], ['_id', 'title']);
if (!$ad) {
return $view->set('message', "Invalid Request");
}
$user = User::first(["id = ?" => RM::post("aff_id")]) ?? $this->user;
$tdomains = Shared\Services\User::trackingLinks($user, $this->org);
if (RM::post("domain")) {
$domain = RM::post("domain");
} else {
$domain = $this->array_random($tdomains);
}
$link = Link::first(["ad_id = ?" => $ad->_id, "user_id = ?" => $user->_id], ['domain', '_id']);
if (!$link) {
$link = new Link(['user_id' => $user->_id, 'ad_id' => $ad->_id, 'domain' => $domain, 'live' => true]);
$link->save();
}
$view->set('message', $ad->title)->set('link', $link->getUrl($domain));
}
示例7: campaign
/**
* @before _secure
* @after _cleanUp
*/
public function campaign($id = null)
{
$view = $this->getActionView();
$org = $this->_org;
$active = RequestMethods::get('active', 1);
$fields = ['_id', 'title', 'description', 'image', 'url', 'device', 'expiry', 'created'];
$commFields = ['model', 'rate', 'revenue', 'coverage'];
if ($id) {
$campaign = Ad::first(['_id' => $id, 'org_id' => $org->_id], $fields);
} else {
$campaign = null;
}
if ($id && !$campaign) {
return $this->failure('30');
}
$type = RequestMethods::type();
switch ($type) {
case 'GET':
if (!$id) {
// display list of campaigns
$ads = Ad::all(['org_id' => $org->_id, 'live' => $active], $fields);
$ads = Ad::objectArr($ads, $fields);
$results = [];
foreach ($ads as $id => $a) {
$arr = Utils::toArray($a);
$comms = Commission::all(['ad_id' => $a->_id], $commFields);
$arr['commissions'] = Ad::objectArr($comms, $commFields);
$results[$id] = (object) $arr;
}
$data = ['campaigns' => $results];
$view->set('data', $data);
} else {
$ads = Ad::objectArr($campaign, $fields);
$campaign = array_shift($ads);
$comm = Commission::all(['ad_id' => $campaign->_id], $commFields);
$data = ['campaign' => $campaign, 'commissions' => Commission::objectArr($comm, $commFields)];
$view->set('data', $data);
}
break;
case 'POST':
if ($id) {
// edit a particular campaign
} else {
// create a new campaign
$fields = ['title', 'description', 'url', 'expiry', 'category', 'device', 'user_id'];
$img = RequestMethods::post('image');
// contains image url
$campaign = new Ad(['org_id' => $org->_id, 'type' => 'article', 'image' => Utils::media($img, 'download')]);
foreach ($fields as $f) {
$campaign->{$f} = RequestMethods::post($f);
}
$view->set('success', false);
$visibility = RequestMethods::post('visibility', 'public');
if ($visibility === 'private') {
$campaign->getMeta()['private'] = true;
}
$opts = ['devices' => array_keys(Shared\Markup::devices()), 'advertisers' => $org->users('advertiser', false)];
if (true) {
// $campaign->save();
$arr = ArrayMethods::reArray($_POST['commissions']);
var_dump($arr);
var_dump($_POST['commissions']);
$view->set('success', true);
} else {
$data = ['errors' => $campaign->errors];
$view->set('data', $data);
}
}
break;
case 'DELETE':
$message = $campaign->delete();
$view->set($message);
break;
}
}
示例8: importCampaigns
/**
* Process the Meta table for campaign urls and create the
* campaign from the corresponding URL
*/
protected function importCampaigns()
{
$metas = \Meta::all(['prop = ?' => 'campImport']);
$users = [];
$orgs = [];
foreach ($metas as $m) {
$user = Usr::find($users, $m->propid, ['_id', 'org_id', 'email', 'meta']);
$org = \Organization::find($orgs, $user->org_id);
$categories = \Category::all(['org_id' => $org->_id], ['_id', 'name']);
$categories = array_values($categories);
$category = $categories[array_rand($categories)];
// fetch ad info foreach URL
$advert_id = $m->value['advert_id'];
$comm = $m->value['campaign'] ?? $org->meta;
if (!isset($comm['model']) || !isset($comm['rate'])) {
continue;
}
$urls = $m->value['urls'];
foreach ($urls as $url) {
$ad = \Ad::first(['org_id' => $org->_id, 'url' => $url]);
if ($ad) {
continue;
}
// already crawled URL may be due to failed cron earlier
$data = Utils::fetchCampaign($url);
$image = Utils::downloadImage($data['image']);
if (!$image) {
$image = '';
}
$ad = new \Ad(['user_id' => $advert_id, 'org_id' => $org->_id, 'title' => $data['title'], 'description' => $data['description'], 'url' => $url, 'image' => $image, 'category' => [$category->_id], 'type' => 'article', 'live' => false, 'device' => ['ALL']]);
if ($ad->validate()) {
$ad->save();
$rev = $comm['revenue'] ?? 1.25 * (double) $comm['rate'];
$commission = new \Commission(['ad_id' => $ad->_id, 'model' => $comm['model'], 'rate' => $comm['rate'], 'revenue' => round($rev, 6), 'coverage' => ['ALL']]);
$commission->save();
} else {
var_dump($ad->getErrors());
}
}
$msg = 'Campaigns imported for the user: ' . $user->email;
$this->log($msg);
$m->delete();
}
}