/**
  * Function to notify subscribers
  */
 public static function notify(Model_Ad $ad)
 {
     $subscribers = new Model_Subscribe();
     if ($ad->price > 0) {
         $subscribers->where_open()->where(DB::EXPR((int) $ad->price), 'BETWEEN', array('min_price', 'max_price'))->or_where('max_price', '=', 0)->where_close();
     }
     //location is set
     if (is_numeric($ad->id_location)) {
         $subscribers->where('id_location', 'in', array($ad->id_location, 0));
     }
     //filter by category, 0 means all the cats, in case was not set
     $subscribers->where('id_category', 'in', array($ad->id_category, 0));
     $subscribers = $subscribers->find_all();
     $subscribers_id = array();
     // array to be filled with user emails
     foreach ($subscribers as $subs) {
         // do not repeat same users.
         if (!in_array($subs->id_user, $subscribers_id)) {
             $subscribers_id[] = $subs->id_user;
         }
     }
     // query for getting users, transform it to array and pass to email function
     if (count($subscribers_id) > 0) {
         $query = DB::select('email')->select('name')->from('users')->where('id_user', 'IN', $subscribers_id)->where('status', '=', Model_User::STATUS_ACTIVE)->execute();
         $users = $query->as_array();
         // Send mails like in newsletter, to multiple users simultaneously
         if (count($users) > 0) {
             $url_ad = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
             $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $ad->title);
             Email::content($users, '', core::config('email.notify_email'), core::config('general.site_name'), 'ads-subscribers', $replace);
         }
     }
 }
