Esempio n. 1
0
File: helper.php Progetto: 01J/topm
 /**
  * Get a list of tags
  *
  * @param   JRegistry  &$params  Module parameters
  *
  * @return  mixed                Results array / null
  */
 public static function getList(&$params)
 {
     $app = JFactory::getApplication();
     $option = $app->input->get('option');
     $view = $app->input->get('view');
     // For now assume com_tags and com_users do not have tags.
     // This module does not apply to list views in general at this point.
     if ($option == 'com_tags' || $view == 'category' || $option == 'com_users') {
         return;
     }
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $matchtype = $params->get('matchtype', 'all');
     $maximum = $params->get('maximum', 5);
     $tagsHelper = new JHelperTags();
     $prefix = $option . '.' . $view;
     $id = $app->input->getInt('id');
     $tagsToMatch = $tagsHelper->getTagIds($id, $prefix);
     if (!$tagsToMatch || is_null($tagsToMatch)) {
         return;
     }
     $tagCount = substr_count($tagsToMatch, ',') + 1;
     $query = $db->getQuery(true)->select(array($db->quoteName('m.tag_id'), $db->quoteName('m.core_content_id'), $db->quoteName('m.content_item_id'), $db->quoteName('m.type_alias'), 'COUNT( ' . $db->quoteName('tag_id') . ') AS ' . $db->quoteName('count'), $db->quoteName('t.access'), $db->quoteName('t.id'), $db->quoteName('ct.router'), $db->quoteName('cc.core_title'), $db->quoteName('cc.core_alias'), $db->quoteName('cc.core_catid'), $db->quoteName('cc.core_language')));
     $query->from($db->quoteName('#__contentitem_tag_map', 'm'));
     $query->join('INNER', $db->quoteName('#__tags', 't') . ' ON m.tag_id = t.id')->join('INNER', $db->quoteName('#__ucm_content', 'cc') . ' ON m.core_content_id = cc.core_content_id')->join('INNER', $db->quoteName('#__content_types', 'ct') . ' ON m.type_alias = ct.type_alias');
     $query->where($db->quoteName('m.tag_id') . ' IN (' . $tagsToMatch . ')');
     $query->where('t.access IN (' . $groups . ')');
     $query->where('(cc.core_access IN (' . $groups . ') OR cc.core_access = 0)');
     // Don't show current item
     $query->where('(' . $db->quoteName('m.content_item_id') . ' <> ' . $id . ' OR ' . $db->quoteName('m.type_alias') . ' <> ' . $db->quote($prefix) . ')');
     // Only return published tags
     $query->where($db->quoteName('cc.core_state') . ' = 1 ');
     // Optionally filter on language
     $language = JComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
     if ($language != 'all') {
         if ($language == 'current_language') {
             $language = JHelperContent::getCurrentLanguage();
         }
         $query->where($db->quoteName('cc.core_language') . ' IN (' . $db->quote($language) . ', ' . $db->quote('*') . ')');
     }
     $query->group($db->quoteName(array('m.core_content_id')));
     if ($matchtype == 'all' && $tagCount > 0) {
         $query->having('COUNT( ' . $db->quoteName('tag_id') . ')  = ' . $tagCount);
     } elseif ($matchtype == 'half' && $tagCount > 0) {
         $tagCountHalf = ceil($tagCount / 2);
         $query->having('COUNT( ' . $db->quoteName('tag_id') . ')  >= ' . $tagCountHalf);
     }
     $query->order($db->quoteName('count') . ' DESC');
     $db->setQuery($query, 0, $maximum);
     $results = $db->loadObjectList();
     foreach ($results as $result) {
         $explodedAlias = explode('.', $result->type_alias);
         $result->link = 'index.php?option=' . $explodedAlias[0] . '&view=' . $explodedAlias[1] . '&id=' . $result->content_item_id . '-' . $result->core_alias;
     }
     return $results;
 }
Esempio n. 2
0
File: Tags.php Progetto: akeeba/fof
 /**
  * This event runs after unpublishing a record in a model
  *
  * @param   DataModel  &$model  The model which calls this event
  * @param   mixed      $data    An associative array or object to bind to the DataModel instance.
  *
  * @return  void
  */
 public function onAfterBind(&$model, &$data)
 {
     $tagField = $model->getBehaviorParam('tagFieldName', 'tags');
     if ($model->{$tagField}) {
         return;
     }
     $type = $model->getContentType();
     $model->addKnownField($tagField);
     $model->{$tagField} = $this->tagsHelper->getTagIds($model->getId(), $type);
 }
