Evernote API show all note in a notebook - php

I'm trying to get all of the notes from a particular evernote notebook. I am able to display all of the data as an array, and I'm trying to use a foreach loop to get the title. I also want to be able to get the content, date, etc.
$filter = new NoteFilter();
$filter->notebookGuid = $notebookGuid;
$notelist = $client->getNoteStore()->findNotes($authToken, $filter, 0, 100);
foreach($notelist as $value) {
echo $value->title;
}
I know that I'm being really stupid, but I'm new to php and evernote. Any help is appreciated!

The return value of NoteStore.findNotes is NoteList which is not a collection. You have to get notes attribute from NoteList and then iterate it.
By the way, findNotes is now deprecated so please use findNotesMetadata.

You might want to check the following example from evernote:
https://github.com/evernote/evernote-sdk-php/blob/master/sample/client/EDAMTest.php

Related

how to use scroll in foselasticabundle?

I would like to know how can i set scroll in foselasticabundle? I have this code
$res = $this->commentIndex->createSearch($query, ['scroll' => '1m']);
$res->addType('reading');
$res->scroll();
I know Im already close getting the result of my query. Can you help me which of the function in foselasticabundle I can use to display the results of my query. Im trying deep study the code of foselasticabundle.
I found the answer of the issue in this link
I have this code the same in the link
$search = $this->commentIndex->createSearch();
$search->addType('reading');
$search->setQuery($query);
$scroll = new \Elastica\Scroll($search);
$results = [];
foreach ($scroll as $scrollId => $resultSet) {
foreach ($resultSet->getDocuments() as $doc) {
$results[$doc->getId()] = $doc;
}
}
So far in this approach I can get the scroll id and the results i need. But if you found another way, hoping you can post it in this question.

Splitting an external array to give different titles

I've been trying to figure out how to split the array and add different titles for each of the separate titles on the page, for each of the different things that this displays. However the most I can manage to do is add a comma between the numbers and words.
I would like to add selling"1st variable price"second variable" etc however I don't quite know how to do anything other than to turn this very confusing looking bunch of letters:
user name and notes 01001000013972583957ecCCany amount-w378- v west
into anything other than this:
0,100,10000,1397258395,7ec,CC,any amount-w378- v west
Also, this is what it looks like in its JSON form:
{"selling":"0","quantity":"100","price":"10000","date":"1397258395","rs_name":"7ec","contact":"CC","notes":"any amount-w378- v west"}
I just want all the information that is in there to displayed like that however I'm not quite sure how to add the titles that is in the JSON data. I also don't have access to the external site to change anything.
A little background: what I am trying to achieve is a price look-up for a game on my website from an external site. I tried to use an iframe but it was terrible; I would rather just manually display it rather than showing their site from mine - their style and my style clash terribly.
$json = file_get_contents('http://forums.zybez.net/runescape-2007-prices/api/rune+axe');
$obj = json_decode($json,true);
$blah1 = implode( $obj[0]["offers"][1]);
print_r($blah1);
If you know where it is, you should be able to just grab it and show it out?
You can use a failsafe to check if it is present with is_array() and isset() functions - see php.net docs on them.
Your print_r should give you good valid info -- try to wrap it around <pre></pre> tags before for better readability or view the source - it will be easier!
<pre><?php print_r($obj) ?></pre>
This should be your starting point, and from here you will either take the first one of your items or loop through all with
foreach ($obj as $o) { //should be $objects, not $obj
//do whatever with $o, like echo $o['price']
}
Each offers row is a table with each field separated by row:
$item = json_decode(file_get_contents('http://forums.zybez.net/runescape-2007-prices/api/rune+axe'));
while ($offer = array_shift($item[0]->offers)) {
echo "<table>" . PHP_EOL;
foreach ($offer as $field => $value) {
echo "<tr><th>$field</th><td>$value</td></tr>" . PHP_EOL;
}
echo "</table>" . PHP_EOL;
}
http://codepad.org/C3PQJHqL
Tables in HTML:
http://jsfiddle.net/G5QqZ/

I need help sorting out an if statement in a simplexml statement

