本文整理汇总了PHP中JUDownloadHelper::addCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP JUDownloadHelper::addCategory方法的具体用法?PHP JUDownloadHelper::addCategory怎么用?PHP JUDownloadHelper::addCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUDownloadHelper
的用法示例。
在下文中一共展示了JUDownloadHelper::addCategory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeValue
public function storeValue($value, $type = 'default', $inputData = null)
{
$db = JFactory::getDbo();
$mainCatId = $value['main'];
$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 (!isset($this->doc->cat_id) || !$this->doc->cat_id)
{
$saveMainCat = JUDownloadHelper::addCategory($this->doc_id, $mainCatId, 1);
if (!$saveMainCat)
{
return false;
}
}
else
{
if ($this->doc->cat_id != $mainCatId)
{
$query = "UPDATE #__judownload_documents_xref SET cat_id = " . $mainCatId . " WHERE doc_id= " . $this->doc_id . " AND main = 1";
$db->setQuery($query);
$db->execute();
}
$secondaryCatIdsDB = $this->getSecondaryCategoryIds($this->doc_id);
$removeSecondaryCatIds = array_diff($secondaryCatIdsDB, $secondaryCatIds);
if ($removeSecondaryCatIds)
{
$query = "DELETE FROM #__judownload_documents_xref WHERE (doc_id= " . $this->doc_id . " AND main=0 AND cat_id IN (" . implode(",", $removeSecondaryCatIds) . "))";
$db->setQuery($query);
$db->execute();
}
}
foreach ($secondaryCatIds AS $key => $catId)
{
$query = "SELECT id FROM #__judownload_documents_xref WHERE doc_id = " . $this->doc_id . " AND cat_id = $catId AND main = 0";
$db->setQuery($query);
$itemId = $db->loadResult();
if ($itemId)
{
$query = "UPDATE #__judownload_documents_xref SET ordering = " . ($key + 1) . " WHERE id = " . $itemId;
$db->setQuery($query);
$db->execute();
}
else
{
JUDownloadHelper::addCategory($this->doc_id, $catId, 0, $key + 1);
}
}
return true;
}