Esempio n. 3
0
 function getProduct($categories = array())
 {
     $this->onExecuteBefore('getProduct', array(&$categories));
     $id = JRequest::getInt('id');
     $product = KSSystem::loadDbItem($id, 'products');
     $product = KSMedia::setItemMedia($product, 'product');
     $product->categories = array();
     $product->properties = array();
     $product->childs = array();
     if (count($categories)) {
         $query = $this->_db->getQuery(true);
         $query->select('category_id')->from('#__ksenmart_products_categories')->where('product_id=' . $id)->where('is_default=1');
         $this->_db->setQuery($query);
         $is_default = $this->_db->loadResult();
         foreach ($categories as $category_id) {
             $category = new stdClass();
             $category->category_id = $category_id;
             $category->is_default = $category->category_id == $is_default ? 1 : 0;
             $product->categories[$category_id] = $category;
         }
     } else {
         $query = $this->_db->getQuery(true);
         $query->select('category_id, is_default')->from('#__ksenmart_products_categories')->where('product_id=' . $id);
         $this->_db->setQuery($query);
         $product->categories = $this->_db->loadObjectList('category_id');
     }
     if (count($product->categories)) {
         $query = $this->_db->getQuery(true);
         $query->select('p.*')->from('#__ksenmart_properties as p')->innerjoin('#__ksenmart_product_categories_properties as cp on cp.property_id=p.id')->where('cp.category_id in (' . implode(',', array_keys($product->categories)) . ')')->where('p.published=1');
         $this->_db->setQuery($query);
         $product->properties = $this->_db->loadObjectList('id');
         foreach ($product->properties as &$p) {
             $p->values = array();
         }
         if (!empty($product->properties)) {
             $in = array_keys($product->properties);
             $query = $this->_db->getQuery(true);
             $query->select('*')->from('#__ksenmart_product_properties_values')->where('product_id=' . $id)->where('property_id in (' . implode(',', $in) . ')');
             $this->_db->setQuery($query);
             $values = $this->_db->loadObjectList();
             foreach ($values as $v) {
                 if (isset($product->properties[$v->property_id])) {
                     $product->properties[$v->property_id]->values[$v->id] = $v;
                 }
             }
         }
     }
     if ($product->is_parent == 1) {
         $empty_group = new stdClass();
         $empty_group->id = 0;
         $empty_group->title = JText::_('KSM_CATALOG_PRODUCT_CHILDS_EMPTY_GROUP');
         $empty_group->product_id = $id;
         $empty_group->products = array();
         $empty_group->ordering = 0;
         $query = $this->_db->getQuery(true);
         $query->select('*')->from('#__ksenmart_products_child_groups')->where('product_id=' . $id)->order('ordering');
         $this->_db->setQuery($query);
         $product->childs = $this->_db->loadObjectList('id');
         array_unshift($product->childs, $empty_group);
         foreach ($product->childs as &$child) {
             $query = $this->_db->getQuery(true);
             $query->select('p.*')->from('#__ksenmart_products as p')->where('p.parent_id=' . $id)->where('p.childs_group =' . $child->id)->order('p.ordering');
             $query = KSMedia::setItemMainImageToQuery($query);
             $this->_db->setQuery($query);
             $child->products = $this->_db->loadObjectList('id');
             foreach ($child->products as &$prd) {
                 $prd->small_img = KSMedia::resizeImage($prd->filename, $prd->folder, $this->params->get('admin_product_thumb_image_width', 36), $this->params->get('admin_product_thumb_image_heigth', 36), json_decode($prd->params, true));
             }
         }
     }
     $query = $this->_db->getQuery(true);
     $query->select('p.*')->from('#__ksenmart_products as p')->innerjoin('#__ksenmart_products_relations as pr on pr.relative_id=p.id')->where('pr.relation_type=' . $this->_db->quote('relation'))->where('pr.product_id=' . $id);
     $query = KSMedia::setItemMainImageToQuery($query);
     $this->_db->setQuery($query);
     $product->relative = $this->_db->loadObjectList('id');
     foreach ($product->relative as &$prd) {
         $prd->small_img = KSMedia::resizeImage($prd->filename, $prd->folder, $this->params->get('admin_product_thumb_image_width', 36), $this->params->get('admin_product_thumb_image_heigth', 36), json_decode($prd->params, true));
     }
     $tagHelper = new JHelperTags();
     $product->tags = $tagHelper->getTagIds(array($product->id), 'com_ksenmart.product');
     $this->onExecuteAfter('getProduct', array(&$product));
     return $product;
 }
