예제 #1
0
 public function getAttachmentsList(JeproshopContext $context = null)
 {
     jimport('joomla.html.pagination');
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $option = $app->input->get('option');
     $view = $app->input->get('view');
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int');
     $limit_start = $app->getUserStateFromRequest($option . $view . '.limitstart', 'limitstart', 0, 'int');
     $lang_id = $app->getUserStateFromRequest($option . $view . '.lang_id', 'lang_id', $context->language->lang_id, 'int');
     $order_by = $app->getUserStateFromRequest($option . $view . '.order_by', 'order_by', 'attachment_id', 'string');
     $order_way = $app->getUserStateFromRequest($option . $view . '.order_way', 'order_way', 'ASC', 'string');
     $use_limit = true;
     if ($limit === false) {
         $use_limit = false;
     }
     $lang_join = " LEFT JOIN " . $db->quoteName('#__jeproshop_attachment_lang') . " AS attachment_lang ON (attachment_lang." . $db->quoteName('attachment_id');
     $lang_join .= " = attachment." . $db->quoteName('attachment_id') . " AND attachment_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
     /*if(!JeproshopShopModelShop::isFeaturePublished()){
           $lang_join .= " AND attachment_lang." . $db->quoteName('shop_id') . " 1";
       }else{
           $lang_join .= " AND attachment_lang." . $db->quoteName('shop_id') . " = " . ()
           $lang_join .= " AND attachment_lang." . $db->quoteName('shop_id') . " = a"
       }*/
     do {
         $query = "SELECT SQL_CALC_FOUND_ROWS attachment." . $db->quoteName('attachment_id') . ", attachment_lang." . $db->quoteName('name') . ", attachment.";
         $query .= $db->quoteName('file') . ", attachment." . $db->quoteName('file_name') . ", attachment." . $db->quoteName('mime') . ", IFNULL(virtual.";
         $query .= "products, 0) AS products FROM " . $db->quoteName('#__jeproshop_attachment') . " AS attachment LEFT JOIN (SELECT " . $db->quoteName('attachment_id');
         $query .= ", COUNT(*) AS products FROM " . $db->quoteName('#__jeproshop_product_attachment') . " GROUP BY attachment_id) virtual ON (attachment.";
         $query .= $db->quoteName('attachment_id') . " = virtual." . $db->quoteName('attachment_id') . ") " . $lang_join . " ORDER BY ";
         $query .= (str_replace('`', '', $order_by) == 'attachment_id' ? " attachment." : "") . $order_by . " " . $order_way;
         $db->setQuery($query);
         $total = count($db->loadObjectList());
         $query .= $use_limit === true ? " LIMIT " . (int) $limit_start . ", " . (int) $limit : "";
         $db->setQuery($query);
         $attachments = $db->loadObjectList();
         if ($use_limit == true) {
             $limit_start = (int) $limit_start - (int) $limit;
             if ($limit_start < 0) {
                 break;
             }
         } else {
             break;
         }
     } while (empty($attachments));
     if (count($attachments)) {
         $productAttachments = JeproshopAttachmentModelAttachment::getAttachedProduct((int) $lang_id, $attachments);
         $list_product_list = array();
         foreach ($attachments as $attachment) {
             $product_list = '';
             if (isset($productAttachments[$attachment->attachment_id])) {
                 foreach ($productAttachments[$attachment->attachment_id] as $product) {
                     $product_list .= $product . ', ';
                 }
             }
             $list_product_list[$attachment->attachment_id] = $product_list;
         }
     }
     $this->pagination = new JPagination($total, $limit_start, $limit);
     return $attachments;
 }