jDownloads Support Forum

Older Versions => jDownloads 3.2 (Support ended) => Bugs => Topic started by: pharin on 21.05.2015 14:44:18

Title: AlphaUserPoints: Rule User Upload published does not work - [Fixed in 3.2.33!!!]
Post by: pharin on 21.05.2015 14:44:18
Hey jDownloads Members,

following setup:
jDownloads 3.2
AlphaUserPoints 2.0.0

Set jdownloads setting for Alphauserpoints to true
Added, published, approved the download and upload rule for jdownloads in alphauserpoints

Download rule works
Upload rule does not work

At upload it jumps into the marked lines and sets it
           if ($app->isSite() && !$auto_added){
               if ($isNew){
                  $this->submitted_by   = $user->id;
                  $this->set_aup_points = 1;
                   if ($user_rules->uploads_auto_publish == 1){
                       $this->published = 1;
                   }
               }

But doesn`t get to this method setAUPPointsUploads to send this to alphauserpoints -> maybe because it will be redirected to category ?
Method in components\com_jdownloads\helpers         public static function setAUPPointsUploads($submitted_by, $file_title) won`t be called at all but this one should be executed right ?

Please- Can someone test and verify the upload rule for alphauserpoints does not work?

Greetings

pharin




Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: pharin on 24.05.2015 21:26:48
Hey,

I analysed it.
Currently the user upload rule of alphauserpoints is not supported in 3.2 versions

As a short term solution I created following fix:
I have adapted the function postSaveHook in file components\com_jdownloads\controllers\download.php with following code lines

protected function postSaveHook(JModelLegacy $model, $validData = array())
{
global $jlistConfig;
$task = $this->getTask();

if ($task == 'save') {
if ($jlistConfig['use.alphauserpoints']){
$file_title = $validData["file_title"];
$user = JFactory::getUser()->id;
JDHelper::setAUPPointsUploads($user,$file_title);
}
$this->setRedirect(JRoute::_('index.php?option=com_jdownloads&view=category&id='.$validData['cat_id'], false));
}
}



@Arno - Please let me know if this is OK as a work around and when it`s possible to receive an update for this issue.

Greetings,

pharin
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: Arno on 24.05.2015 22:00:35
Hi Pharin,
i know that some users use succesful the AUP support in jD 3.2.x.
Maybe possible that this users used not the 'upload' plugin. So i will check this tommorow more in detail.
So please wait a little bit.  ;)
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: pharin on 25.05.2015 02:55:53
Hey,

I`ve extended it a bit as I need to to be able to write a specific answer after the upload of the file has been successfully made. (=>e.g. Letting the user know how much alphauserpoints are available after the upload.)
Please take this as a suggestion / proposal -> I`m not the expert. This is just the workaround for me.

Additional method in jdownloadshelper.php


/**
    * Check AlphaUserPoints for the current user
    *   
    * @param
    *
    * @return  decimal
    */
    public static function getUserPoints()
    {
    global $jlistConfig;
    $points = 0;
    $user   = JFactory::getUser();
    if ($jlistConfig['use.alphauserpoints'] && $user){
    $api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
    if (file_exists($api_AUP)){
    require_once ($api_AUP);
    // get current user points - stored in $profil->points
    $aup = new AlphaUserPointsHelper;
    $profil = $aup->getUserInfo('', $user->id);
   
    if ($profil){
    $points = $profil->points;
    }
   
    }
    }
    return $points;
    }


and change of the function postSaveHook in com_jdownloads/controllers/download.php

/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModel $model The data model object.
* @param array $validData The validated data.
*
* @return void
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
{
global $jlistConfig;
$task = $this->getTask();

if ($task == 'save') {
if ($jlistConfig['use.alphauserpoints']){
$file_title = $validData["file_title"];
$user = JFactory::getUser()->id;
JDHelper::setAUPPointsUploads($user,$file_title);
$points = JDHelper::getUserPoints();
$this->message =  JText::_('COM_JDOWNLOADS_AUP_UPLOAD_POINTS').$points;
}
$this->setRedirect(JRoute::_('index.php?option=com_jdownloads&view=category&id='.$validData['cat_id'], false));
}
}


and changes in the language file for german and english:
COM_JDOWNLOADS_AUP_UPLOAD_POINTS="Vielen Dank für`s Hochladen. Die Datei wurde erfolgreich gespeichert. Zugleich werden Ihnen Punkte für weitere Downloads gutgeschrieben.

Aktueller Punktestand: "
COM_JDOWNLOADS_AUP_UPLOAD_POINTS="Thanks for the upload. The file has been stored successfully. Likewise points will be credited for further downloads

Your credit points: "

Greetings,

pharin
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: Arno on 26.05.2015 10:29:13
Hi pharin,
ich antworte jetzt mal auf deutsch.

- Ich muss bestätigen das wir hier einen Bug haben.   :-\

- Deine Lösung kannst du so natürlich machen. Bedenke aber, dass die Punkte nur einmal und nur dann vergeben werden, wenn ein neu erstellter Download auch veröffentlicht wird.
Also nicht unbedingt automatisch beim Speichern. Kommt halt hier dann auch darauf an, ob das Feld zur Veröffentlichung zur Anzeige im Formular aktiviert wurde.
Auch kann die Veröffentlichung später im Backend ODER Frontend vorgenommen werden.
Ich werde das ganze für mich daher ein wenig anders lösen müssen.

- Ich arbeite schon an einem Fix.
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: pharin on 26.05.2015 12:34:51
Hi Arno,

sehr cool! Danke für die Info und dass du dich dem Problem annimmst.
In meinem Fall wird es immer gleich auto-gepublished.
Da hast du auch recht und ich hab nicht mitgedacht -> ein file wird nicht unbedingt gleich gepublished, sondern vielleicht auch erst später.

Sollte ich dir beim Testen helfen können oder nochmal drüberkucken, sobald der Fix fertig ist, kann ich das gerne machen.

Grüße,

pharin
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: Arno on 26.05.2015 14:28:24
Hi pharin,
sicher kannst du mir beim Testen helfen.

$this->set_aup_points = 1;
Dieses ist noch ein überbleibsel aus einer viel älteren Version.
Die AUP Rules hatten halt früher nicht die Möglichkeit wie heute, im Plugin festzulegen, wie oft die Punkte bei einer Aktion vergeben werden sollen.
Kann daher eigentlich nun entfallen. Na ja mal sehen.
Veröffentlichen im BE ist fast fertig. Schicke es dir nachher.

Ärgere mich das ich dass wohl leider nicht getestet hatte. Aber bei der Größe und auf Grund der vielen Möglichkeiten der Komponente ist das leider schon mal möglich.  :-\

[gelöscht durch Administrator]
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: Arno on 26.05.2015 17:20:06
Hi,
bitte teste die untenstehende Vorabversion 3.2.33. Sollte jetzt beides funktionieren. Also das Veröffentlichen sowohl im Backend als auch im Frontend mit den Einstellungen der Regel.
Hier auf die richtige Einstellung achten (Only once per user).
Einen Mitteilungstext kannst du darin ebenfalls definieren. ;)

