Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

I created a class that extends admin\tokens - why did all actions stop working?

  • alorenc
  • alorenc's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 2 months ago #212140 by alorenc
Limesurvey v3.25 does not supported PHP paging for LDAP.

The "ldap_doTokenSearch ()" function from ldap_helper.php is actually responsible for the import. Overwriting the function would not be a good idea in this case.

So I decided to create the admin\tokensext.php class that extends the tokens.php class and override the importldap() method.

I set it to import my helper from importldap() method:
Yii::app()->loadHelper('ldappaging');

Then in AdminController for the getActionClasses() method I changed the entry "'tokens' => 'tokensext',"

I would have to overwrite them to make them work as well. So in the tokensext class with a reference to the parent method. Example:
Code:
public function browse($iSurveyId, $limit = 50, $start = 0): void
    {
        parent::browse($iSurveyId, $limit, $start);
    }
I don't want to do it that way. Normally a class extension should work. And the actions should be directed to the parent's methods. But in this case, they don't work or return any error.

What did I do wrong? or possibly how should I have done it correctly?
The topic has been locked.
  • alorenc
  • alorenc's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 1 month ago #212169 by alorenc
I found in the runWithParams method in the Survey_Common_Action class Line 75:
Code:
if (empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != strtolower($aActions[$this->getId()]) || !$oMethod->isPublic()) {
    $oMethod = new ReflectionMethod($this, $sDefault);
}
In this state, "$oMethod->getDeclaringClass ()->name" returns "tokens" and strtolower($aActions[$ this->getId()]) returns my "tokensext". Therefore it returns the default page which is "index".

I added an override to the runWithParams method in my tokensext class:
Code:
public function runWithParams($params)
    {
        if (empty($params['sa'])) {
            $sSubAction = 'index';
        } else {
            $sSubAction = $params['sa'];
        }
 
        $oClass = new ReflectionClass($this);
        if (!$oClass->hasMethod($sSubAction)) {
            $sSubAction = 'run';
        }
 
        $params = $this->_addPseudoParams($params);
 
        if (!empty($params['iSurveyId'])) {
            LimeExpressionManager::SetSurveyId($params['iSurveyId']);
        }
 
        $oMethod  = new ReflectionMethod($this, $sSubAction);
 
        if (strtolower($oMethod->getDeclaringClass()->name) == 'tokens' && $oMethod->getName() != 'importldap') {
            return parent::runWithParamsInternal($this, $oMethod, $params);
        } else {
            return parent::runWithParams($params);
        }
    }
Everything would be nice if the _addPseudoParams method modifier in the Survey_Common_Action class was not private, but e.g. protected. But unfortunately this is not the case and the example above will not work.

How can I do it differently?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212206 by DenisChenu
manual.limesurvey.org/BeforeControllerAction

This allow to run your own controller,

But : it's really hard to have a plugin allowing update with this

I have this working plugin : gitlab.com/SondagesPro/ExportAndStats/extendAdminStatitistics
in 2.50, 2.63. Broke around 2.70

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: alorenc
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose