I have a table *sitepage_manageadmins* which contain: " user_id, page_id ".
There is another table *sitepage_pages* which contain " page_id, title ".
Im trying to render as dropdown ( select list ) in Zend_Form the user which is admin to relevant page_id .
Here is my code:
$this->view->owner_id = $viewer_id = $viewer->getIdentity(); // get $viewer
$adminpages = Engine_Api::_()->getDbtable('manageadmins', 'sitepage')->getManageAdminPages($viewer_id); // get viewer page_id's where is admin
Getting the page_id as dropdown list:
$ids = array ( 0 => '-- Select --');
foreach ($adminpages as $adminpage) {
$ids[] = $adminpage->page_id;
}
Rendering the dropdown
$this->addElement('select', 'page_id', array (
'label' => 'Page where I'm Admin',
'multioptions' => $ids,
));
For now, im only render the Page_ID numbers as dropdown. I want from Specific Page_ID to render the Title.
Any ideas are welcome?
Thanks
This is because you are putting only the ids to the $ids[] array The multioption array should be key-value pair in this case page_id as key & page_title as value.
foreach ($adminpages as $adminpage) {
$ids[$adminpage->page_id] = $adminpage->page_title;
}
Related
I am trying to select a record with the mimetype field with a non-null value,
$file = $DB->get_record('table', array('itemid' => $id_imagen, 'component' => 'user', 'mimetype' => 'is not null'));
Is there any way to get this using get_record?
I answer my own question in case this can help someone
No, it is no possible to use IS NOT NULL or others with get_record function. You can acomplish it using function get_record_sql like this:
$file = $DB->get_record_sql("SELECT * FROM table WHERE itemid = " . $id_imagen . " AND component = 'user' AND mimetype IS NOT NULL");
This is My Code
$ids = join(", ",$man);
if ( !isset($_SESSION[$appID.'_FQLResult']) ) {
$FQLQuery = "SELECT uid, sex, pic_square FROM user WHERE uid in ($ids)";
$FQLResult = $facebook->api(array( 'method' => 'fql.query', 'query' => $FQLQuery, 'access_token'=>$fbme['access_token'] ));
$_SESSION[$appID.'_FQLResult'] = $FQLResult;
} else {
$FQLResult = $_SESSION[$appID.'_FQLResult'];
}
echo $ids;
echo $FQLResult;
There is an error
when i echo $ids it shows the value of $ids but when i echo $FQLResult is shows only "array" written whats wrong in this fql query?
how i can fix this?
I think there is something wrong in this query
$FQLQuery = "SELECT uid, sex, pic_square FROM user WHERE uid in ($ids)";
Use implode() directly instead of join()
After a successful API call, you should be expecting an array, so use print_r($FQLResult);
Always, if you are not sure of the type of the variable use var_dump()
You may want to use the new Graph API end-point (/fql?q=YOUR_QUERY), read here
Serialize your array before adding to sessions
Watch our of the session size limits!
I have a task form for an application I am building which allows me to specify what contact it is assigned to. I had set up a dependent dropdown in Yii with the following code:
echo $form->dropDownList($model,'associationType',
array('none'=>'None','contact'=>'Contact','sale'=>'Sale','account'=>'Account',
'project'=>'Project','case'=>'Case'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('tasks/parseType'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#auto_complete', //selector to update
)
));
What I'm trying to do is use the CJuiAutoComplete widget with the dropDown specifying which array to grab. So the drop down is selected to contacts, it should get a list of contacts etc.
Here is what I have for the CJui widget
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'auto_select',
'source' => $names,
'options'=>array(
'minLength'=>'2',
'select'=>'js:function( event, ui ) {
$("#'.CHtml::activeId($model,'associationId').'").val(ui.item.id);
return false;
}',
),
));
The variable $names is just a placeholder for now, but in my controller method I pass it a JSON encoded array with id and name. Controller code:
public function actionParseType() {
//if(isset($_POST['TaskChild']['associationType'])){
//$type=$_POST['TaskChild']['associationType'];
$type='sale';
$sql = 'SELECT id, name FROM x2_'.$type.'s';
$cmd = Yii::app()->db->createCommand($sql);
$res = $cmd->queryAll();
echo CJSON::encode($res);
//}
}
Right now I'm forcing it to use "Sale" but I don't get anything when I call the method, and was wondering how I might go about fixing this. I'm still a little new to Yii so I've been mostly reading wiki/forum posts on how these kinds of thing are done. Any help is greatly appreciated, thanks!
Try something like this in your controller action:
$sql = 'SELECT people_id as id, CONCAT(first_name," ",last_name) as value, first_name as label FROM people WHERE first_name LIKE :qterm ORDER BY first_name ASC';
$command = Yii::app()->db->createCommand($sql);
$qterm = $_GET['term'].'%';
$command->bindParam(":qterm", $qterm, PDO::PARAM_STR);
$result = $command->queryAll();
echo CJSON::encode($result); exit;
Then you can check it by using this in your widget 'options' array: 'select'=>'js:function(event, ui) { console.log(ui.item.id +":"+ui.item.value); }'
I'm trying to figure out how to find how many of my friends like a particular entity.
For example, for a given book or movie, how can I look up how many of my friends have already liked the same book or movie.
I believe that information does appear when we display the fb:like button social plugin but I want to get that count so I can programatically display the most popular books among my friends etc is descending order.
My backend is php but I'm also using Javascript SDK.
Thanks for your inputs in advance
These "objects" are actually pages, so to retrieve your friends list that like a movie or a book (a page), use this query:
SELECT uid FROM page_fan WHERE page_id = 91290503700 AND uid IN (SELECT uid2 FROM friend WHERE uid1=me())
Try this in the console of fql.query, it will retrieve all your friends ID that likes the Inception movie.
EDIT:
The obvious way to retrieve the movies (for example) that your friends like would be:
SELECT page_id,uid
FROM page_fan
WHERE type="MOVIE"
AND uid IN (
SELECT uid2
FROM friend
WHERE uid1=me()
)
But I've noticed that it won't return all the users if the set is large (which most likely the case for every user)..so I've made a hack just to get you started!
function sectionArray($array, $step) {
$sectioned = array();
$k = 0;
for ( $i=0;$i < count($array); $i++ ) {
if ( !($i % $step) ) {
$k++;
}
$sectioned[$k][] = $array[$i];
}
return $sectioned;
}
$result = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT page_id FROM page_fan WHERE type='MOVIE' AND uid IN (SELECT uid2 FROM friend WHERE uid1=me())"
));
$pages = array();
foreach($result as $k=>$v) {
$pages[] = $v["page_id"];
}
$pages = array_unique($pages);
$pages = array_values($pages);
$sets = sectionArray($pages,10);
$movies = array();
foreach($sets as $set) {
$page_set = implode(',',$set);
$friends = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT page_id,uid FROM page_fan WHERE page_id IN ($page_set) AND uid IN (SELECT uid2 FROM friend WHERE uid1=me())"
));
$movies[] = $friends;
}
$final = array();
foreach($movies as $v)
foreach($v as $k=>$arr)
$final[$arr["page_id"]][] = $arr["uid"];
print_r($final);
This code is doing the following:
Get all the MOVIEs ids that your friends like
Remove the repeated results and divide the resultant array to a set of arrays (10 movies each)
Query Facebook again to get the friends for each set (10 movies at a time) which would hopefully get you the full list of friends
sort by movie id
And the result would be something like:
Array
(
[movie_id] => Array
(
[0] => friend_id
[1] => friend_id
[2] => friend_id
[3] => friend_id
)
[movie_id] => Array
(
[0] => friend_id
[1] => friend_id
[2] => friend_id
[3] => friend_id
[4] => friend_id
[5] => friend_id
[6] => friend_id
[7] => friend_id
)
[movie_id] => Array
(
[0] => friend_id
)
[movie_id] => Array
(
[0] => friend_id
)
)
From here, you can check for the most liked...etc
P.S.: As I said the above just to get you started and I guess you can cache some queries and improve the performance.
I cannot figure out what is wrong with this fql.multiquery and cannot seem to find any examples of the new sdk with fql.multiquery.
Ultimately I want to get the page name and page id(s) of the visiting user pages which they both administrator and are fans of.
$queries = '{
"page_admin_ids" :
"SELECT page_id FROM page_admin WHERE uid = ' . $afid . ' LIMIT 5",
"page_fan_ids" :
"SELECT page_id FROM page_fan WHERE page_id IN (SELECT page_id FROM #page_admin_ids)",
"page_name_and_id" :
"SELECT name, page_id FROM page WHERE page_id IN (SELECT page_id FROM #page_fan_ids)"
}';
$attachment = array("method"=>"fql.multiquery","query"=>$queries,'access_token'=>$access_token);
$ret_code = $facebook->api($attachment);
print_r($ret_code); die();
$multiQuery = array(
'likes' =>
' SELECT ... FROM like ...',
'users' =>
' SELECT uid, name ' .
' FROM user ' .
' WHERE uid IN (SELECT user_id FROM #likes) ',
);
$multiQueryResult = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $multiQuery
));
I think you should replace "query" parameter in $attachment with "queries".