本文整理汇总了PHP中Ad::setCategories方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::setCategories方法的具体用法?PHP Ad::setCategories怎么用?PHP Ad::setCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ad
的用法示例。
在下文中一共展示了Ad::setCategories方法的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]);
}
示例2: edit
/**
* @before _secure
* @after _csrfToken
*/
public function edit($id)
{
$c = \Ad::first(["_id = ?" => $id, "org_id = ?" => $this->org->_id]);
if (!$c) {
$this->redirect("/campaign/manage.html");
}
$this->seo(['title' => sprintf("Edit: %s", $c->title), 'description' => 'Edit the campaign']);
$view = $this->getActionView();
$categories = \Category::all(['org_id' => $this->org->id], ['_id', 'name']);
if (RM::type() === 'DELETE') {
$this->_commissionDel($c, $view);
}
if (RM::type() === 'POST') {
$action = RM::post("action");
switch ($action) {
case 'targeting':
$campaign = $c;
$campaign->device = RM::post('device', $campaign->device);
$visibility = RM::post('visibility', 'public');
if ($visibility === "private") {
$campaign->getMeta()['private'] = true;
} else {
unset($campaign->getMeta()['private']);
}
$permission = RM::post('permission', false);
if ($permission == "yes") {
$campaign->getMeta()['permission'] = true;
} else {
unset($campaign->getMeta()['permission']);
}
$campaign->save();
$view->set("message", "Campaign updated!!");
break;
case 'adedit':
$c->category = \Ad::setCategories(RM::post('category'));
$c->title = RM::post('title');
$c->url = RM::post("url");
$c->description = RM::post('description');
$c->device = RM::post('device', ['all']);
$expiry = RM::post('expiry');
if ($expiry) {
$c->expiry = $expiry;
}
if (!$c->validate()) {
$view->set("errors", $c->errors);
$view->set("message", "Validation Failed");
} else {
$c->save();
$view->set("message", "Campaign updated!!");
}
break;
case 'imageUpload':
$message = "Image Updated Successfully!!";
$img = ' ';
$imgUrl = RM::post("imageUrl");
if ($_FILES['image']['name']) {
$img = Utils::media('image', 'upload');
} else {
if ($imgUrl) {
$img = Utils::media($imgUrl, 'download');
}
}
if (strlen($img) > 4) {
// to check if media was uploaded successfully
Utils::media($c->image, 'remove');
} else {
$img = $c->image;
$message = "Please Upload a valid Image!!";
}
$c->image = $img;
$c->save();
$view->set("message", $message);
break;
case 'commadd':
case 'commedit':
$cid = RM::post('cid');
if ($cid) {
$comm = Commission::first(["id" => $cid, "ad_id" => $c->_id]);
} else {
$comm = new \Commission(['ad_id' => $c->_id, 'live' => true]);
}
$comm->model = RM::post('model');
$comm->description = RM::post('description');
$comm->rate = $this->currency(RM::post('rate'));
$comm->revenue = $this->currency(RM::post('revenue'));
$comm->coverage = RM::post('coverage', ['ALL']);
if ($comm->validate()) {
$comm->save();
$view->set("message", "Commission updated!!");
} else {
$view->set("errors", $comm->errors);
$view->set("message", "Validation Failed");
}
break;
}
}
//.........这里部分代码省略.........