助けてください、これは私が書いている最初のプラグインで、完全に迷っています。カスタムのGiveBadge()関数を使用して、joomla データベースのテーブルに情報を書き込んで更新しようとしています。関数は 2 つの異なる変数を受け取ります。最初の変数は$userIDで、2 番目の変数は数字300で、これをクラスの最後でgiveBadge(300)を使用して渡します。同時に、Joomla データベースの$userIDを比較して、Joomla サイトにログインしている現在のユーザーに番号300が与えられていることを確認します。
前もって感謝します。
<?php
defined('JPATH_BASE') or die;
class plgUserBadge extends JPlugin
{
public function onUserLogin () {
$user =& JFactory::getUser();
$userID =& user->userID;
return $userID;
}
public function giveBadge ($userID, &$badgeID) {
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
'profile_value=\'Updating custom message for user 1001.\'',
'ordering=2');
// Conditions for which records should be updated.
$conditions = array(
'user_id='.$userID,
'profile_key=\'custom.message\'');
$query->update($db->quoteName('#__user_badges'))->set($fields)->where($conditions);
$db->setQuery($query);
try {
$result = $db->query();
} catch (Exception $e) {
// Catch the error.
}es = array(1001, $db->quote('custom.message'), $db->quote('Inserting a record using insert()'), 1);
}
}
giveBadge(300); //attaches to $badgeID
?>