本文整理汇总了PHP中Model_Ad::loaded方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Ad::loaded方法的具体用法?PHP Model_Ad::loaded怎么用?PHP Model_Ad::loaded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Ad
的用法示例。
在下文中一共展示了Model_Ad::loaded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_get
public function action_get()
{
try {
if (is_numeric($id_ad = $this->request->param('id'))) {
$ad = new Model_Ad();
//get distance to the ad
if (isset($this->_params['latitude']) and isset($this->_params['longitude'])) {
$ad->select(array(DB::expr('degrees(acos(sin(radians(' . $this->_params['latitude'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $this->_params['latitude'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $this->_params['longitude'] . ' - `longitude`))))) * 69.172'), 'distance'));
}
$ad->where('id_ad', '=', $id_ad)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->cached()->find();
if ($ad->loaded()) {
$a = $ad->as_array();
$a['price'] = i18n::money_format($ad->price);
$a['images'] = array_values($ad->get_images());
$a['category'] = $ad->category->as_array();
$a['location'] = $ad->location->as_array();
$a['user'] = Controller_Api_Users::get_user_array($ad->user);
$a['customfields'] = Model_Field::get_by_category($ad->id_category);
//sorting by distance, lets add it!
if (isset($ad->distance)) {
$a['distance'] = i18n::format_measurement($ad->distance);
}
$a['url'] = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
$this->rest_output(array('ad' => $a));
} else {
$this->_error(__('Advertisement not found'), 404);
}
} else {
$this->_error(__('Advertisement not found'), 404);
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
return;
}
}
示例2: before
/**
* Automatically executed before the widget action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
$ad = new Model_Ad();
$ad->where('seotitle', '=', Request::current()->param('seotitle'))->limit(1)->find();
if ($ad->loaded()) {
$this->id_ad = $ad->id_ad;
}
}
示例3: action_user_contact
public function action_user_contact()
{
$ad = new Model_Ad($this->request->param('id'));
//message to user
if ($ad->loaded() and $this->request->post()) {
$user = new Model_User($ad->id_user);
//require login to contact
if ((core::config('advertisement.login_to_contact') == TRUE or core::config('general.messaging') == TRUE) and !Auth::instance()->logged_in()) {
Alert::set(Alert::INFO, __('Please, login before contacting'));
HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
}
if (captcha::check('contact')) {
//check if user is loged in
if (Auth::instance()->logged_in()) {
$email_from = $this->user->email;
$name_from = $this->user->name;
} else {
$email_from = core::post('email');
$name_from = core::post('name');
}
//akismet spam filter
if (!core::akismet($name_from, $email_from, core::post('message'))) {
if (core::config('general.messaging')) {
//price?
$price = (core::post('price') !== NULL and is_numeric(core::post('price'))) ? core::post('price') : NULL;
$ret = Model_Message::send_ad(core::post('message'), $this->user, $ad->id_ad, $price);
} else {
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
} else {
$file = NULL;
}
//contact email is set use that one
if (isset($ad->cf_contactemail) and Valid::email($ad->cf_contactemail)) {
$to = $ad->cf_contactemail;
} else {
$to = NULL;
}
$ret = $user->email('user-contact', array('[EMAIL.BODY]' => core::post('message'), '[AD.NAME]' => $ad->title, '[EMAIL.SENDER]' => $name_from, '[EMAIL.FROM]' => $email_from, '[URL.AD]' => Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle))), $email_from, $name_from, $file, $to);
}
//if succesfully sent
if ($ret) {
Alert::set(Alert::SUCCESS, __('Your message has been sent'));
// we are updating field of visit table (contact)
Model_Visit::contact_ad($ad->id_ad);
} else {
Alert::set(Alert::ERROR, __('Message not sent'));
}
HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
} else {
Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.'));
}
} else {
Alert::set(Alert::ERROR, __('Captcha is not correct'));
HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
}
}
}
示例4: is_favorite
/**
* is favorite?
* @param Model_User $user user
* @param Model_Ad $ad ad
* @return boolean
*/
public static function is_favorite(Model_User $user, Model_Ad $ad)
{
if ($user->loaded() and $ad->loaded()) {
$fav = new Model_Favorite();
$fav->where('id_user', '=', $user->id_user)->where('id_ad', '=', $ad->id_ad)->find();
if ($fav->loaded()) {
return TRUE;
}
}
return FALSE;
}
示例5: before
/**
* Automatically executed before the widget action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
$ad = new Model_Ad();
$user_ads = clone $ad;
//get current ad do not filter by user since admin also can see
$ad->where('seotitle', '=', Request::current()->param('seotitle'))->limit(1)->find();
if ($ad->loaded() and Auth::instance()->logged_in()) {
$user = Auth::instance()->get_user();
if ($user->id_role == Model_Role::ROLE_ADMIN or $user->id_user == $ad->id_user) {
$this->ad = $ad;
$this->user_ads = $user_ads->where('id_user', '=', $ad->id_user)->find_all();
}
}
}
示例6: action_create
public function action_create()
{
try {
if (!is_numeric(core::request('id_ad')) or !is_numeric(core::request('id_product')) or !is_numeric(core::request('id_user'))) {
$this->_error(__('Missing parameters'), 501);
} else {
$user = new Model_User(core::request('id_user'));
$ad = new Model_Ad(core::request('id_ad'));
if ($user->loaded() and $ad->loaded()) {
$id_product = core::request('id_product');
$amount = core::request('amount');
//in case not set by request
if (!is_numeric($amount)) {
//get original price for the product
switch ($id_product) {
case Model_Order::PRODUCT_CATEGORY:
$amount = $ad->category->price;
break;
case Model_Order::PRODUCT_TO_TOP:
$amount = core::config('payment.pay_to_go_on_top');
break;
case Model_Order::PRODUCT_TO_FEATURED:
$amount = Model_Order::get_featured_price(core::request('featured_days'));
break;
case Model_Order::PRODUCT_AD_SELL:
$amount = $ad->price;
break;
default:
$plan = new Model_Plan($id_product);
$amount = $plan->loaded() ? $plan->price : 0;
break;
}
}
$order = Model_Order::new_order($ad, $user, $id_product, $amount, core::request('currency'), Model_Order::product_desc(core::request('id_product')), core::request('featured_days'));
$order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id'));
$order->save();
$this->rest_output(array('order' => self::get_order_array($order)));
} else {
$this->_error(__('User or Ad not loaded'), 501);
}
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
}
}
示例7: action_user_contact
public function action_user_contact()
{
$ad = new Model_Ad($this->request->param('id'));
//message to user
if ($ad->loaded() and $this->request->post()) {
$user = new Model_User($ad->id_user);
if (captcha::check('contact')) {
//akismet spam filter
if (!core::akismet(core::post('name'), core::post('email'), core::post('message'))) {
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
} else {
$file = NULL;
}
$ret = $user->email('user.contact', array('[EMAIL.BODY]' => core::post('message'), '[AD.NAME]' => $ad->title, '[EMAIL.SENDER]' => core::post('name'), '[EMAIL.FROM]' => core::post('email')), core::post('email'), core::post('name'), $file);
//if succesfully sent
if ($ret) {
Alert::set(Alert::SUCCESS, __('Your message has been sent'));
// we are updating field of visit table (contact)
$visit_contact_obj = new Model_Visit();
$visit_contact_obj->where('id_ad', '=', $this->request->param('id'))->order_by('created', 'desc')->limit(1)->find();
try {
$visit_contact_obj->contacted = 1;
$visit_contact_obj->save();
} catch (Exception $e) {
//throw 500
throw new HTTP_Exception_500($e->getMessage());
}
} else {
Alert::set(Alert::ERROR, __('Message not sent'));
}
Request::current()->redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
} else {
Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.'));
}
} else {
Alert::set(Alert::ERROR, __('You made some mistake'));
}
}
}
示例8: multiple_mails
public function multiple_mails($receivers)
{
foreach ($receivers as $num => $receiver_id) {
if (is_numeric($receiver_id)) {
$ad = new Model_Ad($receiver_id);
if ($ad->loaded()) {
$cat = $ad->category;
$usr = $ad->user;
//we get the QL, and force the regen of token for security
$url_ql = $usr->ql('ad', array('category' => $cat->seoname, 'seotitle' => $ad->seotitle), TRUE);
$ret = $usr->email('ads-activated', array('[USER.OWNER]' => $usr->name, '[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title));
}
}
}
}
示例9: action_favorites
public function action_favorites()
{
$user = Auth::instance()->get_user();
//favs or unfavs
if (is_numeric($id_ad = $this->request->param('id'))) {
$this->auto_render = FALSE;
$this->template = View::factory('js');
$ad = new Model_Ad($id_ad);
//ad exists
if ($ad->loaded()) {
//if fav exists we delete
if (Model_Favorite::unfavorite($user->id_user, $id_ad) === TRUE) {
//fav existed deleting
$this->template->content = __('Deleted');
} else {
//create the fav
Model_Favorite::favorite($user->id_user, $id_ad);
$this->template->content = __('Saved');
}
} else {
$this->template->content = __('Ad Not Found');
}
} else {
$this->template->title = __('My Favorites');
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
Controller::$full_width = TRUE;
$this->template->styles = array('//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen');
$this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js';
$this->template->scripts['footer'][] = 'js/oc-panel/favorite.js';
$favorites = new Model_Favorite();
$favorites = $favorites->where('id_user', '=', $user->id_user)->order_by('created', 'desc')->find_all();
$this->template->bind('content', $content);
$this->template->content = View::factory('oc-panel/profile/favorites', array('favorites' => $favorites));
}
}
示例10: action_thanks
/**
* thanks for publish
* @return [type] [description]
*/
public function action_thanks()
{
$ad = new Model_Ad($this->request->param('id'));
if ($ad->loaded()) {
$page = Model_Content::get_by_title(Core::config('advertisement.thanks_page'));
//template header
$this->template->title = $page->loaded() ? $page->title : __('Thanks');
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
Breadcrumbs::add(Breadcrumb::factory()->set_title($ad->title)->set_url(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle))));
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
$this->template->bind('content', $content);
$this->template->content = View::factory('pages/ad/thanks', array('ad' => $ad, 'page' => $page));
} else {
//throw 404
throw HTTP_Exception::factory(404, __('Page not found'));
}
}
示例11: new_order
/**
* creates an order
* @param Model_Ad $ad
* @param Model_User $user
* @param integer $id_product
* @param numeric $amount
* @param string $currency
* @param string $description
* @return Model_Order
*/
public static function new_order(Model_Ad $ad = NULL, $user, $id_product, $amount, $currency = NULL, $description = NULL, $featured_days = NULL)
{
if ($currency === NULL) {
$currency = core::config('payment.paypal_currency');
}
if ($description === NULL) {
$description = Model_Order::product_desc($id_product);
}
//get if theres an unpaid order for this product and this ad
$order = new Model_Order();
if ($ad !== NULL and $ad->loaded()) {
$order->where('id_ad', '=', $ad->id_ad);
}
$order->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_product', '=', $id_product)->where('amount', '=', $amount)->where('currency', '=', $currency)->limit(1)->find();
//if no unpaid create order
if (!$order->loaded()) {
//add coupon ID and discount only if not AD_SELL
if (Model_Coupon::valid($id_product)) {
$amount = Model_Coupon::price($id_product, $amount);
$order->id_coupon = Model_Coupon::current()->id_coupon;
}
//create order
$order = new Model_Order();
$order->id_user = $user->id_user;
if ($ad !== NULL and $ad->loaded()) {
$order->id_ad = $ad->id_ad;
}
$order->id_product = $id_product;
$order->currency = $currency;
$order->amount = $amount;
$order->description = $description;
// check product
if ($order->id_product == Model_Order::PRODUCT_AD_SELL) {
// check if ad has VAT
if (isset($order->ad->cf_vatnumber) and $order->ad->cf_vatnumber and isset($order->ad->cf_vatcountry) and $order->ad->cf_vatcountry) {
$order->VAT_country = $order->ad->cf_vatcountry;
$order->VAT_number = $order->ad->cf_vatnumber;
$order->VAT = euvat::vat_by_country($order->ad->cf_vatcountry);
} elseif (isset($order->user->cf_vatnumber) and $order->user->cf_vatnumber and isset($order->user->cf_vatcountry) and $order->user->cf_vatcountry) {
$order->VAT_country = $order->user->cf_vatcountry;
$order->VAT_number = $order->user->cf_vatnumber;
$order->VAT = euvat::vat_by_country($order->user->cf_vatcountry);
}
} else {
if (core::config('payment.vat_country') and core::config('payment.vat_number')) {
$order->VAT_country = core::config('payment.vat_country');
$order->VAT_number = core::config('payment.vat_number');
$order->VAT = euvat::vat_by_country(core::config('payment.vat_country'));
}
}
//store how many days the ad is featured
if ($featured_days !== NULL and is_numeric($featured_days)) {
$order->featured_days = $featured_days;
}
try {
$order->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
//send email to user with link to pay
$url_checkout = $user->ql('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order));
$replace = array('[ORDER.ID]' => $order->id_order, '[ORDER.DESC]' => $order->description, '[URL.CHECKOUT]' => $url_checkout);
//$user->email('new-order',$replace);
}
return $order;
}
示例12: unfavorite
/**
* unfavorite an ad
* @param integer $id_user user
* @param integer $id_ad ad
* @return boolean
*/
public static function unfavorite($id_user, $id_ad)
{
//try to find the fav
$fav = new Model_Favorite();
$fav->where('id_user', '=', $id_user)->where('id_ad', '=', $id_ad)->find();
if ($fav->loaded()) {
$fav->delete();
// update ad favorite counter
$ad = new Model_Ad($id_ad);
if ($ad->loaded()) {
$ad->favorited--;
try {
$ad->save();
} catch (Exception $e) {
return FALSE;
}
}
return TRUE;
} else {
return FALSE;
}
}
示例13: action_cleanimages
/**
* cleans old pictures
* @return [type] [description]
*/
public function action_cleanimages()
{
$count_deleted = 0;
//loop for directory image
$folder = DOCROOT . 'images';
//year
foreach (new DirectoryIterator($folder) as $year) {
if ($year->isDir() and !$year->isDot() and is_numeric($year->getFilename())) {
//month
foreach (new DirectoryIterator($year->getPathname()) as $month) {
if ($month->isDir() and !$month->isDot() and is_numeric($month->getFilename())) {
//day
foreach (new DirectoryIterator($month->getPathname()) as $day) {
if ($day->isDir() and !$day->isDot() and is_numeric($day->getFilename())) {
//id_ad
foreach (new DirectoryIterator($day->getPathname()) as $id_ad) {
if ($id_ad->isDir() and !$id_ad->isDot() and is_numeric($id_ad->getFilename())) {
$delete = TRUE;
//if ad is available leave it, if not delete folder ID
$ad = new Model_Ad($id_ad->getFilename());
if ($ad->loaded() and $ad->status == Model_Ad::STATUS_PUBLISHED) {
$delete = FALSE;
}
//ok lets get rid of it!
if ($delete === TRUE) {
echo '<br>Deleting: ' . $id_ad->getFilename() . '---' . $id_ad->getPathname();
File::delete($id_ad->getPathname());
//if the ad was loaded means had a different status, put it like he doesnt have images.
if ($ad->loaded()) {
$ad->has_images = 0;
$ad->save();
//$ad->delete();//optional
}
$count_deleted++;
}
}
}
}
}
}
}
}
}
echo '<br>deleted ' . $count_deleted;
}
示例14: action_delete_image
public function action_delete_image()
{
try {
if (is_numeric($id_ad = $this->request->param('id')) and is_numeric($num_image = $this->_post_params['num_image'])) {
$ad = new Model_Ad();
$ad->where('id_ad', '=', $id_ad)->where('id_user', '=', $this->user->id_user)->find();
if ($ad->loaded()) {
if ($ret = $ad->delete_image($num_image)) {
$this->rest_output($ret);
} else {
$this->_error($ret);
}
} else {
$this->_error(__('Advertisement not found'), 404);
}
} else {
$this->_error(__('Advertisement not found'), 404);
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
return;
}
}
示例15: send_ad
/**
* send message to an advertisement
* @param string $message
* @param Model_User $user_from
* @param integer $id_ad
* @param integer $price negotiate price optionsl
* @return bool / model_message
*/
public static function send_ad($message, $user_from, $id_ad, $price = NULL)
{
//get the ad if its available, and user to who we need to contact
$ad = new Model_Ad();
$ad->where('id_ad', '=', $id_ad)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->find();
//ad loaded and is not your ad....
if ($ad->loaded() == TRUE and $user_from->id_user != $ad->id_user) {
//check if we already have a thread for that ad and user...then its a reply not a new message.
$msg_thread = new Model_Message();
$msg_thread->where('id_message', '=', DB::expr('id_message_parent'))->where('id_ad', '=', $id_ad)->where('id_user_from', '=', $user_from->id_user)->limit(1)->find();
//actually reply not new thread....
if ($msg_thread->loaded()) {
return self::reply($message, $user_from, $msg_thread->id_message, $price);
} else {
$ret = self::send($message, $user_from, $ad, $id_ad, NULL, $price);
//send email only if no device ID since he got the push notification already
if ($ret !== FALSE and !isset($ad->user->device_id)) {
$ad->user->email('messaging-ad-contact', array('[AD.NAME]' => $ad->title, '[FROM.NAME]' => $user_from->name, '[TO.NAME]' => $ad->user->name, '[DESCRIPTION]' => $message, '[URL.QL]' => $ad->user->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $ret->id_message))));
}
return $ret;
}
}
return FALSE;
}