本文整理汇总了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;
}