Some basic background ...
I have a form that enters data to an xml file and another page that displays the data from teh xml depending that it meets the requirements . All of this I have managed to get done and thanks to a member on here I got it to show only the data as long as it has todays date and status is out . But I am left with the problem of trying to sort an if statement which needs to show data if it has it or show another div if not .
My Code ...
$lib = simplexml_load_file("sample.xml");
$today = date("m/d/y");
$query = $lib->xpath("//entry[.//date[contains(., '$today')]] | //entry[.//status[contains(., 'out')]]");
foreach($query as $node){
echo "<div id='one'>$node->name</div>
<div id='two'>$node->notes</div>
<div id='three'><div class='front'>$node->comments</div></div>";
}
So to reiterate if query returns matched data do the foreach else show another div
I only wish to know the right code for the if else statement if soneone could help with this I would be very grateful and will up vote any answer as soon as I have the reputation in place . I also apologise in advance if the question has been asked before or if it is too vague thanks again .
If xpath fails to resolve the path, it will return false (see here). Wrap the foreach loop in a simple check:
if( $query ) {
foreach($query as $node){
...
}
}
else {
// Echo the special div.
}
Since PHP is loose typed, if xpath happens to return an empty array, this check will also handle that case. Be aware that if the xpath call does return false, there may be a separate error at play that may require additional or alternative handling.

Google social Graph response decode

I would like make a script that automatically insert in a Array the Google+ ID's fetched from
the SocialGraphs Api but i can't understand the type of this result,here's the example of the result: http://pastebin.com/wfBAtjH7
If can be help,i've seen the method for isolate the ID's done in Javascript:
var oids = [];
var reobg = new RegExp("\\d{21}","g"); // only interested in user ID so prepare regexp
oids = resp.match(reobg); // get an array of ids
if (!oids == null){ // if something stringify it
oids = oids.join(",");
}
For get in a variable all the text,i've used this code:
$gplus = file_get_contents('https://plus.google.com/u/0/_/socialgraph/lookup/visible/?o=[null,null,"103227580967788703328"]&rt=j');
Where 103227580967788703328 is an example Google Plus ID.
Thanks in advance.
Kind Regards.
Luca.
Try and cycle through the input with this regex:
\[\[,,"(\d+)"\]
and grab the first group each time.
Try this \[(.*),(.*),"(.*)"\] this is may help U.

How do I get the Position of an Attribute-Option in Magento?

I've got the following problem. In an extra module, I want to sort the options of an attribute, based on their position. When I try to get the Option of an Attribute, I can get the Id and the Label, but there is nothing mor ein that object.
I can do, for example, this:
$attribute = $_product->getResource()->getAttribute($code)->getOptionsText($value):
Or just getOptionId($value), but there is nothing to get the Position, which is editable in the backend. So, how to get this? Havn't found anything (useful) on the net yet.
(Also the similar question magento sort attribute option collection by position? doesnt give any help)
EDIT:
What I managed to do, is doing a direct SQL statement, like this:
SELECT sort_order FROM mag_eav_attribute_option WHERE option_id = 114 AND attribute_id = 533;
But I think, there is a better option to get that value.
I found the answer myself and want to share it with you.
$attribute = Mage::getModel('eav/entity_attribute')->load( $code, 'attribute_code');
$option_col = Mage::getResourceModel( 'eav/entity_attribute_option_collection')
->setAttributeFilter( $attribute->getId() )
->setStoreFilter()
->setPositionOrder( 'ASC' );
$option_col->getSelect()->order('main_table.sort_order '.$orderby);
I hope it helps someone.
This is actually quite simple if you take a look # Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
$attributeId = 230;
$options = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attributeId)
->setPositionOrder('desc', true)
->load();
foreach($options as $opt){
Mage::log($opt->getSortOrder());
}
I see you came up with something similar already but I thought I would post this as it may be helpful to others.
Start to debug then:
print_r($_product->getResource()->getAttribute($code));
print_r($_product->getResource()->getAttribute($code)->getData());
print_r(get_class_methods($_product->getResource()->getAttribute($code)));
Okay, so you have your attribute code $code and your attribute option value $value. Then you can get the corresponding sort order like that:
$source = $product->getResource()->getAttribute($code)->getSource();
$optionId = $source->getOptionId($product->getData($code));
$optionSortOrder = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setIdFilter($_optionId)
->getFirstItem()
->getSortOrder();
From: http://www.phptechi.com/getting-product-attributes-values-and-labels.html
How to fetch attribute value sort order?
Here is the Quick and Easy way using SQL to get attribute value sort positing.
Change value for variables in following code:
$CurtAtr is current attribute like color, size, etc
$attrVal is attribute value e.g. size has "small, medium, Large, etc"
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$read->fetchAll("SELECT ao.sort_order FROM eav_attribute_option_value as aov, eav_attribute_option as ao where value='$attrVal' and aov.option_id = ao.option_id and attribute_id=$CurtAtr limit 1");

Categories