Topic-icon How can I make individual activity pages 4 custom open graph actions?

Support Specialist
Make sure the coupon URL is the full url, including yourdomain.com/ . Then, echo out the $urlKey that is created. Look in your database in the #__opengraph_activity database to see if the key is already used for the user_id if of the user you're testing with.

The actionReady() function will take the $urlKey and look up the current user in the database. Then, it will check that the last time that urlKey was used wasn't within the action timelimit period (once per day).

So, if they urlKey isn't being fetched correctly, that would be the problem. The key is usually just the article ID for a K2 item, but it could be something else. It depends on a lot of things.

Hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
Thanks Alex... Will reply back asap!
The topic has been locked.
Support Specialist
Sounds good. I look forward to hearing how it goes!
The topic has been locked.
Active Subscriptions:

None
Hey Alex... Ok so here is where I am now stuck...

You were correct in guessing that my object link ($this->item->link) didn't contain the base part of my url... So I made sure to append it and now I am passing the correct url into the function getUniqueKey().... However, I am still having some issues... Here is how I am currently testing... Maybe something I am doing is incorrect?

1) I have set my custom action called "clip" to be triggered manually and only allowed to be used once.
2) I have 5 published test k2 items (aka. objects / coupons) setup in my test category that is linked to the custom action.
3) To test them... I then use my custom action buttons to "clip" all 5 items... I see the "successfully posted to facebook" popup and they also show up in my activity feed... So they have defiantly all been "used" / expired....
4) I then reload the page, expecting my code (below) to alert and/or display red divs in place of the used items... but it never does :-/

I added an echo in the code to print the $urlKey like you said... and every time... it echos 5 urlkeys (one for each item)... I then check the database... and YES... I can see a record for all five of my keys next to my user_id

SO CLOSE... YET SO FAR AWAY!!! :)

thanks for helping...

HERE IS THE CURRENT CODE I AM USING:
//JFB Connect Action Check Code
$couponUrl = 'http://www.mysite.com' . $this->item->link;
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_jfbconnect/models'); 
$jfbcOgActionModel = JModelLegacy::getInstance('OpenGraphAction', 'JFBConnectModel'); 
$urlKey = $jfbcOgActionModel->getUniqueKey($couponUrl); // The URL of the object page 
$action = $jfbcOgActionModel->getAction('1'); // ID of the action you want to check 

	// Check to see if the user has disabled the action (if the action is configured to be disable-able) and check if it hasn't been triggered within the timeframe settings 
	if ($action->enabledForUser()) {
	     $isReady = true; 
	     
	} else {
	 
	     $isReady = false;
	     
	}
     
     if($isReady == false){ ?>
     
     alert("Item Already Used");
    // ITEM USED DIV HERE IN RED
	     
    
     if($isReady == true){
     
     echo($urlKey);
     // MY NORMAL ITEMS HERE

Oh... and 5.0 is working well thanks!
The topic has been locked.
Support Specialist
Ryan,
Sorry for the delay in getting back to this. First off, I'm glad to hear that 5.0 is going well for you.

As for getting the action to work, you removed the double-check that I originally posted. Remember above that I checked for if ($action->actionReady($urlKey) && $action->enabledForUser()) . You're only checking for "enabledForUser()", which unless you're specifically disabling that action, it's always going to come back as 'ready'.

The actionReady($urlKey) function is what checks when the action was last triggered and whether it's available to be triggered again. Without that, you're not really checking anything based on the last time the action was triggered.

So, add that back in there now that you are using the full URL and see if that helps get things going.

Keep me posted, and good luck,
Alex
The topic has been locked.
Active Subscriptions:

None
Hey Alex... Thanks for the reply... Sorry... Yeah that makes alot of sense... duh! LOL

However... I added the other check back in and I am getting the same result :-/

My code looks like this:
if ($action->actionReady($urlKey) && $action->enabledForUser()) {
	     $isReady = true; 
	} else {
	     $isReady = false;    
	}
     
     if($isReady == false){ ?>
          alert("Item Already Used");
          RED ITEM USED
    
     
     if($isReady == true){
     
     echo($urlKey);   //this prints if true... which it always is... so I get 5 of them back each time
Each time... My code prints the 5 url keys... :-/

THANK YOU AGAIN :)
The topic has been locked.
Active Subscriptions:

None
Just an FYI I tested the same code in another view (my custom component's view) and am getting the same thing :-/

Here is a pic of my custom component's view... You can see I echo out the k2 item id AND the urlKey (they match like you said) for each item.... Along with the k2 item link and title.

However... When I test using the conditionals (same as above)... None come back expired :-/

File Attachment:
The topic has been locked.
Active Subscriptions:

None
Hey Alex,

I am going to be working on this a bit tonight... I was just curious if you, by any chance, had any new info? Sorry... I know you're busy with all sorts of stuff... Not trying to push but I did once hear that the squeaky wheel gets the oil :)

SO CLOSE... YET SO FAR!!!

Ryan
The topic has been locked.
Support Specialist
Ryan,
You're going to have to go into the /components/com_jfbconnect/models/opengraphaction.php and find the actionReady function. Around 293, you should see:
$query = "SELECT COUNT(*) FROM #__opengraph_activity WHERE
            `action_id` = " . $this->id . " AND
            `user_id` = " . $userId . " AND
            `unique_key` = " . $this->db->quote($uniqueKey) . " AND
            `status` = 1 AND
                (`created` > (NOW() - " . $duration . ") OR " . $this->params->get('og_unique_action') . ")";
        $this->db->setQuery($query);
Print out that $query statement to see what JFBConnect is actually checking. Then, you'll have to do a little debug in the #__opengraph_activity table to see why something isn't being reported. Basically, that query should come back with a non-zero number if the action is *not* ready. The number will be how many times the action has been triggered in the 'interval' period you set. With a 1-time action, which you said you've set, the return value should always be 1 if it's already been triggered.

So, poke through that query and see where something is 'off' and you should have your answer. If not, post the query for one of the coupons that has been 'clipped'. I won't know what's in your database, but I can at least tell you if the query looks right.

Hope that helps, and good luck!
Alex
The topic has been locked.
Active Subscriptions:

None
Hmmmm... So I just did a print_r on the action in my view and there are some SQL errors reported in the object... I am going the personal message them to you as they might contain some sensitive info?! But maybe they make more sense to you?
	$action = $jfbcOgActionModel->getAction('1'); // ID of the action you want to check 
       print_r($action);

RESULTS SENT IN PM
The topic has been locked.