Different FQL results - facebook

If I run this query with the php sdk:
$fql ="http://graph.facebook.com/fql?q=SELECT+id,+text,time,+fromid+FROM+comment+WHERE+post_fbid+=+414571855318181+AND+is_private+=+0+AND+object_id+IN+%28SELECT+comments_fbid+FROM+link_stat+WHERE+url+=+%22http://griekenland.net/actie-pagina/%22%29";
$fql_query_result = file_get_contents($fql);
$fql_query_obj = json_decode($fql_query_result, true);
I get this response, which I think is wrong. Because it should filter on is_private and the comment hasn't been approved yet, so I don't see why it should return it.
Array
(
[data] => Array
(
[0] => Array
(
[id] => 394048867370480_2458709
[text] => Kefalonia vind ik zo overweldigend mooi en afwisselend......speechless :O
[time] => 1375532512
[fromid] => removed
)
)
)
Now when I enter the same query directly in the browser http://graph.facebook.com/fql?q=SELECT+id,+text,time,+fromid+FROM+comment+WHERE+post_fbid+=+414571855318181+AND+is_private+=+0+AND+object_id+IN+%28SELECT+comments_fbid+FROM+link_stat+WHERE+url+=+%22http://griekenland.net/actie-pagina/%22%29 then it shows the expected response, which is nothing.
How can there be a difference like this? I mean it's either private or not? And I'm pretty sure the FQL call through php used to give the correct response until somewhere last week. If anyone knows what could possible cause this difference I would like to know :)

Have you tried using can_like instead? That should give you an idea of whether it's approved or not.

Related

Drupal 8/9 module no refresh form data after post

I have a D8 module that works well. But I have a problem.
Sensors data are stored in a database. In the D8 website, the cache is disabled, but the selected data are not updated. If I use the "drush cr" then ok, but the next selected data are not updated.
What may be the problem?
The code shortly:
#
# form for SQL SELECT
#
function buildForm()
//...
$form['date_from'] = [ '#type' => 'datetime', ... ];
$form['date_to'] = ...
$form['#cache'] = ['max-age' => 0];
/// ...
So, I select a date_from and date_to and post it then it is ok. I go back and change the date_from, date_to and post it then it still stay the previous date!
After "drush cr" it works once again... and so on
It has no effect (settings.php): $settings['rebuild_access'] = TRUE;
Thanks,
G.
I found it: How to clear cache programmatically in Drupal 8?
Both work. :)
in function buildForm():
drupal_flush_all_caches();
// or
\Drupal::service("router.builder")->rebuild();

PHP preg_replace not working as expected

I'm trying to run a find replace of multiple values to do a mail merge effect on an HTML signature stored in the database.
I can get the string part replaced no worries, but for some reason it's leaving the "[" & "]" behind in the output.
Merge tags in the HTML would look like this: [FirstName], [LastName]
Original HTML would look like this:
Kind regards
[FirstName] [LastName]
After running the mailmerge function it should look like this:
Kind regards
John Smith
Here is what I've come up with so far, and Im sure the issue is something small:
public function merge_user_signature() {
$user = $this->get_user_by_id();
//spit_out($user);
$authorisedMergeTags = array (
"[FirstName]" => $user->firstName,
"[LastName]" => $user->lastName
);
$keys = array_keys($authorisedMergeTags);
$values = array_values($authorisedMergeTags);
$html = $this->get_user_signature();
$mergedSignature = preg_replace($keys, array_values($authorisedMergeTags), $html);
return $mergedSignature;
}
Thanks in advance
You don't need to use a regex to deal with literal strings (whatever the situation):
return strtr($html, $authorisedMergeTags);

Yii2-mongodb: how to add database fetched items in dropdown list

I am trying to add the team names(to be fetched from mongoDB) in the form to let user select the form name.
I am not getting how to add the database fetched form names in the dropdown list.
It should search based on organization_id first & then form_name.
what i am doing is this:
<?= $form->field($model1, 'form_name')->dropDownList(ArrayHelper::map(CreateTeam::find(array('organization_id' => Yii::$app->session['organization_id']))->all(), 'form_name')); ?>
It is showing me an error that missing the third argument. What could be the third argument in that case???
I went through issue with fetching record from country collection to serve record in state form
I got solution as below (considering as my state form)
use app\models\Countries;
use yii\helpers\ArrayHelper;
$countries=Countries::find()->all();
$listData=ArrayHelper::map(Countries::find()->all(),function ($model){return (string)$model->_id;},'name');
echo $form->field($model, 'countries_id')->dropDownList($listData, ['prompt'=>'Select...']);
Hope I was able to let you understand !
$collection2 = Yii::$app->mongodb->getCollection('teamdashboard');
$models = $collection2->find(array('organization_id' => Yii::$app- >session['organization_id']));
$items = ArrayHelper::getColumn($models, 'team_name');
return $this->render('teamdashboard', ['model1' => $model1, 'model2' => $model2, 'items' => $items]);
This one works fine for mongodb...
Yes, in ArrayHelper::map() first three parameters are required, so you are definitely calling this method wrong.
Check out official documentation for map().
The second parameter represents the actual values in database (usually they are primary keys), the third - readable text.
Assuming your primary key is id it should be:
$models = CreateTeam::find([
'organization_id' => Yii::$app->session['organization_id'],
])->all();
$items = ArrayHelper::map($models, 'id', 'form_name');
<?= $form->field($model1, 'form_name')->dropDownList($items) ?>

How to avoid affecting other queries when using posts_orderby?

