本文整理汇总了PHP中Ad::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Ad::set方法的具体用法?PHP Ad::set怎么用?PHP Ad::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ad
的用法示例。
在下文中一共展示了Ad::set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildAd
/**
* @param \ApiParam $params
* @param \User $user
* @return \Ad
* @throws \Exception
*/
public static function buildAd(\ApiParam $params, \User $user)
{
if ($params->adId) {
$ad = self::loadAndCheck($params->adId, $user, false, $params->udid);
$ad->set('modifyIp', \Ip::remote_addr());
} else {
$ad = new \Ad();
$ad->userIp = \Ip::remote_addr();
$ad->status = \Ad::STATUS_ACTIVE;
$ad->userId = $user->id;
//City 编辑信息不能更换city
$city = \City::loadByName($params->cityEnglishName);
if (!isset(\Page::$context['city'])) {
\Page::$context['city'] = $city;
}
if (!$city) {
throw new \Exception('invalid city', 504);
}
$ad->areaCityLevelId = $city->oid;
$ad->set('totalReport', 0);
$ad->set('MasterCheckDate', 0);
}
//Category
if (!$params->adId) {
$ad->categoryEnglishName = $params->categoryEnglishName;
} else {
$ad->categoryEnglishName = $ad->categoryEnglishName;
}
try {
$category = \Category::loadByName($ad->categoryEnglishName);
} catch (\Exception $e) {
throw new \Exception('该类目不存在', '407');
}
if ($category->level != \Category::LEVEL_SECOND) {
throw new \Exception('信息只能发布到二级类目', '406');
}
//联系方式
$params->contact = $params->contact ?: $params->mobile;
//@todo 如果没有写发布人的,加上发布人属性,保留到2012年9月2日 by zhaojun
if (!$params->faburen) {
$ad->setPosterType(null);
if ($ad->get('faburen')) {
$params->faburen = $ad->get('faburen');
} else {
$params->faburen = 'm33660';
//dirty fix, but it works(liuweili@baixing.com)
}
}
$metas = $category->metas();
if ($params->wanted) {
switch ($category->parentEnglishName) {
case 'gongzuo':
case 'jianzhi':
$metas = \Category::loadByName('qiuzhijianli')->metas();
break;
case 'ershou':
$metas = \Category::loadByName('qiumai')->metas();
break;
case 'cheliang':
$metas = \Category::loadByName('cheliangqiugou')->metas();
break;
default:
$metas = \Category::loadByName('qiufang')->metas();
break;
}
}
foreach ($metas as $meta) {
$data = $meta->dataValue($params);
$dataWithoutUnit = $params->{$meta->name};
if (strpos($meta->style, 'required') !== false && !array_filter($data, function ($a) {
return $a !== null && $a !== '';
})) {
if (!array_key_exists('地区', $data) && $params->api_key == 'api_mobile_android') {
\InstantCounter::count('fabubitian');
throw new \Exception('属性' . $meta->displayName . '是必填项,请填写', '422');
}
}
if ($meta->maxlength && mb_strlen($dataWithoutUnit) > $meta->maxlength) {
throw new \Exception($meta->displayName . '不能超过' . $meta->maxlength . '个字', '423');
}
foreach ($data as $key => $value) {
$ad->set($key, is_array($value) ? implode(',', $value) : (string) $value);
}
}
if (!$ad->title) {
throw new \Exception('属性标题是必填项,请填写', '422');
}
//Images
if (is_string($params->images) && strlen($params->images)) {
$params->image = explode(',', $params->images);
}
$images = self::validImage($params->image);
$images = array_slice($images, 0, $user->imageLimit(\City::loadByName($params->cityEnglishName)));
if ($ad->categoryEnglishName != 'ktvjiuba') {
//.........这里部分代码省略.........