How do you get the Respondent ID from a Survey Monkey survey? - php

The Story
I'm in the beginning stages of creating a video teaching engine for a retailer incentive program my company is putting together. The way it will work is that retailers will register and be provided the ability to login to the system to access the content. Once logged in, retailers will watch short videos about my company's products and then they will be asked to answer a 3 or 4 question quiz about the product. The idea is that based on their responses they will earn the incentive. For example: the user passes 10 quizzes then they get a significant discount on their next order from my company.
The Problem
So I'm getting to the point where I'm researching different ways to go about putting together the whole program and am trying to determine the best way to write it. One thought so far is to create the quizzes as SurveyMonkey surveys and then process the results from that to award the incentive. I've been looking through the SurveyMonkey PHP API and I see that there is a method to get_responses(), which seems like it's exactly what I'm after. The problem is, is that this method takes a respondent_id for one of the parameters, which I have no idea how you get.
The Question
How do I get the respondent_id after the user has taken the quiz/survey? Ideally I would like to get this, then get the response information, process it, and then output a result/increment the number of incentives earned. I did do some looking around here on StackOverflow and found this: Get details about survey monkey's questions and answers by id, but it doesn't really look like what I'm after.
If this isn't something that SurveyMonkey can really do, that's OK, as I'm more just looking for an efficient way of doing it, short of having to build the whole thing myself. As always any help or info is appreciated!

In order to get the responses, you need a list of respondent_ids. And in order to get the respondent_ids, you need to have the survey_id(s) from the get_survey_list API call. Note that the responses only includes a question_id that maps to the question (text and possible answers) in the output of get_survey_details (with the exception of open-ended text answers).
If this isn't something that SurveyMonkey can really do, that's OK, as I'm more just looking for an efficient way of doing it, short of having to build the whole thing myself.
It takes a modest code infrastructure to get all these pieces put together. You may want to start with the API Console and see if the output of the API can be of use to you.

https://developer.surveymonkey.com/mashery/get_respondent_list seems to be what you are looking for, from there you can get the response information.

Related

In a social network environment, what would be the easiest way to check for friendships globally?

For reference, here is a question on SO that I asked recently that is relevant to this question: How to model Friendship relationships
On that question, we figured out a way to display news feed items only if posted by friends. However, what I need is advice on how to check for friendship in a more dynamic way so it can be used throughout several site functions.
For example, I've just installed a comment system, allowing users to post comments on news posts. However, this isn't restricted to friends, and it should be (and later should be made optional by the author of the post).
Posting news items only by friends was slightly different because I was getting data directly from the database, and using SELECT subqueries to only get posts by friends of the current user. However, in the example of the commenting, I only want to display the comment post form if the person is a friend. I'm not actually pulling anything from the database to pick, sort, and display.
Knowing issues like this will arise many times throughout the site, what would be the simplest way to check for friendship? Could I somehow pull all the friends' user IDs from the database into a session array of some kind and then do an if(in_array($friends)) whenever I needed to determine if the person in question is a friend of the currently logged in user? Off the top of my head, this sounds like it would work fine, but I'd like your input first.
The question I linked to above explains how my friendship table works, in case that help you help me with this.
Actually, it is a very bad idea to stor the friend array in the session. What happens if some you add a new friend after the session variable is created? It does not get updated in the session.
Since you will be checking the list of friends a lot of times on the same page, why not just query it out and store it in a local array that you can keep using on the same page.
When the page finish executing, the array will be discarded.
So basically, you will only query the list out once.
A recommended implementation would be to follow the advise of "pst" in the above comment, and just query for every time you need to find the relationship first, as that is simple to implement. Later, when the speed of the query starts to become a issue, you can just change the internal of that method to cache the friend list in a local array when it is first called to speed things up. (exchange memory usage for processor usage).

Integrating a 1-10 voting system effectively without common pitfalls

I'm planning on integrating a reasonable ranking/voting system into an existing application.
I'm familiar with how the traditional 5 star rating systems work and know the common pitfalls/problems associated with them therefore was wondering if there is other ways (I've heard of Wilsons, Bayesian etc. but not really sure on how to implement this with the below structure):
I'm planning on allowing users to vote on content between 1 to 10 via the contents page.
The score and total votes for that content will be displayed on the contents page.
I will also be displaying/listing the Top 10 Content so I'd need the method to be fair/realistic and not make a vote of 10 with total votes of 1 to go straight to number 1.
I'm using PHP and MySQL, I have a table for the content (which has a content_id which I guess I can JOIN on).
I'm wondering if you can suggest a way/method which achieves the above, I'd appreciate if you can attach some example PHP code and example MySQL schema so I can better understand it, as I've google'd and may have found potential solutions such as Wilsons and Bayesian...yet they provide a lengthy article with confusing mathematical equations - and mention no way which achieves the above (ie. the score....and implenting the method in PHP/MySQL) or atleast due to there not being any example PHP/MySQL code me misunderstanding this.
Perhaps this is easier then I think - I don't know as I've never had the need to implement this sort of "more complex" ranking/voting functionality before - so I'd appreciate your responses.
You should start by watching this video on youtube : Building Web Reputation Systems.
To emphasize the point, let me direct you to XKCD.
As for DB structure, you need following parts:
list of items ( with total_votes column )
list of user, which have voted
intersection table for the items-users ( with rating column, if you go with 5star thing )