Esempio n. 4
0
 function getExportStep()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $jinput = $app->input;
     $jform = $jinput->get('jform', array(), 'array');
     $categories = isset($jform['categories']) ? $jform['categories'] : array();
     $unic = $jform['unic'];
     $header = array(JText::_('ksm_exportimport_export_csv_product_id'), JText::_('ksm_exportimport_export_csv_product_name'), JText::_('ksm_exportimport_export_csv_product_parent'), JText::_('ksm_exportimport_export_csv_product_category'), JText::_('ksm_exportimport_export_csv_product_childs_group'), JText::_('ksm_exportimport_export_csv_product_price'), JText::_('ksm_exportimport_export_csv_product_promotion_price'), JText::_('ksm_exportimport_export_csv_product_currency'), JText::_('ksm_exportimport_export_csv_product_code'), JText::_('ksm_exportimport_export_csv_product_unit'), JText::_('ksm_exportimport_export_csv_product_packaging'), JText::_('ksm_exportimport_export_csv_product_in_stock'), JText::_('ksm_exportimport_export_csv_product_promotion'), JText::_('ksm_exportimport_export_csv_product_recommendation'), JText::_('ksm_exportimport_export_csv_product_hot'), JText::_('ksm_exportimport_export_csv_product_new'), JText::_('ksm_exportimport_export_csv_product_introcontent'), JText::_('ksm_exportimport_export_csv_product_content'), JText::_('ksm_exportimport_export_csv_product_manufacturer'), JText::_('ksm_exportimport_export_csv_product_country'), JText::_('ksm_exportimport_export_csv_product_set'), JText::_('ksm_exportimport_export_csv_product_relative'), JText::_('ksm_exportimport_export_csv_product_tags'), JText::_('ksm_exportimport_export_csv_product_photos'));
     $cats_tree = array();
     $query = $db->getQuery(true);
     $query->select('id,title,parent_id')->from('#__ksenmart_categories');
     $db->setQuery($query);
     $cats = $db->loadObjectList();
     foreach ($cats as $cat) {
         $cat_tree = array($cat->title);
         $parent = $cat->parent_id;
         while ($parent != 0) {
             $query = $db->getQuery(true);
             $query->select('title,parent_id')->from('#__ksenmart_categories')->where('id=' . $parent);
             $db->setQuery($query);
             $category = $db->loadObject();
             if (!empty($category)) {
                 $cat_tree[] = $category->title;
                 $parent = $category->parent_id;
             } else {
                 $parent = 0;
             }
         }
         $cat_tree = array_reverse($cat_tree);
         $cats_tree[$cat->id] = implode(':', $cat_tree);
     }
     $query = $db->getQuery(true);
     $query->select('id,title')->from('#__ksenmart_properties')->where('published = 1');
     $db->setQuery($query);
     $properties = $db->loadObjectList();
     foreach ($properties as $property) {
         $header[] = $property->title;
     }
     $f = fopen(JPATH_ROOT . '/administrator/components/com_ksenmart/tmp/export.csv', 'w');
     fputcsv($f, $header, ';');
     $query = $db->getQuery(true);
     $query->select('p.*,m.title as manufacturer_title,c.title as country_title')->from('#__ksenmart_products as p')->order('p.id');
     $query->leftjoin('#__ksenmart_manufacturers as m on m.id = p.manufacturer');
     $query->leftjoin('#__ksenmart_countries as c on c.id = m.country');
     $query->select('(select ' . $unic . ' from #__ksenmart_products where id = p.parent_id) as parent_title');
     $query->select('(select title from #__ksenmart_products_child_groups where id = p.childs_group) as group_title');
     $query->select('(select title from #__ksenmart_currencies where id = p.price_type) as currency_title');
     $query->select('(select form1 from #__ksenmart_product_units where id = p.product_unit) as unit_title');
     if (count($categories) > 0) {
         $query->innerjoin('#__ksenmart_products_categories as pc on pc.product_id=p.id');
         $query->where('pc.category_id in (' . implode(', ', $categories) . ')');
     }
     $query->group('p.id');
     $db->setQuery($query);
     $products = $db->loadObjectList();
     foreach ($products as $product) {
         $cats = array();
         $set = '';
         $rels = '';
         $tags = '';
         $photos = '';
         if ($product->old_price != 0) {
             $product->promotion_price = $product->price;
             $product->price = $product->old_price;
         } else {
             $product->promotion_price = 0;
         }
         $query = $db->getQuery(true);
         $query->select('pc.category_id')->from('#__ksenmart_products_categories as pc')->where('pc.product_id=' . $product->id);
         $db->setQuery($query);
         $prd_cats = $db->loadColumn();
         foreach ($prd_cats as $prd_cat) {
             $cats[] = $cats_tree[$prd_cat];
         }
         $cats = implode(';', $cats);
         $query = $db->getQuery(true);
         $query->select('p.' . $unic)->from('#__ksenmart_products_relations as pr')->leftjoin('#__ksenmart_products as p on p.id=pr.relative_id')->where('pr.product_id=' . $product->id)->where('pr.relation_type=' . $db->quote('set'));
         $db->setQuery($query);
         $set = $db->loadColumn();
         $set = implode(';', $set);
         $query = $db->getQuery(true);
         $query->select('p.' . $unic)->from('#__ksenmart_products_relations as pr')->leftjoin('#__ksenmart_products as p on p.id=pr.relative_id')->where('pr.product_id=' . $product->id)->where('pr.relation_type=' . $db->quote('relation'));
         $db->setQuery($query);
         $rels = $db->loadColumn();
         $rels = implode(';', $rels);
         $tagHelper = new JHelperTags();
         $tags = $tagHelper->getTagIds(array($product->id), 'com_ksenmart.product');
         if (!empty($tags)) {
             $query = $db->getQuery(true);
             $query->select('title')->from('#__tags')->where('id in (' . $tags . ')');
             $db->setQuery($query);
             $tags = $db->loadColumn();
             $tags = implode(';', $tags);
         }
         $query = $db->getQuery(true);
         $query->select('f.filename')->from('#__ksenmart_files as f')->where('f.owner_id=' . $product->id)->where('f.owner_type=' . $db->quote('product'));
         $db->setQuery($query);
         $photos = $db->loadColumn();
         $photos = implode(';', $photos);
         $arr = array($product->id, $product->title, $product->parent_title, $cats, $product->group_title, $product->price, $product->promotion_price, $product->currency_title, $product->product_code, $product->unit_title, $product->product_packaging, $product->in_stock, $product->promotion, $product->recommendation, $product->hot, $product->new, $product->introcontent, $product->content, $product->manufacturer_title, $product->country_title, $set, $rels, $tags, $photos);
         foreach ($properties as $property) {
             $props = array();
             $query = $db->getQuery(true);
             $query->select('pv.title,ppv.price')->from('#__ksenmart_product_properties_values as ppv')->leftjoin('#__ksenmart_property_values as pv on pv.id=ppv.value_id')->where('ppv.product_id=' . $product->id)->where('ppv.property_id=' . $property->id);
             $db->setQuery($query);
             $prd_props = $db->loadObjectList();
             foreach ($prd_props as $prd_prop) {
                 $prop = $prd_prop->title;
                 if (!empty($prd_prop->price)) {
                     $prop .= '=' . $prd_prop->price;
                 }
                 $props[] = $prop;
             }
             $arr[] = implode(';', $props);
         }
         fputcsv($f, $arr, ';');
     }
     fclose($f);
     $contents = file_get_contents(JPATH_ROOT . '/administrator/components/com_ksenmart/tmp/export.csv');
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="export.csv"');
     echo $contents;
     $app->close();
 }
