function __construct() { parent::__construct(); $this->cedTagModelTag = new CedTagModelTag(); }
function __construct() { parent::__construct(); }
/** * @param $name * @param null $description * @param int $weight * @return bool|int */ public function store($name, $description = null, $weight = 0) { $dbo = JFactory::getDbo(); $cedTagsHelper = new CedTagsHelper(); $name = $cedTagsHelper->isValidName($name); if (!$name) { return false; } $cedTagModelTag = new CedTagModelTag(); $tagAlreadyExisting = $cedTagModelTag->getTagId($name); if (isset($tagAlreadyExisting) & isset($tagAlreadyExisting->id)) { $needUpdate = false; $updateQuery = 'update #__cedtag_term set '; if (isset($description) && !empty($description)) { $needUpdate = true; $updateQuery .= "description='" . $description . "'"; } if (isset($weight)) { if ($needUpdate) { $updateQuery .= ', weight=' . $weight; } else { $updateQuery .= ' weight=' . $weight; $needUpdate = true; } } if ($needUpdate) { $updateQuery .= ' where id=' . $tagAlreadyExisting->id; $dbo->setQuery($updateQuery); $dbo->query(); } return $tagAlreadyExisting->id; } else { $insertQuery = "insert into #__cedtag_term (name"; $valuePart = " values('" . $name . "'"; if (isset($description) && !empty($description)) { $insertQuery .= ",description"; $valuePart .= ",'" . $description . "'"; } if (isset($weight)) { $insertQuery .= ",weight"; $valuePart .= "," . $weight; } $date = JFactory::getDate(); $now = JDate::getInstance()->toSql($date); $insertQuery .= ',created) '; $valuePart .= ',' . $dbo->Quote($now) . ')'; $dbo->setQuery($insertQuery . $valuePart); $dbo->query(); return $dbo->insertid(); } }