I have an app that I'm trying to write where users can view the photos that have been uploaded to an event's wall. I've managed to write a PHP script that gives me the photos and their URL's but I can't see how to get the event id that a photo has been posted against (so that each picture can be associated with the date of the event and therefore only show the appropriate ones when a user clicks on a calendar).
$event_id_name = 'actor_id'; //changed each attempt to something from the Facebook 'stream' table
$fql = array(
"permsQuery"=>"SELECT user_events, create_event FROM permissions WHERE uid = me()",
"query1"=>"SELECT eid FROM event_member WHERE uid = me()",
"query2"=>"SELECT name,start_time, eid FROM event WHERE eid IN (SELECT eid FROM #query1)",
"query3"=> 'SELECT attachment, '.$event_id_name.' FROM stream WHERE source_id IN (SELECT eid FROM #query1)',
"userQuery"=>"SELECT first_name FROM user WHERE uid = me()",
);
$ret_obj = $facebook->api(array('method' => 'fql.multiquery',
'access_token' => $access_token,
'scope' => $required_permissions,
'queries' => $fql,
));
//get the index of the query in the returned sets
//Yes, I'm sure there's an easier way of doing this! :)
$x = 0;
while ($x < count($ret_obj))
{
if ($ret_obj[$x]['name'] == 'query3') {$returnedPostIndex = $x;}
$x++;
}
//for debugging, just throw out the array elements in an relatively easy format
$x = 0;
while ($x < count($ret_obj[$returnedPostIndex][$results_set]))
{
print_r ($ret_obj[$returnedPostIndex][$results_set][$x][$event_id_name]);
print_r (' : ');
print_r (count($ret_obj[$returnedPostIndex][$results_set][$x]['attachment']['media']));
print_r (', ');
$x++;
}
So using the above code, I get a line of text on my web page which has the column content and then the count of photos that were uploaded for each post on all the events for a user. The problem is that I'm hoping that
$ret_obj[$returnedPostIndex][$results_set][$x][$event_id_name]
will return the event id but I don't seem to get that at all. The result (when looking at the actor_id column) is:
694382034 : 8, 694382034 : 2, 694382034 : 1, 694382034 : 1,
Which shows, correctly, that there are a total of 12 photos posted over 4 posts, but I know that they're spread over 2 events so clearly actor_id isn't the event's id.
Reading this I expected the 'actor_id' to be
The ID of the user, page, group, or event that published the post
I'm assuming that I'm approaching this from completely the wrong direction but am stuck now, so can someone please tell me how to access an individual photograph's associated event id?
So I did eventually approach from a different angle: I just take the eid's of the events and store them then lazy fetch the pictures assigned to those eid's when required.
Related
I am here to have some help from you.
I am making a Unilevel MLM using Codeigniter
and now I can sucessfully add new member
But the problem is I need to distribute the earnings to other level
after a new member is successfully Added
See pic below:
Distribution of earnings
I need to distribute like the image above.
I hope you can help me with this guys.
Okay, I have a solution for you. The process i used is based on my understanding of the question.
So this is it, first i checked for a registration post, if a post request is made, i use the referral id from the post to fetch the number of registrations tied to that referral id that has not been given awarded the 100 earning. If the count of the result of this query is equal to 4, i loop through all of them and give them the earning of 100 and update their paid status to reflect that they have been paid then i insert the record, else i just insert the record.
So too much text, lets see the code
//this is the controller code
//first check for post of registration
if($_POST){
//kindly do your form validation here
$register = array(
"name" => $this->input->post('name'),
"refid" => $this->input->post('refID')
);
//during post, get the referral id from the post
$refID = $this->input->post('refID');
//before registering, use referral id to get the referred that have not been given earnings yet
$thereffered = $this->referral_m->getReferred($refID);
//check for the number of registration
if(count($thereffered) == 4){
//then get their ids and give them their earnings and update them to paid
foreach($thereffered as $referred){
$earnings = array(
"userID" => $referred->id,
"amount" => 100
);
$paid = array(
"paid" => 1
);
//give earning
$this->referral_m->giveEarning($earnings); //this adds the user id to earning table and give it an amount of 100
$this->referral_m->updateUser($paid, $referred->id); //this updates the user with the paid status
}
//then proceed to register the new record
$this->referral_m->register($register);
}else{
//register the new record
$this->referral_m->register($register);
}
//redirect after registration
redirect();
}else{
//load view here
}
This is how the model looks like
function getReferred($refID){
return $this->db->get_where('referral', array("refid" => $refID, "paid" => '0'))->result();
}
function giveEarning($record){
$this->db->insert('earnings', $record);
}
function register($array){
$this->db->insert('referral', $array);
}
function updateUser($array, $id){
$this->db->where('id', $id);
$this->db->update('referral', $array);
}
From the model, you would discover that i created 2 database tables, I assume you already have those tables created, just use the logic to update your code. If you find any difficulty, kindly comment lets sort it out
I am working on a website written in Yii framework (version 1.1.14) that allows uploading and displaying news. The admin of the site can select three news to promote to homepage and specify the order in which they are displayed. I am using Mysql database. The news table has two fields: isChecked (0 or 1) and homepagePos (integer) in addition to the other fields. The isChecked field determines whether the news is selected for displaying in homepage and the homepagePos field determines the order in which the news are displayed. I have used jquery's sortable plugin to sort the news. When the user selects which news to display and clicks save button, the news ids are sent to php via ajax.
The javascript portion to send the values to news controller is as follows:
$(document).on('click', '#saveToHomepage', function()
{
var url = ajaxRequestSendUrl; //ajaxRequestSendUrl contains url to news controller's promote to homepage method.
$.ajax({
method: "GET",
url: url,
data: {
contentIds: contentIds, //contentIds contains an array of news Ids in certain order
},
success: function() {
// Show success message
},
error: function() {
alert('Some error occured. Please reload the page and try again.');
}
});
});
Here's the promote to homepage method in news controller:
public function actionHomepage()
{
$allNews = News::model()->findAll();
$value = $_GET['contentIds'];
foreach ($allNews as $news) {
if($news->id == $value[0] ||$news->id == $value[1] ||$news->id == $value[2])
{
$news->isChecked = 1;
$news->homepagePos = array_search($news->id, $value); //Assign index of the array as the position
$news->save();
}
else
{
$news->isChecked = 0;
$news->homepagePos = -1;
$news->save();
}
}
}
My problem is that the news table I have has over 2k data. So the ajax call takes really long time (over a minute) to complete. Is there any way I can optimize the code or is there other way I can approach this to reduce the time taken to complete this operation?
Thanks in advance
Three queries: One first to set the whole table to not checked status, and the rest to set the checked status only in the row each selected id
public function actionHomepage()
{
$values = $_GET['contentIds'];
$sql = "UPDATE news SET idChecked=0,homepagePos = -1";
Yii::app()->db
->createCommand($sql)
->execute();
for($ii = 0; $ii < 3; $ii++) {
$sql = "UPDATE news SET idChecked = 1,homepagePos = ':homepagePos' WHERE id=:id";
Yii::app()->db
->createCommand($sql)
->bindValues(array(':homepagePos' => array_search($ii, $values), ':id' => $values[$ii]))
->execute();
}
}
i am not sure, but why don't you get the filtered records from the database itself by sending the id's of selected news. I don't know your backend language. Seems, you are getting all the records and applying filtering. which consumes time. Instead get the filtered news from the database.
Hope this helps!
Its taking a long time because you're fetching all the records and then updating those three id. You could try this:
$criteria = new CDbCriteria;
$criteria->addInCondition( "id" , $value ) ; // $value = array ( 1, 2, 3 );
News::model()->updateAll(array('isChecked'=>'1','homepagePos'=>'val2'), $criteria);
You could do an update before hand to reset all the homepagePos and then update only the ids you need.
/* In moodle **/
Like we obtain user id using $USER->id dynamically who is logged in ,how can we obtain the quiz id of which the user is currently playing ? is there any option like $QUIZ->id or something else ?.Please help
In theory, if its been set up correctly, you can get the course module from the $PAGE object.
$cm = $PAGE->cm
Then grab the quiz record from the $cm object
$quiz = $DB->get_record('quiz', array('id' => $cm->instance));
I'm reading wildly different things about tagging photos on Facebook.
One article says you can send tags=array(...tag_uid...) at the same time as you post the photo: Tagging photos on Facebook with Graph API / PHP SDK
One article said you can tag, but first you have to post to photo, and then set tags afterwards. (Can't remember the page)
One article said you can tag, but only one tag per request, so you have to iterate over the array. (Can't remember the page)
One article says you can't tag at all: https://developers.facebook.com/blog/post/371/
Does anyone know if tagging actually possible, and what is the correct way of doing it as of the current date?
You must get Photo ID firs and then tag someone on this photo
upload photo to album
$photo_details = array(
'message' => $message,
'access_token' => $token
);
$photo_details['image'] = '#' . realpath($file);
$uploaded_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
Get Photo ID
$photo_id = $uploaded_photo['id'];
set Friend ID you want to tag
$tags = array(
array('tag_uid' => $friend_id, 'x' => rand() % 100, 'y' => rand() % 100 )
);
tag friend
$facebook->api('/'.$photo_id.'/tags', 'post', array('tags'=>$tags));
It works for me, I hope this will help you
I am new to moodle ,currently i am working on questionnaire module, in which we create questionnaire for courses(created by teacher , which are viewed by student on course detailed page there they will answer ) . now i want to know which user created that questionnaire (i.e userid ). I have been searching for while but didnt found any answer.
If the questionnaire table has a createdby field, then you can use that, otherwise, you'll have to do a search through the logs table like this:
// You'll need to get the right coursemoduleid first from the course_modules table
$cmid = 27;
$conditions = array('module' => 'questionnaire',
'coursemoduleid' => $cmid,
'action' => 'add');
$creationrecord = $DB->get_record('log', $conditions);
$creator = $creationrecord->userid;