function getOptions($id = null)
 {
     if (!$this->model) {
         $this->model = new waContactCategoryModel();
     }
     if (!$this->categories) {
         $this->categories = $this->model->getAll('id');
     }
     // Checklist options, category_id => name
     $options = array();
     foreach ($this->categories as $id => $row) {
         $options[$id] = $row['name'];
     }
     return $options;
 }
Ejemplo n.º 2
0
 public function execute()
 {
     $app_settings_model = new waAppSettingsModel();
     $settings = $app_settings_model->get(shopPricePlugin::$plugin_id);
     $ccm = new waContactCategoryModel();
     $categories = array(array('id' => 0, 'name' => 'Все покупатели'));
     foreach ($ccm->getAll() as $c) {
         if ($c['app_id'] == 'shop') {
             $categories[$c['id']] = $c;
         }
     }
     $price_model = new shopPricePluginModel();
     $prices = $price_model->getAll();
     $_prices = array();
     foreach ($prices as $price) {
         $_prices[$price['domain_hash']][] = $price;
     }
     $domain_routes = wa()->getRouting()->getByApp('shop');
     $domains_settings = shopPrice::getDomainsSettings();
     $this->view->assign('prices', $_prices);
     $this->view->assign('domain_routes', $domain_routes);
     $this->view->assign('categories', $categories);
     $this->view->assign('settings', $settings);
     $this->view->assign('domain_settings', $domains_settings);
 }
 public function execute()
 {
     // Only show categories available to current user
     $crm = new contactsRightsModel();
     $cm = new waContactCategoryModel();
     // List of categories user is allowed to add contacts to
     $categories = $cm->getAll('id');
     //        $allowed = $crm->getAllowedCategories();
     //        if ($allowed === true) {
     //            $allowed = $categories;
     //        }
     //        foreach($categories as $id => &$cat) {
     //            if (!isset($allowed[$id]) || $cat['system_id']) {
     //                unset($categories[$id]);
     //            }
     //            $cat = $cat['name'];
     //        }
     //        unset($cat);
     // Set of catorories that are always checked and disabled in list
     $d = waRequest::get('disabled');
     if (!is_array($d)) {
         $d = array($d);
     }
     $this->view->assign('categories', $categories);
     $this->view->assign('disabled', array_fill_keys($d, true));
 }
 public function execute()
 {
     $this->view->assign('views', null);
     $this->view->assign('settings', $this->getUser()->getSettings('contacts'));
     $historyModel = new contactsHistoryModel();
     $this->view->assign('history', $historyModel->get());
     $cc = new contactsCollection();
     $this->view->assign('totalContacts', $cc->count());
     // only show categories available to current user
     $crm = new contactsRightsModel();
     $wcrm = new waContactRightsModel();
     $ccm = new waContactCategoryModel();
     $allowed = $crm->getAllowedCategories();
     $categories = array();
     if ($allowed === true) {
         $categories = $ccm->getAll();
     } else {
         if ($allowed) {
             foreach ($ccm->getAll() as $cat) {
                 if (isset($allowed[$cat['id']])) {
                     $categories[] = $cat;
                 }
             }
         }
     }
     $this->view->assign('categories', $categories);
     // User views are only available to global admin
     $r = new waContactRightsModel();
     $this->view->assign('superadmin', FALSE);
     $this->view->assign('admin', FALSE);
     if (wa()->getUser()->getRights('webasyst', 'backend')) {
         $this->view->assign('superadmin', TRUE);
         $this->view->assign('admin', TRUE);
         $group_model = new waGroupModel();
         $this->view->assign('groups', $group_model->getAll());
         $cc = new contactsCollection('/users/all/');
         $this->view->assign('totalUsers', $cc->count());
     } else {
         if (wa()->getUser()->getRights('contacts', 'backend') >= 2) {
             $this->view->assign('admin', TRUE);
         }
     }
     // is user allowed to add contacts?
     $this->view->assign('show_create', $wcrm->get(null, null, 'create'));
 }
 public function execute()
 {
     // Only show categories available to current user
     $crm = new contactsRightsModel();
     $cm = new waContactCategoryModel();
     // List of categories user is allowed to add contacts to
     $categories = $cm->getAll('id');
     // Set of catorories that are always checked and disabled in list
     $d = waRequest::get('disabled');
     if (!is_array($d)) {
         $d = array($d);
     }
     $this->view->assign('categories', $categories);
     $this->view->assign('disabled', array_fill_keys($d, true));
 }
 public function execute()
 {
     // Category counts
     // !!! Probably not the best idea to fetch category counts on the fly...
     $cm = new shopCustomerModel();
     $counts = $cm->getCategoryCounts();
     // Categories
     $ccm = new waContactCategoryModel();
     $categories = array();
     foreach ($ccm->getAll() as $c) {
         if ($c['app_id'] == 'shop') {
             $c['cnt'] = ifset($counts[$c['id']], 0);
             $categories[$c['id']] = $c;
         }
     }
     $this->view->assign('all_customers_count', $cm->countAll());
     $this->view->assign('contacts_url', wa()->getAppUrl('contacts'));
     $this->view->assign('categories', $categories);
 }
 public function execute()
 {
     $ccdm = new shopContactCategoryDiscountModel();
     if (waRequest::post()) {
         $categories = waRequest::post('categories', array());
         if (is_array($categories)) {
             $ccdm->save($categories);
         }
     }
     // Categories
     $categories = array();
     $ccm = new waContactCategoryModel();
     $values = $ccdm->getAll('category_id', true);
     foreach ($ccm->getAll('id') as $c) {
         if ($c['app_id'] == 'shop') {
             $c['value'] = (double) ifset($values[$c['id']], 0);
             $categories[$c['id']] = $c;
         }
     }
     $enabled = shopDiscounts::isEnabled('category');
     $this->view->assign('enabled', $enabled);
     $this->view->assign('categories', $categories);
 }