Need to add "This answer helped" for an FAQ/KB using PHP/MySQL

I've found ways to rank existing values but it's been awhile and I'm not sure the best way to add a "This answered my question" function to my KB/FAQ. I guess my biggest problem is separating multiple queries into individual ones so I can plug this feature in. I'm assuming I'd just have to add a insert into the database that will +1 each time someone clicks the button, but it's been awhile and I haven't done this before.
As a further clarification, Im using this within a Facebook app I'm making so need to rate individual answers that are generated by the search of my knowledge base to produce better answers. It's all dynamic, so no static pages.
Haven't found an answer that could help thus far.
Consider adding something like the Google Plus One button to your site. It's very easy to implement and you don't have to worry about any backend stuff as a result.
Or search on google.

How to Create Quiz using PHP, MySQL and Jquery

I need to create a quiz/multiple choice questions with correct answer.
Its basically for vocabulary, so 'A definition will be shown' and then possible Words would be provided.
My previous plan: Select word and meaning from Database, then generate the form for answers and then when user answers move on to next word.
I would be selecting words from database randomly, to keep it different each time. Also, I would be noting down how many times the word was answered correctly or incorrectly. So, that later on I can arrange them according to difficulty also.
My Problem: How do I update to the next question when user answers the question? How do I move on to the next problem, I thought I could do it easily using Jquery but integrating Jquery with PHP is tougher than it seems. I searched for plugins but they basically hard code the question in the JS, I wish to take them out from Database which would be updated as required.
Its a pet project, just so that I can help people practice their Vocabulary. I have implemented the basic design and also developed space for people to Contribute their words. The plans for expansion are vast with many possible directions, later, ranking system, facebook integration, etc. etc. I wish to finish it by the end of this weekend, so that I can move on to other things.
You can see vocabulary.dharamveer.in but you would only get idea about the basic application, not much regarding the problem at hand.
Eagerly awaiting your answers, thank you for help in advance :)
ajax is definitely the way to go with this, use ajax with json to load up your questions and then just have jquery loop through them.
Option 1
If you are creating a set length quiz, you could always create the full quiz off the start. That way you can ensure there are no repeating questions without the need to save anything. Then you can just loop through the whole quiz without making a call for each question.
Option 2
If it's a never ending quiz, then maybe you can do the questions in batches. Then when the user is done the old batch you can send that one back as a parameter and exclude them from the new batch. If your batches are large (for example 50 questions), than it would be at the very least 50 questions until a repeat and that's the worst case. Depending on how many questions you have total, you could end up with multiple batches before a repeat.
I would use Ajax to he the next question. Have another page simply retrieve a single random question and retrieve it with jquery Ajax.

Forum achievements on a phpBB3 board?

I recently started a new community. The forum software is phpBB3, and so far so good. In an attempt to make my community more unique and interesting, I had to idea of having user achievements. Let me give you a quick run-down.
Each user has achievements that they can earn (these will probably be across all users), for example an achievement for when a user hits 1,000 posts, when they upload an avatar, when one of their topics gets 1,000 views and so on. Each achievement has points, for example an achievement like uploading an avatar will be 10 points and reaching 10,000 points will grant 50 achievement points. If anyone here plays World of Warcraft you may be seeing where I'm getting the ideas from. :)
What I'm struggling to get my head around though is how exactly to code this... I could keep a record of all users activity and add it to a special database table possibly, and then check via cron every minute or so if any user has met achievement criteria... but then I also want it controllable through the ACP so I can easily add new achievements and change their points etc. My mind is pretty blank when it comes to anything but the most simple things.
What I really posted here for was feedback on the idea and how you all think I should go about doing this. The coding part should be pretty simple for me once I get my head around how phpBBB MODs need to be written.
Thanks for reading, and I look forward to your replies. :)
Have you checked out this mod?
http://www.phpbb.com/community/viewtopic.php?f=70&t=1696785
It's in beta at the moment but it looks like it's sorta what you're trying to accomplish. Even if it isn't, you can always take it and make something else out of it. I have heavily modified existing mods to suite my site. It takes a little while to get your head around how things are done with phpbb3 but it is easy when you start doing it.
In regards to creating your own, I don't think this has to be done on crontab. You could simply inject a function into the relevant parts of code.
With post counts, there is already a function that updates the description under the avatar of users based on certain post numbers, you could probably put an extra function update_achievement() there. Same goes with the avatar being updated. Unfortunately, taking this approach you will not be able to edit the achievements completely from the ACP but you could possibly have an interface that could enable/disable certain achievements.
You will obviously need an extra table or two for this. Without thinking too much, I would have 1 table that has 2 columns, user and acheivement_id. Then another table which just lists the acheivements ids and descriptions etc..

Categories