[gelöscht durch Administrator]
Title: Re: AlphaUserPoints: Rule User Upload published for Jdownloads does not work
Post by: pharin on 27.05.2015 11:34:47
Hi Arno,

1. ich habs getestet.
Alles funktioniert soweit top. Die Nachricht wird dargestellt und auch die Punkte werden sauber nach oben gezählt. das Feld {points} zeigt die Punkte an die einem gutgeschrieben werden, was auch mehr Sinn macht. Muss ich bei mir noch anpassen....
Einzig und allein wenn die AlphaUser-Nachricht erscheint, braucht es keine Nachricht "der Eintrag wurde übermittelt" mehr. Aber das ist auch erstmal wurscht.


2. Lässt sich bei dem Alphauser - Nachricht im Hintergrund das Ganze auch für andere Sprachen (multilingual) einstellen ? Hab auch nachgekuckt aber habs nicht gefunden :( ? in \language\de-DE\de-DE.com_alphauserpoints.ini hab ichs nicht gefunden ....

3. Zum Code:

Den Code in tables\dowload.php könnte man noch vereinfachen:
              if ($isNew){
                   $this->submitted_by   = $user->id;
                   if ($user_rules->uploads_auto_publish == 1){
                       $this->published = 1;
                   }
                   if ($jlistConfig['use.alphauserpoints'] && $this->published == 1){
                       // add the AUP points
                       //JDHelper::setAUPPointsUploads($this->submitted_by, $this->file_title);
                   }
               } else {
                   if ($jlistConfig['use.alphauserpoints'] && $this->published == 1){
                       // add the AUP points when an older download is published (maybe the first time)
                       JDHelper::setAUPPointsUploads($this->submitted_by, $this->file_title);
                   }


ersetzen durch:


if ($isNew){
                   $this->submitted_by   = $user->id;
                   if ($user_rules->uploads_auto_publish == 1){
                       $this->published = 1;
                   }
                 
               }
                   if ($jlistConfig['use.alphauserpoints'] && $this->published == 1){
                       // add the AUP points when an older download is published (maybe the first time)
                       JDHelper::setAUPPointsUploads($this->submitted_by, $this->file_title);
                   }



4. Nur so aus Interesse: Das setzen von setAUPPointsUploads in der admin/controller/download.php ist dann nötig wenn auto_added true ist bzw. die Überwachung an ist und das file gepublished wird oder ?

5.   Braucht man den else-Zweig da überhaupt noch ? (admin/tables/download.php)

     if ($app->isSite() && !$auto_added){
               if ($isNew){
                   $this->submitted_by   = $user->id;
                   if ($user_rules->uploads_auto_publish == 1){
                       $this->published = 1;
                   }
                 
               }
                   if ($jlistConfig['use.alphauserpoints'] && $this->published == 1){
                       // add the AUP points when an older download is published (maybe the first time)
                       JDHelper::setAUPPointsUploads($this->submitted_by, $this->file_title);
                   }
               }
           } else {    
               $this->set_aup_points = $jinput->get('set_aup_points', 0, 'integer');
               $this->submitted_by   = $jinput->get('submitted_by', 0, 'integer');
           }    







Auf jeden Fall DANKE VIELMALS für das schnelle unkomplizierte Fixen!

Gruß,

pharin

[gelöscht durch Administrator]
Title: Re: AlphaUserPoints: Rule User Upload published does not work - Fixed in 3.2.33
Post by: Arno on 30.05.2015 01:09:02
Hi pharin,
das mit den 2 Meldungen ist logisch - einmal vom Speichervorgang und einmal von AUP. Musst du halt die von AUP anders texten, dann passt das schon.

Edit:
Quote2. Lässt sich bei dem Alphauser - Nachricht im Hintergrund das Ganze auch für andere Sprachen (multilingual) einstellen ? Hab auch nachgekuckt aber habs nicht gefunden Traurig ? in \language\de-DE\de-DE.com_alphauserpoints.ini hab ichs nicht gefunden ....
Habe ich noch nicht nachgesehen - frag mal im AUP Forum nach.

Quote3. Zum Code:
aktuell geht es so, daher wäre ich mit Änderungen vorsichtig.