/** * Handle GET requests. */ public function action_index() { try { if (is_numeric($this->request->param('id'))) { $this->action_get(); } else { $output = array(); $users = new Model_User(); $users->where('status', '=', Model_User::STATUS_ACTIVE); //filter results by param, verify field exists and has a value and sort the results $users->api_filter($this->_filter_params)->api_sort($this->_sort); //how many? used in header X-Total-Count $count = $users->count_all(); //pagination with headers $pagination = $users->api_pagination($count, $this->_params['items_per_page']); $users = $users->cached()->find_all(); //as array foreach ($users as $user) { $output[] = self::get_user_array($user); } $this->rest_output(array('users' => $output), 200, $count, $pagination !== FALSE ? $pagination : NULL); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
public function action_index() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Newsletter'))); $this->template->title = __('Newsletter'); //count all users $user = new Model_User(); $user->where('status', '=', Model_User::STATUS_ACTIVE); $count_all_users = $user->count_all(); //count support expired $query = DB::select(DB::expr('COUNT(id_order) count'))->from('orders')->where('status', '=', Model_Order::STATUS_PAID)->where('support_date', '<', Date::unix2mysql())->execute(); $count_support_expired = $query->as_array(); $count_support_expired = $count_support_expired[0]['count']; //count license expired $query = DB::select(DB::expr('COUNT(id_license) count'))->from('licenses')->where('valid_date', 'IS NOT', NULL)->where('valid_date', '<', Date::unix2mysql())->execute(); $count_license_expired = $query->as_array(); $count_license_expired = $count_license_expired[0]['count']; //orders per product, not accuarate since 1 user could buy more than 1 product but will do $query = DB::select(DB::expr('COUNT(id_order) count'))->select('p.title')->select('p.id_product')->from(array('products', 'p'))->join(array('orders', 'o'))->using('id_product')->where('o.status', '=', Model_Order::STATUS_PAID)->group_by('p.id_product')->execute(); $products = $query->as_array(); //post done sending newsletter if ($this->request->post() and Core::post('subject') != NULL) { $users = array(); if (core::post('send_all') == 'on') { $query = DB::select('email')->select('name')->from('users')->where('status', '=', Model_User::STATUS_ACTIVE)->execute(); $users = array_merge($users, $query->as_array()); } if (Theme::get('premium') == 1) { if (core::post('send_expired_support') == 'on') { $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('orders', 'o'))->using('id_user')->where('o.status', '=', Model_Order::STATUS_PAID)->where('o.support_date', '<', Date::unix2mysql())->where('u.subscriber', '=', 1)->group_by('u.id_user')->execute(); $users = array_merge($users, $query->as_array()); } if (core::post('send_expired_license') == 'on') { $query = DB::select('email')->select('name')->from(array('licenses', 'l'))->join(array('users', 'u'))->using('id_user')->where('l.valid_date', 'IS NOT', NULL)->where('l.valid_date', '<', Date::unix2mysql())->where('u.subscriber', '=', 1)->group_by('u.id_user')->execute(); $users = array_merge($users, $query->as_array()); } if (is_numeric(core::post('send_product'))) { $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('orders', 'o'))->using('id_user')->where('o.id_product', '=', core::post('send_product'))->where('o.status', '=', Model_Order::STATUS_PAID)->where('u.subscriber', '=', 1)->group_by('u.id_user')->execute(); $users = array_merge($users, $query->as_array()); } } //NOTE $users may have duplicated emails, but phpmailer takes care of not sending the email 2 times to same recipient //sending! if (count($users) > 0) { if (!Email::send($users, '', Core::post('subject'), Kohana::$_POST_ORIG['description'], Core::post('from'), Core::post('from_email'))) { Alert::set(Alert::ERROR, __('Error on mail delivery, not sent')); } else { Alert::set(Alert::SUCCESS, __('Email sent')); } } else { Alert::set(Alert::ERROR, __('Mail not sent')); } } $this->template->content = View::factory('oc-panel/pages/newsletter', array('count_all_users' => $count_all_users, 'count_support_expired' => $count_support_expired, 'count_license_expired' => $count_license_expired, 'products' => $products)); }
/** * * Loads a basic list info * @param string $view template to render */ public function action_index($view = NULL) { $this->template->title = __($this->_orm_model); $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js'; $users = new Model_User(); // filter users by search value if ($q = $this->request->query('search')) { $users->where('email', 'like', '%' . $q . '%')->or_where('name', 'like', '%' . $q . '%'); } $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $users->count_all()))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $pagination->title($this->template->title); $users = $users->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $pagination = $pagination->render(); $this->render('oc-panel/crud/index', array('elements' => $users, 'pagination' => $pagination)); }
public function action_info() { //try to get the info from the cache $info = Core::cache('action_info', NULL); //not cached :( if ($info === NULL) { $ads = new Model_Ad(); $total_ads = $ads->count_all(); $last_ad = $ads->select('published')->order_by('published', 'desc')->limit(1)->find(); $last_ad = $last_ad->published; $ads = new Model_Ad(); $first_ad = $ads->select('published')->order_by('published', 'asc')->limit(1)->find(); $first_ad = $first_ad->published; $views = new Model_Visit(); $total_views = $views->count_all(); $users = new Model_User(); $total_users = $users->count_all(); $info = array('site_url' => Core::config('general.base_url'), 'site_name' => Core::config('general.site_name'), 'site_description' => Core::config('general.site_description'), 'created' => $first_ad, 'updated' => $last_ad, 'email' => Core::config('email.notify_email'), 'version' => Core::VERSION, 'theme' => Core::config('appearance.theme'), 'theme_mobile' => Core::config('appearance.theme_mobile'), 'charset' => Kohana::$charset, 'timezone' => Core::config('i18n.timezone'), 'locale' => Core::config('i18n.locale'), 'currency' => '', 'ads' => $total_ads, 'views' => $total_views, 'users' => $total_users); Core::cache('action_info', $info); } $this->response->headers('Content-type', 'application/javascript'); $this->response->body(json_encode($info)); }
public function action_index() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Newsletter'))); $this->template->title = __('Newsletter'); //count all users $user = new Model_User(); $user->where('status', '=', Model_User::STATUS_ACTIVE)->where('subscriber', '=', 1); $count_all_users = $user->count_all(); //count featured expired $query = DB::select(DB::expr('COUNT(id_user) count'))->from('ads')->where('status', '=', Model_Ad::STATUS_PUBLISHED)->where('featured', '<', Date::unix2mysql())->group_by('id_user')->execute(); $count_featured_expired = $query->as_array(); $count_featured_expired = isset($count_featured_expired[0]['count']) ? $count_featured_expired[0]['count'] : 0; //count all featured $query = DB::select(DB::expr('COUNT(id_user) count'))->from('ads')->where('status', '=', Model_Ad::STATUS_PUBLISHED)->where('featured', 'IS NOT', NULL)->group_by('id_user')->execute(); $count_featured = $query->as_array(); $count_featured = isset($count_featured[0]['count']) ? $count_featured[0]['count'] : 0; //users without published ads $query = DB::select(DB::expr('COUNT(id_user) count'))->from(array('users', 'u'))->join(array('ads', 'a'), 'LEFT')->using('id_user')->where('u.status', '=', Model_User::STATUS_ACTIVE)->where('u.subscriber', '=', 1)->where('a.title', 'is', NULL)->group_by('u.id_user')->execute(); $count_unpub = $query->as_array(); $count_unpub = isset($count_unpub[0]['count']) ? $count_unpub[0]['count'] : 0; //count all users not login 3 months $query = DB::select(DB::expr('COUNT(id_user) count'))->from('users')->where('status', '=', Model_User::STATUS_ACTIVE)->where('last_login', '<=', Date::unix2mysql(strtotime('-3 month')))->or_where('last_login', 'IS', NULL)->where('subscriber', '=', 1)->execute(); $count_logged = $query->as_array(); $count_logged = isset($count_logged[0]['count']) ? $count_logged[0]['count'] : 0; //count all users spammers $query = DB::select(DB::expr('COUNT(id_user) count'))->from('users')->where('status', '=', Model_User::STATUS_SPAM)->where('subscriber', '=', 1)->execute(); $count_spam = $query->as_array(); $count_spam = isset($count_spam[0]['count']) ? $count_spam[0]['count'] : 0; //post done sending newsletter if ($this->request->post() and Core::post('subject') != NULL) { $users = array(); if (core::post('send_all') == 'on') { $query = DB::select('email')->select('name')->from('users')->where('status', '=', Model_User::STATUS_ACTIVE)->where('subscriber', '=', 1)->execute(); $users = array_merge($users, $query->as_array()); } if (Theme::get('premium') == 1) { if (core::post('send_featured_expired') == 'on') { $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('ads', 'a'))->using('id_user')->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->where('a.featured', '<', Date::unix2mysql())->where('u.subscriber', '=', 1)->group_by('id_user')->execute(); $users = array_merge($users, $query->as_array()); } if (core::post('send_featured') == 'on') { $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('ads', 'a'))->using('id_user')->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->where('a.featured', 'IS NOT', NULL)->where('u.subscriber', '=', 1)->group_by('id_user')->execute(); $users = array_merge($users, $query->as_array()); } if (core::post('send_unpub') == 'on') { //users without published ads $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('ads', 'a'), 'LEFT')->using('id_user')->where('u.status', '=', Model_User::STATUS_ACTIVE)->where('u.subscriber', '=', 1)->where('a.title', 'is', NULL)->execute(); $users = array_merge($users, $query->as_array()); } if (core::post('send_logged') == 'on') { $query = DB::select('email')->select('name')->from('users')->where('status', '=', Model_User::STATUS_ACTIVE)->where('last_login', '<=', Date::unix2mysql(strtotime('-3 month')))->or_where('last_login', 'IS', NULL)->where('subscriber', '=', 1)->execute(); $users = array_merge($users, $query->as_array()); } if (core::post('send_spam') == 'on') { $query = DB::select('email')->select('name')->from('users')->where('status', '=', Model_User::STATUS_SPAM)->where('subscriber', '=', 1)->execute(); $users = array_merge($users, $query->as_array()); } } //NOTE $users may have duplicated emails, but phpmailer takes care of not sending the email 2 times to same recipient //sending! if (count($users) > 0) { if (!Email::send($users, '', Core::post('subject'), Kohana::$_POST_ORIG['description'], Core::post('from'), Core::post('from_email'))) { Alert::set(Alert::ERROR, __('Error on mail delivery, not sent')); } else { Alert::set(Alert::SUCCESS, __('Email sent')); } } else { Alert::set(Alert::ERROR, __('Mail not sent')); } } $this->template->content = View::factory('oc-panel/pages/newsletter', array('count_all_users' => $count_all_users, 'count_featured_expired' => $count_featured_expired, 'count_featured' => $count_featured, 'count_unpub' => $count_unpub, 'count_logged' => $count_logged, 'count_spam' => $count_spam)); }
public function action_index() { $db_prefix = Database::instance('default')->table_prefix(); //include num of ads so we can filter, sort and display next to each user $query_count = '(SELECT count(id_ad) FROM ' . $db_prefix . 'ads WHERE id_user='******'user.id_user AND status=' . Model_Ad::STATUS_PUBLISHED . ')'; $users = new Model_User(); $users->select(array(DB::expr($query_count), 'ads_count'))->where('status', '=', Model_User::STATUS_ACTIVE); //search filter if (core::request('search') !== NULL and strlen(core::request('search')) >= 3) { $search = core::request('search'); $users->where_open()->where('name', 'like', '%' . $search . '%')->or_where('description', 'like', '%' . $search . '%')->where_close(); } //cf filter foreach (array_merge($_POST, $_GET) as $name => $value) { //value set and is a CF if (isset($value) and $value != NULL and strpos($name, 'cf_') !== FALSE and array_key_exists(str_replace('cf_', '', $name), Model_UserField::get_all())) { //checkbox when selected return string 'on' as a value $value = $value == 'on' ? 1 : $value; if (is_numeric($value)) { $users->where($name, '=', $value); } elseif (is_string($value)) { $users->where($name, 'like', '%' . $value . '%'); } } } $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $users->count_all(), 'items_per_page' => core::config('advertisement.advertisements_per_page'))); /** * order depending on the sort parameter */ switch (core::request('sort')) { //num of ads desc case 'ads-asc': $users->order_by('ads_count', 'asc')->order_by('created', 'desc'); break; //num of ads desc //num of ads desc case 'ads-desc': $users->order_by('ads_count', 'desc')->order_by('created', 'desc'); break; //name z->a //name z->a case 'name-asc': $users->order_by('name', 'asc')->order_by('created', 'desc'); break; //name a->z //name a->z case 'name-desc': $users->order_by('name', 'desc')->order_by('created', 'desc'); break; //rating //rating case 'rating': $users->order_by('rate', 'desc')->order_by('created', 'desc'); break; //oldest first //oldest first case 'created-asc': $users->order_by('created', 'asc'); break; //newest first //newest first case 'created-desc': default: $users->order_by('created', 'desc'); break; } $users = $users->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); //if home page is the users if (($landing = json_decode(core::config('general.landing_page'))) != NULL and $landing->controller == 'user' and $landing->action == 'index' and (isset($pagination) and $pagination->current_page == 1)) { //only show site title $this->template->title = NULL; // if we have site description lets use that ;) if (core::config('general.site_description') != '') { $this->template->meta_description = core::config('general.site_description'); } } else { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Users'))); $this->template->title = __('Users search'); } if (Theme::get('infinite_scroll')) { $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js'; $this->template->scripts['footer'][] = 'js/users.js'; } $this->template->content = View::factory('pages/user/list', array('users' => $users, 'pagination' => $pagination)); }