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


PHP Ad::objectArr方法代码示例

本文整理汇总了PHP中Ad::objectArr方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::objectArr方法的具体用法?PHP Ad::objectArr怎么用?PHP Ad::objectArr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ad的用法示例。


在下文中一共展示了Ad::objectArr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: campaigns

 /**
  * @before _secure
  */
 public function campaigns()
 {
     $this->seo(array("title" => "Campaigns"));
     $view = $this->getActionView();
     $limit = RM::get("limit", 20);
     $page = RM::get("page", 1);
     $category = RM::get("category", []);
     $keyword = RM::get("keyword", '');
     $query = ["live = ?" => true, "org_id = ?" => $this->org->_id];
     $query["meta.private"] = ['$ne' => true];
     $today = date('Y-m-d');
     if (count($category) > 0) {
         // if you want AND query instead of OR query then replace '$in' --> '$all'
         $query["category"] = ['$in' => Ad::setCategories($category)];
     }
     if ($keyword) {
         $query["title"] = Utils::mongoRegex($keyword);
     }
     switch (RM::get("action")) {
         case 'trending':
             $ads = \Ad::all($query, [], 'modified', 'desc');
             $fields = Shared\Services\User::fields('Ad');
             $ids = array_keys($ads);
             $ads = Ad::objectArr($ads, $fields);
             $limit = $count = 30;
             $clickCol = Registry::get("MongoDB")->clicks;
             $results = $clickCol->aggregate([['$match' => ['adid' => ['$in' => Db::convertType($ids, 'id')], 'is_bot' => false, 'created' => Db::dateQuery(RM::get("start", $today), RM::get("end", $today))]], ['$project' => ['adid' => 1, '_id' => 1]], ['$group' => ['_id' => '$adid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]], ['$limit' => $limit]]);
             $ans = [];
             foreach ($results as $r) {
                 $a = (object) $r;
                 $key = Utils::getMongoID($a->_id);
                 $ans[$key] = $ads[$key];
             }
             $ads = $ans;
             break;
         default:
             $count = \Ad::count($query);
             $ads = \Ad::all($query, [], 'modified', 'desc', $limit, $page);
             break;
     }
     //private campaigns
     $query["meta.private"] = true;
     $query["meta.access"] = ['$in' => [$this->user->id]];
     $pads = \Ad::all($query, [], 'modified', 'desc');
     $categories = \Category::all(["org_id = ?" => $this->org->_id], ['name', '_id']);
     $user = $this->user;
     $model = null;
     $rate = null;
     if (array_key_exists("campaign", $user->meta)) {
         $model = $user->meta["campaign"]["model"];
         $rate = $user->meta["campaign"]["rate"];
     }
     $view->set(['limit' => $limit, 'page' => $page, 'count' => $count, 'ads' => $ads, 'model' => $model, 'rate' => $rate, 'categories' => $categories, 'coverage' => $category, 'tdomains' => \Shared\Services\User::trackingLinks($this->user, $this->org), 'keyword' => $keyword, 'pads' => $pads]);
 }
开发者ID:vNative,项目名称:vnative,代码行数:57,代码来源:publisher.php

示例2: 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


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