本文整理汇总了PHP中Ad::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::validate方法的具体用法?PHP Ad::validate怎么用?PHP Ad::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ad
的用法示例。
在下文中一共展示了Ad::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @before _secure
*/
public function create()
{
$this->_create();
$view = $this->getActionView();
if (RM::type() == 'POST') {
$img = null;
// give preference to uploaded image
$img = $this->_upload('image', 'images', ['extension' => 'jpe?g|gif|bmp|png|tif']);
if (!$img) {
$img_url = RM::post("image_url");
$img = Shared\Utils::downloadImage($img_url);
}
if (!$img) {
return $view->set('message', 'Failed to upload the image');
}
$expiry = RM::post('expiry');
$campaign = new \Ad(['user_id' => RM::post('advert_id'), 'title' => RM::post('title'), 'description' => RM::post('description'), 'org_id' => $this->org->_id, 'url' => RM::post('url'), 'preview_url' => RM::post('preview_url'), 'category' => \Ad::setCategories(RM::post('category')), 'image' => $img, 'type' => RM::post('type', 'article'), 'device' => RM::post('device', ['all']), 'live' => false]);
$visibility = RM::post('visibility', 'public');
if ($visibility === "private") {
$campaign->meta = ['private' => true];
}
$permission = RM::post('permission', false);
if ($permission == "yes") {
$campaign->meta = ['permission' => true];
}
if ($expiry) {
$campaign->expiry = $expiry;
}
try {
if ($campaign->type === "video") {
$url = RM::post('videoUrl');
$ytdl = new Downloader($url);
$campaign->getMeta()['processing'] = true;
$campaign->getMeta()['videoUrl'] = $ytdl->getUrl();
}
} catch (\Exception $e) {
// Invalid URL
return $view->set("errors", ['videoUrl' => ["Pass a valid youtube video URL"]]);
}
if (!$campaign->validate()) {
return $view->set("errors", $campaign->errors);
}
$campaign->save();
$models = RM::post('model');
$comm_desc = RM::post('comm_desc');
$revenue = RM::post('revenue');
$rate = RM::post('rate');
$coverage = RM::post('coverage');
foreach ($models as $key => $value) {
$commission = new \Commission(['ad_id' => $campaign->_id, 'description' => $comm_desc[$key], 'model' => $value, 'rate' => $this->currency($rate[$key]), 'revenue' => $this->currency($revenue[$key]), 'coverage' => $coverage[$key]]);
$commission->save();
}
Registry::get("session")->set('$flashMessage', 'Campaign Created successfully!!');
$this->redirect("/campaign/manage.html");
}
}
示例2: 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();
}
}