当前位置: 首页>>代码示例>>PHP>>正文


PHP JUDirectoryHelper::addCategory方法代码示例

本文整理汇总了PHP中JUDirectoryHelper::addCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP JUDirectoryHelper::addCategory方法的具体用法?PHP JUDirectoryHelper::addCategory怎么用?PHP JUDirectoryHelper::addCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JUDirectoryHelper的用法示例。


在下文中一共展示了JUDirectoryHelper::addCategory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: storeValue

 public function storeValue($value)
 {
     $db = JFactory::getDbo();
     $mainCatId = isset($value['main']) ? $value['main'] : '';
     if (isset($value['secondary'])) {
         $secondaryCatIds = explode(",", $value['secondary']);
         $secondaryCatIds = array_unique($secondaryCatIds);
         if (is_array($secondaryCatIds) && count($secondaryCatIds) > 0) {
             foreach ($secondaryCatIds as $i => $secondaryCatId) {
                 if (!is_numeric($secondaryCatId) || $secondaryCatId <= 0 || $secondaryCatId == $mainCatId) {
                     unset($secondaryCatIds[$i]);
                 }
             }
         }
     }
     if ($mainCatId) {
         if (!isset($this->listing->cat_id) || !$this->listing->cat_id) {
             // Insert main category
             $saveMainCat = JUDirectoryHelper::addCategory($this->listing_id, $mainCatId, 1);
             if (!$saveMainCat) {
                 return false;
             }
         } else {
             // Update main cat id
             if ($this->listing->cat_id != $mainCatId) {
                 $query = "UPDATE #__judirectory_listings_xref SET cat_id = " . $mainCatId . " WHERE listing_id= " . $this->listing_id . " AND main = 1";
                 $db->setQuery($query);
                 $db->execute();
             }
         }
     }
     /* Add/Update secondary categories */
     $allowCatIds = array();
     if (isset($secondaryCatIds)) {
         if ($secondaryCatIds) {
             foreach ($secondaryCatIds as $key => $catId) {
                 $query = "SELECT id FROM #__judirectory_listings_xref WHERE listing_id = " . $this->listing_id . " AND cat_id = {$catId} AND main = 0";
                 $db->setQuery($query);
                 $itemId = $db->loadResult();
                 if ($itemId) {
                     $allowCatIds[] = $catId;
                     $query = "UPDATE #__judirectory_listings_xref SET ordering = " . ($key + 1) . " WHERE id = " . $itemId;
                     $db->setQuery($query);
                     $db->execute();
                 } else {
                     // Insert new secondary cat if it is not exists
                     if (JUDirectoryHelper::addCategory($this->listing_id, $catId, 0, $key + 1)) {
                         $allowCatIds[] = $catId;
                     }
                 }
             }
         }
         $query = $db->getQuery(true);
         $query->delete('#__judirectory_listings_xref')->where('listing_id = ' . $this->listing_id)->where('main = 0');
         if ($allowCatIds) {
             $query->where('cat_id NOT IN (' . implode(',', $allowCatIds) . ')');
         }
         $db->setQuery($query);
         $db->execute();
     }
     /* End - Process secondary categories */
     return true;
 }
开发者ID:ranrolls,项目名称:ras-full-portal,代码行数:63,代码来源:core_categories.php


注:本文中的JUDirectoryHelper::addCategory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。