Exemple #2
0
 /**
  * Function for saving emails to subscribers
  */
 public static function find_subscribers($data, $price, $seotitle, $email)
 {
     // locations are optional , get wiget settings for locations and categories
     $jsonObj = json_decode(core::config('widget.Widget_Subscribers_1373877069'), true);
     $subscribers = new Model_Subscribe();
     $category = new Model_Category($data['cat']);
     if ($category->loaded()) {
         if ($category->id_category_parent !== 1) {
             $cat_parent = $category->id_category_parent;
         }
     }
     //only min/max price is required in widget settings
     if ($price !== '0') {
         $subscribers->where('min_price', '<=', $price)->where('max_price', '>=', $price);
     } else {
         $subscribers->where('min_price', '<=', 0)->where('max_price', '>=', 0);
     }
     //location is set
     if ($data['loc'] != NULL and $jsonObj['data']['locations'] !== '0') {
         $subscribers = $subscribers->where('id_location', '=', $data['loc']);
     }
     //category is set
     if ($jsonObj['data']['categories'] !== '0') {
         $subscribers = $subscribers->where('id_category', 'IN', array($data['cat'], $cat_parent));
     }
     $subscribers = $subscribers->find_all();
     $subscribers_id = array();
     // array to be filled with user emails
     foreach ($subscribers as $subs) {
         // do not repeat same users.
         if (!in_array($subs->id_user, $subscribers_id)) {
             $subscribers_id[] = $subs->id_user;
         }
     }
     // query for getting users, transform it to array and pass to email function
     if (count($subscribers_id) > 0) {
         $query = DB::select('email')->select('name')->from('users')->where('id_user', 'IN', $subscribers_id)->where('status', '=', Model_User::STATUS_ACTIVE)->execute();
         $users = $query->as_array();
         $user = new Model_User();
         $user = $user->where('email', '=', $email)->where('status', '=', Model_User::STATUS_ACTIVE)->limit(1)->find();
         // Send mails like in newsletter, to multiple users simultaneously @TODO NOT YET READY
         if (count($users) > 0) {
             $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
             if (!Email::send($users, '', "Advertisement is created on " . core::config('general.site_name') . "!", "Hello, You may be interested in this one: \n\n " . $data['title'] . "! \n\n\n                                        You can visit this link to see advertisement " . $url_ad, "no-reply " . core::config('general.site_name'), core::config('email.notify_email'))) {
                 Alert::set(Alert::ERROR, __('Error on mail delivery, not sent'));
             }
         }
     }
 }
 /**
  * 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()
 {
     // get all categories
     if ($this->categories != FALSE) {
         $this->cat_items = Model_Category::get_as_array();
         $this->cat_order_items = Model_Category::get_multidimensional();
     }
     // get all locations
     if ($this->locations != FALSE) {
         $this->loc_items = Model_Location::get_as_array();
         $this->loc_order_items = Model_Location::get_multidimensional();
     }
     if ($this->price != FALSE) {
         $this->price = TRUE;
     }
     // user
     if (Auth::instance()->logged_in()) {
         //subscriber
         // check if user is already subscribed
         $user_id = Auth::instance()->get_user()->id_user;
         $obj_subscriber = new Model_Subscribe();
         $subscriber = $obj_subscriber->where('id_user', '=', $user_id)->limit(1)->find();
         if ($subscriber->loaded()) {
             $this->subscriber = TRUE;
         }
         //if user logged in pass email and id
         $this->user_email = Auth::instance()->get_user()->email;
         $this->user_id = $user_id;
     } else {
         $this->user_id = 0;
     }
     //min - max price selected
     $this->min_price = $this->min_price;
     $this->max_price = $this->max_price;
 }
Exemple #4
0
 public function action_unsubscribe()
 {
     // unsubscribe user
     $obj_subscribe = new Model_Subscribe();
     $un_subscribe = $obj_subscribe->where('id_user', '=', $this->request->param('id'))->find_all();
     // foreach entry in table where user id, delete it
     foreach ($un_subscribe as $s) {
         try {
             $s->delete();
         } catch (Exception $e) {
             throw new HTTP_Exception_500($e->getMessage());
         }
     }
     Alert::set(Alert::SUCCESS, __('You are unsubscribed'));
     $this->request->redirect(Route::url('default'));
 }
Exemple #5
0
 /**
  * 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()
 {
     // get all categories
     if ($this->categories != FALSE) {
         // loaded category
         list($categories, $order_categories) = Model_Category::get_all();
         $arr_cat = array();
         foreach ($categories as $cat => $value) {
             if ($value['id'] != 1) {
                 $arr_cat[$value['id']] = $value['name'];
             }
         }
         $this->cat_items = $categories;
         $this->cat_order_items = $order_categories;
     }
     // get all locations
     if ($this->locations != FALSE) {
         list($locations, $order_locations) = Model_Location::get_all();
         $this->loc_items = $locations;
         $this->loc_order_items = $order_locations;
     }
     if ($this->price != FALSE) {
         $this->price = TRUE;
     }
     // user
     if (Auth::instance()->logged_in()) {
         //subscriber
         // check if user is already subscribed
         $user_id = Auth::instance()->get_user()->id_user;
         $obj_subscriber = new Model_Subscribe();
         $subscriber = $obj_subscriber->where('id_user', '=', $user_id)->limit(1)->find();
         if ($subscriber->loaded()) {
             $this->subscriber = TRUE;
         }
         //if user logged in pass email and id
         $this->user_email = Auth::instance()->get_user()->email;
         $this->user_id = $user_id;
     } else {
         $this->user_id = 0;
     }
     //min - max price selected
     $this->min_price = $this->min_price;
     $this->max_price = $this->max_price;
 }
 /**
  * list all subscription for a given user
  * @return view 
  */
 public function action_subscriptions()
 {
     $this->template->title = __('My subscriptions');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My subscriptions')));
     Controller::$full_width = TRUE;
     $subscriptions = new Model_Subscribe();
     $user = Auth::instance()->get_user()->id_user;
     //get all for this user
     $query = $subscriptions->where('id_user', '=', $user)->find_all();
     if (count($query) != 0) {
         // get categories, location, date, and price range to show in view
         $subs = $query->as_array();
         foreach ($subs as $s) {
             $min_price = $s->min_price;
             $max_price = $s->max_price;
             $created = $s->created;
             $category = new Model_Category($s->id_category);
             $location = new Model_Location($s->id_location);
             $list[] = array('min_price' => $min_price, 'max_price' => $max_price, 'created' => $created, 'category' => $category->name, 'location' => $location->name, 'id' => $s->id_subscribe);
         }
         if ($this->user->subscriber == 0) {
             Alert::set(Alert::INFO, __('You can not receive emails. Enable it in your profile.'));
         }
         $this->template->content = View::factory('oc-panel/profile/subscriptions', array('list' => $list));
     } else {
         Alert::set(Alert::INFO, __('No Subscriptions'));
     }
 }
Exemple #7
0
 /**
  * list all subscription for a given user
  * @return view 
  */
 public function action_subscriptions()
 {
     $subscriptions = new Model_Subscribe();
     $user = Auth::instance()->get_user()->id_user;
     //get all for this user
     $query = $subscriptions->where('id_user', '=', $user)->find_all();
     if (count($query) != 0) {
         // get categories, location, date, and price range to show in view
         $subs = $query->as_array();
         foreach ($subs as $s) {
             $min_price = $s->min_price;
             $max_price = $s->max_price;
             $created = $s->created;
             $category = new Model_Category($s->id_category);
             $location = new Model_Location($s->id_location);
             $list[] = array('min_price' => $min_price, 'max_price' => $max_price, 'created' => $created, 'category' => $category->name, 'location' => $location->name, 'id' => $s->id_subscribe);
         }
         $this->template->content = View::factory('oc-panel/profile/subscriptions', array('list' => $list));
     } else {
         Alert::set(Alert::INFO, __('No Subscriptions'));
     }
 }