Esempio n. 5
0
 /**
  * Get a list of tags
  *
  * @param   Registry  &$params  Module parameters
  *
  * @return  mixed  Results array / null
  */
 public static function getList(&$params)
 {
     $app = JFactory::getApplication();
     $option = $app->input->get('option');
     $view = $app->input->get('view');
     // For now assume com_tags and com_users do not have tags.
     // This module does not apply to list views in general at this point.
     if ($option == 'com_tags' || $view == 'category' || $option == 'com_users') {
         return;
     }
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $matchtype = $params->get('matchtype', 'all');
     $maximum = $params->get('maximum', 5);
     $ordering = $params->get('ordering', 'count');
     $tagsHelper = new JHelperTags();
     $prefix = $option . '.' . $view;
     $id = $app->input->getInt('id');
     $now = JFactory::getDate()->toSql();
     $nullDate = $db->getNullDate();
     $tagsToMatch = $tagsHelper->getTagIds($id, $prefix);
     if (!$tagsToMatch || is_null($tagsToMatch)) {
         return;
     }
     $tagCount = substr_count($tagsToMatch, ',') + 1;
     $query = $db->getQuery(true)->select(array($db->quoteName('m.core_content_id'), $db->quoteName('m.content_item_id'), $db->quoteName('m.type_alias'), 'COUNT( ' . $db->quoteName('tag_id') . ') AS ' . $db->quoteName('count'), $db->quoteName('ct.router'), $db->quoteName('cc.core_title'), $db->quoteName('cc.core_alias'), $db->quoteName('cc.core_catid'), $db->quoteName('cc.core_language'), $db->quoteName('cc.core_params'), $db->quoteName('cc.core_created_user_id'), $db->quoteName('cc.core_publish_up'), $db->quoteName('cc.core_images'), $db->quoteName('cc.core_created_time')));
     $query->from($db->quoteName('#__contentitem_tag_map', 'm'));
     $query->join('INNER', $db->quoteName('#__tags', 't') . ' ON m.tag_id = t.id')->join('INNER', $db->quoteName('#__ucm_content', 'cc') . ' ON m.core_content_id = cc.core_content_id')->join('INNER', $db->quoteName('#__content_types', 'ct') . ' ON m.type_alias = ct.type_alias');
     // Join over the created by field 'created_by'
     $query->select('`created_by`.name AS `author`, `created_by`.email as `author_email`');
     $query->join('LEFT', '#__users AS created_by ON created_by.id = cc.core_created_user_id');
     $query->where($db->quoteName('m.tag_id') . ' IN (' . $tagsToMatch . ')');
     $query->where('t.access IN (' . $groups . ')');
     $query->where('(cc.core_access IN (' . $groups . ') OR cc.core_access = 0)');
     // Don't show current item
     $query->where('(' . $db->quoteName('m.content_item_id') . ' <> ' . $id . ' OR ' . $db->quoteName('m.type_alias') . ' <> ' . $db->quote($prefix) . ')');
     // Only return published tags
     $query->where($db->quoteName('cc.core_state') . ' = 1 ')->where('(' . $db->quoteName('cc.core_publish_up') . '=' . $db->quote($nullDate) . ' OR ' . $db->quoteName('cc.core_publish_up') . '<=' . $db->quote($now) . ')')->where('(' . $db->quoteName('cc.core_publish_down') . '=' . $db->quote($nullDate) . ' OR ' . $db->quoteName('cc.core_publish_down') . '>=' . $db->quote($now) . ')');
     // Optionally filter on language
     $language = JComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
     if ($language != 'all') {
         if ($language == 'current_language') {
             $language = JHelperContent::getCurrentLanguage();
         }
         $query->where($db->quoteName('cc.core_language') . ' IN (' . $db->quote($language) . ', ' . $db->quote('*') . ')');
     }
     $query->group($db->quoteName(array('m.core_content_id', 'm.content_item_id', 'm.type_alias', 'ct.router', 'cc.core_title', 'cc.core_alias', 'cc.core_catid', 'cc.core_language', 'cc.core_params')));
     if ($matchtype == 'all' && $tagCount > 0) {
         $query->having('COUNT( ' . $db->quoteName('tag_id') . ')  = ' . $tagCount);
     } elseif ($matchtype == 'half' && $tagCount > 0) {
         $tagCountHalf = ceil($tagCount / 2);
         $query->having('COUNT( ' . $db->quoteName('tag_id') . ')  >= ' . $tagCountHalf);
     }
     if ($ordering == 'count' || $ordering == 'countrandom') {
         $query->order($db->quoteName('count') . ' DESC');
     }
     if ($ordering == 'random' || $ordering == 'countrandom') {
         $query->order('RAND()');
     }
     $db->setQuery($query, 0, $maximum);
     try {
         $results = $db->loadObjectList();
     } catch (RuntimeException $e) {
         $results = array();
         JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
     }
     foreach ($results as $result) {
         $explodedAlias = explode('.', $result->type_alias);
         $result->link = 'index.php?option=' . $explodedAlias[0] . '&view=' . $explodedAlias[1] . '&id=' . $result->content_item_id . '-' . $result->core_alias;
         $result->core_params = new Registry($result->core_params);
     }
     return $results;
 }