SpecialK
Well-known member
I am trying to extend the UserUpgrade model to add a new method to it, but it doesn't appear to be working. Here is what I have:
1. A listener on load_class_model. The hint is "XenForo_Model_UserUpgrade" and the callback is TFP_ExpiredSubs_Listener_LoadClassModel::extendUserUpgradeModel
2. My listener with the following content:
and is located at TFP/ExpiredSubs/Listener/LoadClassModel.php
3. My actual model extension with the following content:
and is located at TFP/ExpiredSubs/Extend/Model/UserUpgrade
I am trying to extend an admin controller method and use my new method, but I am getting an error stating that the method doesn't exist. EG:
I'm pulling my hair out over this. I have a feeling I'm doing something obviously stupid but I'm not spotting it. Any help would be appreciated.
1. A listener on load_class_model. The hint is "XenForo_Model_UserUpgrade" and the callback is TFP_ExpiredSubs_Listener_LoadClassModel::extendUserUpgradeModel
2. My listener with the following content:
PHP:
<?php
class TFP_ExpiredSubs_Listener_LoadClassModel
{
public static function extendUserUpgradeModel($class, array &$extend)
{
if ($class == 'Xenforo_Model_UserUpgrade')
{
$extend[] = 'TFP_ExpiredSubs_Extend_Model_UserUpgrade';
}
}
}
3. My actual model extension with the following content:
PHP:
<?php
class TFP_ExpiredSubs_Extend_Model_UserUpgrade extends XFCP_TFP_ExpiredSubs_Extend_Model_UserUpgrade {
/**
* Gets the expired upgrade records for the specified user.
*
* @param integer $userId
*
* @return array [upgrade id] => info (note, the id of the upgrade; not the user-specific record!)
*/
public function getExpiredUserUpgradeRecordsForUser($userId)
{
return $this->fetchAllKeyed('
SELECT user_upgrade_active.*,
user_upgrade.*
FROM xf_user_upgrade_active AS user_upgrade_active
LEFT JOIN xf_user_upgrade AS user_upgrade ON (user_upgrade.user_upgrade_id = user_upgrade_active.user_upgrade_id)
WHERE user_upgrade_active.user_id = ?
AND end_date < ?
AND end_date > 0
', 'user_upgrade_id', array($userId, XenForo_Application::$time));
}
}
I am trying to extend an admin controller method and use my new method, but I am getting an error stating that the method doesn't exist. EG:
PHP:
<?php
class TFP_ExpiredSubs_Extend_ControllerAdmin_User extends XFCP_TFP_ExpiredSubs_Extend_ControllerAdmin_User {
public function actionExtra()
{
$return = parent::actionExtra();
$userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
$user = $this->_getUserOrError($userId);
/** @var XenForo_Model_UserUpgrade $upgradeModel */
$expiredUpgradeModel = $this->getModelFromCache('XenForo_Model_UserUpgrade');
$expiredUpgradeRecords = $expiredUpgradeModel->getExpiredUserUpgradeRecordsForUser($user['user_id']);
return $return;
}
}
I'm pulling my hair out over this. I have a feeling I'm doing something obviously stupid but I'm not spotting it. Any help would be appreciated.