In WordPress as you must already known, when using get_posts() or query_posts() or even WP_Query, it is not possible to order the returned posts by specifying a list of post ID in the order we want.
Instead we have to loop through the results and re-order them on the PHP side. This is a performance hit and a bad practice. Instead we should use built-in MySQL functions to retrieve the posts in the desired order upfront.
Thankfully there is the posts_orderby which can be used to specify a custom ORDERBY statement, like this:
// My list of post IDs in my custom order
$my_post_ids = array(1,3,2);
// Apply filter to the ORDERBY SQL statement
add_filter('posts_orderby', 'my_custom_orderby');
function my_custom_orderby($orderby_statement) {
global $my_post_ids;
$orderby_statement = 'FIELD(ID, '.implode(',',$my_post_ids).')';
return $orderby_statement;
}
// My custom query
$my_custom_query = new WP_Query(array('post_type' => 'post', 'post__in' => $my_post_ids);
However there is a problem with the above code, is that it will affect the order of all queries on the page! Including queries made by plugins, shortcodes, and so on.
Easy fix!
The simple way to fix this, is to apply the filter only one time, and remove it as soon as it is called, by putting a remove_filter() within the filter itself, so it is run only once:
// My list of post IDs in my custom order
$my_post_ids = array(1,3,2);
// Apply filter to the ORDERBY SQL statement
add_filter('posts_orderby', 'my_custom_orderby');
function my_custom_orderby($orderby_statement) {
// Disable this filter for future queries!
remove_filter(current_filter(), __FUNCTION__);
global $my_post_ids;
$orderby_statement = 'FIELD(ID, '.implode(',',$my_post_ids).')';
return $orderby_statement;
}
// My custom query
$my_custom_query = new WP_Query(array('post_type' => 'post', 'post__in' => $my_post_ids);
Because I set this filter just before my custom query, once I execute my custom query it should be filtered by the posts_orderby filter set above, which is then immediately disabled so it won't affect any future queries.
In theory, that's great, and it works great in most case scenarios!
An issue with WPML
However I have encountered a case when using the WPML plugin where this filter affects other queries than mine and causes errors. I believe the WPML plugin is creating a query of its own that is executed just before my own custom query, making my filter applies to the WPML query instead of mine!
Is there any possible way to add a check within the filter to make sure that it affects the correct query?
Thank you very much
Edit:
The fix for WPML
For information, while the accepted answer for this question is correct, it didn't solve the problem I was having with WPML. Here is how I fixed the WPML conflict:
// My list of post IDs in my custom order
$my_post_ids = array(1,3,2);
// Apply filter to the ORDERBY SQL statement
add_filter('posts_orderby', 'my_custom_orderby');
function my_custom_orderby($orderby_statement) {
// Disable this filter for future queries!
remove_filter(current_filter(), __FUNCTION__);
global $my_post_ids, $wpdb;
$orderby_statement = 'FIELD('.$wpdb->base_prefix.'posts.ID, '.implode(',',$my_post_ids).')';
return $orderby_statement;
}
// My custom query
$my_custom_query = new WP_Query(array('post_type' => 'post', 'post__in' => $my_post_ids);
This filter takes two parameters, $orderby and &$this. "this" being the WP_Query object. I'm not sure how to detect that WPML is making the call, but we can check that your call is the one being
made.
$my_post_ids = array(1,3,2);
add_filter( 'posts_orderby', 'my_custom_orderby', 10, 2 );
function my_custom_orderby( $orderby_statement, $object )
{
global $my_post_ids;
if( $my_post_ids != $object->query['post__in'] )
return $orderby_statement;
// Disable this filter for future queries!
remove_filter( current_filter(), __FUNCTION__ );
$orderby_statement = 'FIELD(ID, ' . implode( ',', $my_post_ids ) . ')';
return $orderby_statement;
}

Zend_Db magic method specific cell selection

Currently I'm working on a couple of model related improvements and looking into a specific query I've wrote.
$queryGetPages = $this->fetchAll($this->select()
->where('page_active = ?', (int) $active)
->order('page_rank ASC'));
if($queryGetPages) {
$queryGetPages = $queryGetPages->toArray();
foreach($queryGetPages as $key => $value) {
$queryGetPagePrint = $this->find($value['pageid'])
->current()
->findModule_Model_ModulePagesPrintsViaModule_Model_ModulePagesFuses(
$this->select()
->from('module_pages_prints', array('print_title'))
->where('fuse_locale = ?', $this->_toolbox['editor']['translation']) )
}
}
The problem is in the magic method which is requesting data from a related table. I only need the 'title' cell per row, but for some reason it wont let me. Even with this query, it returns all cells from the row. I'm doing something wrong, but have no idea what!
If someone can point me to the right direction, I would be very thankfull.
Best regards !
The function that is implicitly called in your case is findManyToManyRowset() (code available in Zend/Db/Table/Row/Abstract.php, lines 1001-1108 (as of ZF 1.12.1). Have a look at lines 1070-1072:
$select->from(array('i' => $interName), array(), $interSchema)
->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
->setIntegrityCheck(false);
In short: the function that is called will overwrite your from() call and select all rows from the dependent table (module_pages_fuses). This is the way it's designed to work.
Instead, I would recommend writing the query you actually need the "dumb" way, e.g.
$queryGetPagePrint = $this->select()
->from(array('p' => 'module_pages_prints'), array('print_title'))
->join(array('f' => 'module_pages_fuses'),'p.pageid = f.pageid',array())
->where('f.fuse_locale = ?', $this->_toolbox['editor']['translation'])
->where('p.pageid = ?', $value['pageid']);