Ejemplo n.º 8
0
 public function execute()
 {
     $category_id = waRequest::request('category', 0, 'int');
     $search = waRequest::request('search');
     $start = waRequest::request('start', 0, 'int');
     $limit = 50;
     $order = waRequest::request('order', '!last_order');
     $config = $this->getConfig();
     $use_gravatar = $config->getGeneralSettings('use_gravatar');
     $gravatar_default = $config->getGeneralSettings('gravatar_default');
     // Get customers
     $scm = new shopCustomerModel();
     list($customers, $total) = $scm->getList($category_id, $search, $start, $limit, $order);
     $has_more = $start + count($customers) < $total;
     $countries = array();
     foreach ($customers as &$c) {
         $c['affiliate_bonus'] = (double) $c['affiliate_bonus'];
         if (!$c['photo'] && $use_gravatar) {
             $c['photo'] = shopHelper::getGravatar(!empty($c['email']) ? $c['email'] : '', 50, $gravatar_default);
         } else {
             $c['photo'] = waContact::getPhotoUrl($c['id'], $c['photo'], 50, 50);
         }
         $c['categories'] = array();
         if (!empty($c['address']['region']) && !empty($c['address']['country'])) {
             $countries[$c['address']['country']] = array();
         }
     }
     unset($c);
     // Add region names to addresses
     if ($countries) {
         $rm = new waRegionModel();
         foreach ($rm->where('country_iso3 IN (?)', array_keys($countries))->query() as $row) {
             $countries[$row['country_iso3']][$row['code']] = $row['name'];
         }
         foreach ($customers as &$c) {
             if (!empty($c['address']['region']) && !empty($c['address']['country'])) {
                 $country = $c['address']['country'];
                 $region = $c['address']['region'];
                 if (!empty($countries[$country]) && !empty($countries[$country][$region])) {
                     $c['address']['region_formatted'] = $countries[$country][$region];
                 }
             }
         }
         unset($c);
     }
     // Contact categories
     $ccm = new waContactCategoryModel();
     $categories = $ccm->getAll('id');
     if ($customers) {
         $ccsm = new waContactCategoriesModel();
         foreach ($ccsm->getContactsCategories(array_keys($customers)) as $c_id => $list) {
             foreach ($list as $cat_id) {
                 if (!empty($categories[$cat_id])) {
                     $customers[$c_id]['categories'][$cat_id] = $categories[$cat_id];
                 }
             }
         }
     }
     // Set up lazy loading
     if (!$has_more) {
         // Do not trigger lazy loading, show total count at end of list
         $total_customers_number = $start + count($customers);
     } else {
         $total_customers_number = null;
         // trigger lazy loading
     }
     // List title and other params depending on list type
     if ($search) {
         $title = _w('Search results');
         $hash_start = '#/search/0/' . urlencode($search) . '/';
         $discount = null;
     } else {
         if ($category_id) {
             if (!empty($categories[$category_id])) {
                 $title = $categories[$category_id]['name'];
             } else {
                 $title = _w('Unknown category') . ' ' . $category_id;
             }
             $hash_start = '#/category/' . $category_id . '/';
             if (wa()->getSetting('discount_category')) {
                 $ccdm = new shopContactCategoryDiscountModel();
                 $discount = sprintf_wp('%s%% discount', $ccdm->getDiscount($category_id));
             } else {
                 $discount = null;
             }
         } else {
             $title = _w('All customers');
             $hash_start = '#/all/0/';
             $discount = null;
         }
     }
     $lazy_loading_params = array('limit=' . $limit, 'start=' . ($start + $limit), 'order=' . $order);
     if ($search) {
         $lazy_loading_params[] = 'search=' . $search;
     } else {
         if ($category_id) {
             $lazy_loading_params[] = 'category=' . $category_id;
         }
     }
     $lazy_loading_params = implode('&', $lazy_loading_params);
     $this->view->assign('cols', self::getCols());
     $this->view->assign('title', $title);
     $this->view->assign('order', $order);
     $this->view->assign('total', $total);
     $this->view->assign('discount', $discount);
     $this->view->assign('customers', $customers);
     $this->view->assign('hash_start', $hash_start);
     $this->view->assign('category_id', $category_id);
     $this->view->assign('lazy_loading_params', $lazy_loading_params);
     $this->view->assign('total_customers_number', $total_customers_number);
 }