当前位置: 首页>>代码示例>>PHP>>正文


PHP Ad::first方法代码示例

本文整理汇总了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);
 }
开发者ID:vNative,项目名称:vnative,代码行数:34,代码来源:advertiser.php

示例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);
 }
开发者ID:vNative,项目名称:vnative,代码行数:12,代码来源:report.php

示例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;
 }
开发者ID:vNative,项目名称:vnative,代码行数:11,代码来源:campaign.php

示例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']);
 }
开发者ID:vNative,项目名称:vnative,代码行数:16,代码来源:insight.php

示例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);
 }
开发者ID:vNative,项目名称:vnative,代码行数:14,代码来源:campaign.php

示例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));
 }
开发者ID:vNative,项目名称:vnative,代码行数:29,代码来源:publisher.php

示例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;
     }
 }
开发者ID:vNative,项目名称:vnative,代码行数:79,代码来源:api.php

示例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();
     }
 }
开发者ID:vNative,项目名称:vnative,代码行数:48,代码来源:cron.php


注:本文中的Ad::first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。