Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
1.0k views
in Q2A Core by
I want to add a favorite button inside each tag in the tags list page and i really don't know how to do that !

What i am trying to do is that after a user is registered in the site i want to display the tags list page and force the user to "favorite" 2-3 tags.

Right now i am able to redirect the register user to the tags list page but i cant add the favorite button inside each tag !! I know that it could be done and i really dont care about hack/modify the core files but is very important to me as i want to launch my community soon (its a fashion community for young women btw :) ).

Maybe @sama55 or @pupi could enlight me ????

Ps i have little php and javascript experience

Thanks in advance for your answers and this brilliant script !!!!
Q2A version: 1.7.4

2 Answers

+1 vote
by

Instead of redirecting to tags page, you should create dedicated tags page for registered users.

Layer hack example (This is just hint. It is incomplete!):

public function ranking_cell($content, $class) {
    qa_html_theme_base::ranking_cell($content, $class);
    if($class == 'qa-top-tags-label') {
        $tagword = qa_db_select_with_pending(qa_db_tag_word_selectspec(strip_tags($content)));
        $fform =qa_favorite_form(QA_ENTITY_TAG, $tagword['wordid'], false,
            qa_lang_sub('main/add_tag_x_favorites', $tagword['word']));
        $favoritetags = $fform['favorite_tags'];
        $this->output('<td class="qa-tags-favoriting" ' . $favoritetags . '>');
        $this->output('<form ' . $fform['form_tags'] . '>');
        $this->favorite_inner_html($fform);
        $formhidden = isset($fform['form_hidden']) ? $fform['form_hidden'] : null;
        $this->form_hidden_elements($formhidden);
        $this->output('</form>');
        $this->output('</td');
    }
}

by
thanks for this code is so helpfully  for  create dedicated tags page
+1 vote
by
edited by

I just tried your example @sama55 and it somehow works. But as i m very new on the Q2A framework i really cant understand how to make it works. Right now it displays the favorite "star icon" next to each tag and it generates a unique name eg (favorite_T_604_1) on each tag as it should be, but when i click on each "star icon" it saves the tag to my favorites but it doesn't show the "star icon"  as activated/favorited. On error console i am getting this error :

"TypeError: elem.form is null"

from file qa-page.js when i try to unfavorite a tag.

in the file qa-page.js there is this function:

function qa_favorite_click(elem) {   
var ens=elem.name.split('_');   
 var code=elem.form.elements.code.value;     
qa_ajax_post('favorite', {entitytype:ens[1], entityid:ens[2], favorite:parseInt(ens[3]), code:code},         function (lines) {           
 if (lines[0]=='1')                
qa_set_inner_html(document.getElementById('favoriting'), 'favoriting', lines.slice(1).join("\n"));             else if (lines[0]=='0') {                
alert(lines[1]);                
qa_hide_waiting(elem);             }
else                
qa_ajax_error();         }     );   
  qa_show_waiting_after(elem, false);     
return false; }


Could you please guide me little bit more @sama55 cause this function is very important to me and i guess for other users too from what i already did read in the forum.

Many Thanks

by
There is no "wordid" in the core tags page. It is necessary for favorite form creation. In my answer example, queries to get wordid is executed within the tag loop. Therefore, when there are many tags, performance will be very bad.

By the way, probably, you know "example-page" plugin.  You can create tags page for registered users in this way. On this page, performance problems do not occur by executing a query that also acquires wordid instead of qa_db_popular_tags_selectspec.  This information is not all, but it will be helpful.
by
@ sama55 thanks for helping and replying too. I think i dont have so much knowledge (yet) in Q2A framework.
However if you could build that function for me i should buy it for sure.

Once again Thank you so much for your help.
by
I do not allow PM on this site. Please register to my site, and request to me.
http://www.powerqa.org/qa/
...