Ejemplo n.º 1
0
 private function getStatisticsTabHtml($display)
 {
     $helper = $this->createTemplate('statistics');
     $helper->tpl_vars['integrated'] = $this->integrated;
     if ($this->integrated) {
         set_time_limit(0);
         if ($display) {
             $db = Db::getInstance();
             $templates = PP::getTemplates();
             $statistics = array();
             $used_templates = array();
             $rows = $db->executeS('SELECT count(`id_pp_template`) as count, `id_pp_template` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_pp_template` > 0 group by `id_pp_template`');
             foreach ($rows as $row) {
                 $statistics[$row['id_pp_template']] = $row['count'];
                 $used_templates[$row['id_pp_template']] = $row['id_pp_template'];
             }
             $rows = array();
             foreach ($templates as $template) {
                 $id_pp_template = $template['id_pp_template'];
                 unset($used_templates[$id_pp_template]);
                 $row = array();
                 $row['id'] = $id_pp_template;
                 $row['name'] = $template['name'];
                 $row['count'] = isset($statistics[$id_pp_template]) ? $statistics[$id_pp_template] : 0;
                 if ($row['count'] > 0) {
                     $products = $db->executeS('SELECT p.`id_product`, pl.`name` FROM `' . _DB_PREFIX_ . 'product` p LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . $this->default_language_id . ') WHERE p.`id_pp_template` = ' . $id_pp_template);
                     $row['products'] = $products;
                 }
                 $rows[] = $row;
             }
             $helper->tpl_vars['existing'] = $rows;
             if (!empty($used_templates)) {
                 $products = $db->executeS('SELECT p.`id_product`, p.`id_pp_template`, pl.`name` FROM `' . _DB_PREFIX_ . 'product` p LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . $this->default_language_id . ') WHERE p.`id_pp_template` in (' . implode(',', $used_templates) . ')');
                 if (is_array($products) && count($products) > 0) {
                     $helper->tpl_vars['missing'] = $products;
                 }
             }
             $helper->tpl_vars['linkAdminProducts'] = $this->context->link->getAdminLink('AdminProducts');
         }
     } else {
         $helper->tpl_vars['integration_message'] = $this->getTabIntegrationWarning();
     }
     return $helper->generate();
 }