I have a form in .module file. In the form submit button I am embedding my view using views_embed_view function. I want to pass multiple arguments to the view.
Here is my code
print views_embed_view('testing_signup_info', 'default', '1,2,3');
The above code works fine and three arguments are passed to the view but i want to get sid from signup_log table and pass them as the arguments to the view.
Here is my code.
$result = db_query("SELECT sid from signup_log");
$rows = array();
while($row = db_fetch_array($result)) {
$r = $row['sid'];
$rows[$r] = $row['sid'];
drupal_set_message($r);
}
drupal_set_message(views_embed_view('testing_signup_info', 'default', '"' . $rows .'"'));
but here my view does not display.
I need help if someone know the solution.
How to pass sids retrieving from the table and pass as arguments to the view???
The snippet you included appears to pass in an array. Based on my understanding from this comment by merlinofchaos (the author of Views), it doesn't look like Views expects an array to be passed in. Try the following instead:
$result = db_query("SELECT sid from signup_log");
$rows = array();
while($row = db_fetch_array($result)) {
$r = $row['sid'];
$rows[$r] = $row['sid'];
drupal_set_message($r);
}
$rows_string = implode("+", $rows);
drupal_set_message(views_embed_view('testing_signup_info', 'default', $rows));
Related
I am receiving a JSON object from the backend now I just want "result" array only in my template variable in my angular application from it.
{
"result":[
{"name":"Sunil Sahu",
"mobile":"1234567890",
"email":"abc#gmail.com",
"location":"Mumbai",
"Age":"19"
}
],
"status":200
}
Try with
variable_name["result"].
Try with
var data = response from the backend
var result = data.result;
$var = '{"result":[{"name":"Sunil Sahu","mobile":"1234567890","email":"abc#gmail.com","location":"Mumbai","Age":"19"}],"stats":200}';
If your $var is string, you need to turn it to "array" or "object" by json_decode() function
object:
$var_object = json_decode($var); //this will get an object
$result = $var_object->result; //$result is what you want to get
array:
$var_array = json_decode($var, true); //this will get an array
$result = $var_array['result']; //$result is what you want to get
Else if $var is object, direct use
$result = $var->result; //$result is what you want to get
As result is an array of objects, you can either use any loop to extract key value pair or you can directly access the array using index value.
var results = data["result"] // this would return an array
angular.forEach(results, function(value, key) {
//access key value pair
});
For accessing results in HTML, ng-repeat directive can be used.
Your question didn't explain further, but in the simple way try this :
const stringJson = `{
"result":[
{"name":"Sunil Sahu",
"mobile":"1234567890",
"email":"abc#gmail.com",
"location":"Mumbai",
"Age":"19"
}
],
"status":200
}`
const obJson = JSON.parse(stringJson);
console.log(obJson.result);
I have a custom list that is used as a matrix option of Inventory item. Its 'Color'. This custom list has an abbreviation column. I am creating a saved search on item and using Color field(join) and trying to access 'Abbreviation' field of color.
Abbreviation on custom list is available on when 'Matrix Option List' is checked.
Can someone please help me achieve this? I tried to do this through script and it seems like we cannot access 'Abbreviation' column through script. I also tried to use script to write a search directly on 'Color' - custom list and get the 'abbreviation' through search columns. It did not work. Is there a way to access 'Abbreviation' from custom lists?
Thanks in Advance
You can access it via suitescript by using the record type "customlist" and the internal id of the list like so:
var rec = nlapiLoadRecord('customlist', 5);
var abbreviation = rec.getLineItemValue('customvalue', 'abbreviation', 1);
nlapiLogExecution('DEBUG', 'abbreviation', abbreviation);
Keep in mind that the third argument of getLineItemValue is the line number, not the internal ID of the item in the list. If you want to find a specifc line item, you may want to use rec.findLineItemValue(group, fldnam, value).
Unfortunately, it doesn't look like this translates to saved searches. The suiteanswer at https://netsuite.custhelp.com/app/answers/detail/a_id/10653 has the following code:
var col = new Array();
col[0] = new nlobjSearchColumn('name');
col[1] = new nlobjSearchColumn('internalid');
var results = nlapiSearchRecord('customlist25', null, null, col);
for ( var i = 0; results != null && i < results.length; i++ )
{
var res = results[i];
var listValue = (res.getValue('name'));
var listID = (res.getValue('internalid'));
nlapiLogExecution('DEBUG', (listValue + ", " + listID));
}
However, whatever part of the application layer translates this into a query doesn't handle the abbreviation field. One thing to keep in mind is that the 'custom list' record is basically a header record, and each individual entry is it's own record that ties to it. You can see some of the underlying structure here, but the takeaway is that you'd need some way to drill-down into the list entries, and the saved search interface doesn't really support it.
I could be wrong, but I don't think there's any way to get it to execute in a saved search as-is. I thought the first part of my answer might help you find a workaround though.
Here is a NetSuite SuiteScript 2.0 search I use to find the internalId for a given abbreviation in a custom list.
/**
* look up the internal id value for an abbreviation in a custom list
* #param string custom_list_name
* #param string abbreviation
* #return int
* */
function lookupNetsuiteCustomListInternalId( custom_list_name, abbreviation ){
var internal_id = -1;
var custom_list_search = search.create({
type: custom_list_name,
columns: [ { name:'internalId' }, { name:'abbreviation' } ]
});
var filters = [];
filters.push(
search.createFilter({
name: 'formulatext',
formula: "{abbreviation}",
operator: search.Operator.IS,
values: abbreviation
})
);
custom_list_search.filters = filters;
var result_set = custom_list_search.run();
var results = result_set.getRange( { start:0, end:1 } );
for( var i in results ){
log.debug( 'found custom list record', results[i] );
internal_id = results[i].getValue( { name:'internalId' } );
}
return internal_id;
}
Currently NetSuite does not allows using join on matrix option field. But as you mentioned, you can use an extra search to get the result, you could first fetch color id from item and then use search.lookupFields as follows
search.lookupFields({ type: MATRIX_COLOR_LIST_ID, id: COLOR_ID, columns: ['abbreviation'] });
Note: Once you have internalid of the color its better to use search.lookupFields rather than creating a new search with search.create.
i have an array that am calling from the database using kohana 3.3 i have gotten the data to the view and i can get it with print_r($variable). i want to create a movenext, movefirst,moveprevious and movelast buttons based on the data that is in the array.
my model looks like this
public function get_customer_list(){
$cust_list= DB::select('*')->from('customers')
->order_by('id','ASC')
->execute()
->as_array();
//print_r($cust_list);
return $cust_list;
my controller looks like this
$id=#$_POST["id"];
//echo $id;
$amend = Model::factory('amendments')->get_customer_list(#$d);
$this->page_title = 'amending';
$this->content = View::factory('forms/amendment_next');
//$this->rightwidget =view::factory('rightwidget');
$this->amend = $amend;
$this->next = $id;
my view looks like this
foreach ($amend[0] as $key=>$value){
echo '<p><span>'.$key.'</span><input id="'.$next.'" class="contact" type="text" name="'.$key.'"value="'.$value.'" /></p>';
}
Next Record
Previous Record<button >Next Record</button><button>Last Record</button>
i dont mind using a link or a button
please assist am stack here and my brain is locked.
Try this in your view, just a some javascript code is needed (i have used jQuery)
---next() Example---
$(document).ready(function (){
var customers = <?php echo json_encode($amend) ?>;
var count = 0;
function nextItem(){
if(count >= customers.length )return;
console.log("customer:",customers[count]['id'],customers[count]['name']);
count =++count;
}
})
Your controller should look like this:
$id=#$_POST["id"];
//echo $id;
$amend = Model::factory('amendments')->get_customer_list(#$d);
$this->page_title = 'amending';
$inputArray = array('amend'=>$amend, 'id'=>$id);
$this->content = View::factory('forms/amendment_next',$inputArray);
//$this->rightwidget =view::factory('rightwidget');
You either have to pass the variables you want to use in your view directly to the factory as an associative array or you have to make them globally availible to the factory.
Your view should look like this:
<?
foreach ($amend[0] as $key=>$value){
echo '<p><span>'.$key.'</span><input id="'.$next.'" class="contact" type="text" name="'.$key.'"value="'.$value.'" /></p>';
}
?>
Next Record
Previous Record<button >Next Record</button><button>Last Record</button>
after passing the $inputArray to the factory the vairable $amend will be filled with $inputArray['amend'] and $id will be filled with $inputArray['id']
I used your example to project myself over the problem. and now it stands solved here is the
The Controller looks like this now
$id=#$_GET["id"];
$amend = Model::factory('amendments')->get_customer_list(#$d);
$this->page_title = 'I&M CRB Online App amending';
$this->content = View::factory('forms/amendments');
//$this->rightwidget =view::factory('rightwidget');
$this->amend = $amend;
$this->next = $id;
the view looks something like this
<?php
if (!$next){
$next = "0";}
$nextid = $next+"1";
$previd=$next-"1";
?>
First Record |
Previous Record |
move next |
Last Record
<?php
foreach (#$amend[#$next] as $key=>$value){
echo "<p><span>".$key."</span><input class='contact' type='text' name='".$key."'value='".$value."' /></p>";
}
?>
and for the last record i had to use a different model function
public function get_last_customer(){
$last_customer= DB::select()->from('customers')
->order_by('id','DESC')
->limit(1)
->execute()
->as_array();
return $last_customer;
Thank you all for the support and the answers you provided me with.
How does $_GET Variable works with Concrete5? Can I use that on regular page?
I know I can do this with single page via url segment, I'm just wondering if it is possible with regular page.
Example is :http://www.domain_name.com/about-us/?name=test...
Get-parameters are available via the controllers. In the view of a page or block use:
$this->controller->get("parameterName");
A cleaner way for custom parameters would be to define them in the function view() of the page controller. If at http://www.domain_name.com/about-us is your page and you define the view function of it's pagetype controller like this:
function view($name) {
$this->set("name", $name);
}
... and call the URL http://www.domain_name.com/about-us/test – then "test" will be passed under $name to your page view.
Note that controllers for page types must be in controllers/page_types/ and called BlablaPageTypeController ... with "PageType" literally being in there.
You can use it in a template. For instance, you can grab a variable...
$sort_by = $_GET['sort'];
And then use that variable in a PageList lookup, similar to:
$pl = new PageList();
$ctHandle = "teaching";
// Available Filters
$pl->filterByCollectionTypeHandle($ctHandle); //Filters by page type handles.
// Sorting Options
if ($sort_by == "name") {
$pl->sortByName();
} else {
$pl->sortBy('teaching_date', 'desc'); // Order by a page attribute
}
// Get the page List Results
$pages = $pl->getPage(); //Get all pages that match filter/sort criteria.
$pages = $pl->get($itemsToGet = 100, $offset = 0);
Then you can iterate over that array to print stuff out...eg
if ($pages) {
foreach ($pages as $page){
echo ''.$page->getCollectionName() . '<br />';
}
}
Props to the C5 Cheatsheet for the PageList code.
In drupal6 using views I want a (block) list of authors (with complete profile fields) of some specific node type AND taxonomy term.id OR vocabulary.id
Summarized query:
Views: type user
Argument: Term ID/Vocabulary ID
Filters: Author of Node type abc
Fields: All Profile/Content Profile Fields
How can I achieve such solution?
I have the same issue. I found that if I filtered by node.type = 'blog' and set fields for the profile fields I was interested in, I could get a list or authors, but there would be duplicates. Setting 'Distinct' to Yes didn't help because it was selecting out distinct nodes, not distinct users.
So I ended up creating a custom block to show this information with some code like this:
<?php
$block['subject'] = t('Bloggers');
// Get a list of blog authors
$result = db_query('SELECT DISTINCT u.uid, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = \'blog\'');
$links = array();
while ($blogger = db_fetch_object($result)) {
$link = array();
if (module_exists('profile')) {
profile_load_profile($blogger);
}
if (!empty($blogger->profile_first_name) || !empty($blogger->profile_last_name)) {
$link['title'] = $blogger->profile_first_name . (empty($blogger->profile_first_name) ? '' : ' ') . $blogger->profile_last_name;
}
else {
$link['title'] = $blogger->name;
}
$link['href'] = 'blog/' . $blogger->uid;
$links[] = $link;
}
$block['content'] = theme('links', $links, array('class' => 'flat-links'));
?>
Hope that helps.