I was trying to get all the items from a list using the phpSPO library: https://github.com/vgrem/phpSPO
However in the $remoteList properties in the array of Data there are only 100 rows, and the list has more than 100 items. I saw that it's a common problem, however I don't know which solution I should consider for this library.
https://sharepoint.stackexchange.com/questions/74777/list-api-get-all-items-limited-to-100-rows
$remoteList = $web->getLists()->getByTitle(xxx)
$listData = $remoteList->getItems();
There's a public property for the CamlQuery class called ListItemCollectionPosition defined in this file:
https://github.com/vgrem/phpSPO/blob/b05be0eba6902dabd18784576bb6e1d55426fa99/src/SharePoint/CamlQuery.php
That expects a ListItemCollectionPosition object as a value: https://github.com/vgrem/phpSPO/blob/b05be0eba6902dabd18784576bb6e1d55426fa99/src/SharePoint/ListItemCollectionPosition.php
So I think your code will need to look something like:
$remoteList = $web->getLists()->getByTitle(xxx);
$listItemCollectionPosition = new new ListItemCollectionPosition(); // Either add a use statement for this or use the fully qualified class name here
// ... (set the values according to the items/page you require)
$remoteList->ListItemCollectionPosition = $listItemCollectionPosition;
$listData = $remoteList->getItems();
In terms of how to use it exactly, have a read of the information here:
https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee534956(v%3Doffice.14)#retrieving-items-using-list-item-collection-position
The example is in C# but it's not too hard to follow.
It looks as though you set the ListItemCollectionPosition on your query to get subsequent "pages". It also looks as though responses include a ListItemCollectionPosition property themselves that you can then use as a starting point for the next request.
I'm having a problem getting the values from a pointer column. There is a column named "User" that points to the "_User" class in parse. I'm attempting to get the username associated with each row in my locations database. But for some reason, I'm getting a strange response.
Call to a member function get() on a non-object
My code is:
$query = new ParseQuery("SignoutDestination");
$query->includeKey("User");
// Limit what could be a lot of points.
$query->limit(100);
// Final array of objects
$signoutdestinations = $query->find();
foreach($signoutdestinations as $obj){
echo $obj->get("User")->get("username");
}
Has there been a change in the SDK or anything that could be causing this? Or am I doing something wrong?
I encountered the same issue and I kinda find a solution :
$query = new ParseQuery("SignoutDestination");
$query->includeKey("User"); // I didn't use it in my query
// Limit what could be a lot of points.
$query->limit(100);
// Final array of objects
$signoutdestinations = $query->find();
foreach($signoutdestinations as $obj){
$pointer = $obj->get("User");
// It retrieves a pointer to object, so you
// can only getObjectId() and specific fields
// like this
$pointer->fetch();
$pointer->getUsername();
// Now you're able to getUsername()
}
I hope it will help you, I would have post it as comment but couldn't due to my freshly created account.
EDIT: I changed the code with something I tried on my Parse and it worked, but it just ruins your requests ratio because of fetching, find a clever way to get Username just by querying _User and comparing ObjectId.
Indeed, with the includeKey() it should work as you written it up...
I have a class to manipulate orders. I have created multiple methods for each purpose too. There can be multiple orders to process which is generated from db. Right now, what I am doing is that, loop through each order and create objects with order id as param to constructor.
foreach($order_row as $order_rows)
{
$order_id=$order_rows->order_id ;
$warehouse =new WarehouseManager($order_id);
$warehouse->ProcessWarehouse();
}
Is it okay to loop like this? Is there any better way to handle this?
You don't need to create new object for each order. What if there is a huge number of records returned?, You only need to create one object to process an order one by one.
$warehouse = new WarehouseManager();
foreach($order_row as $order_rows)
{
$order_id=$order_rows->order_id ;
$warehouse->setOrder($order_id); // this method should be implemented first
$warehouse->ProcessWarehouse();
}
I'm looking for a way to prevent repeated calls to the database if the item in question has already been loaded previously. The reason is that we have a lot of different areas that show popular items, latest releases, top rated etc. and sometimes it happens that one item appears in multiple lists on the same page.
I wonder if it's possible to save the object instance in a static array associated with the class and then check if the data is actually in there yet, but then how do I point the new instance to the existing one?
Here's a draft of my idea:
$baseball = new Item($idOfTheBaseballItem);
$baseballAgain = new Item($idOfTheBaseballItem);
class Item
{
static $arrItems = array();
function __construct($id) {
if(in_array($id, self::arrItems)){
// Point this instance to the object in self::arrItems[$id]
// But how?
}
else {
// Call the database
self::arrItems[id] = $this;
}
}
}
If you have any other ideas or you just think I'm totally nuts, let me know.
You should know that static variables only exist in the page they were created, meaning 2 users that load the same page and get served the same script still exist as 2 different memory spaces.
You should consider caching results, take a look at code igniter database caching
What you are trying to achieve is similar to a singleton factory
$baseball = getItem($idOfTheBaseballItem);
$baseballAgain =getItem($idOfTheBaseballItem);
function getItem($id){
static $items=array();
if(!isset($items[$id])$items[$id]=new Item($id);
return $items[$id];
}
class Item{
// this stays the same
}
P.S. Also take a look at memcache. A very simple way to remove database load is to create a /cache/ directory and save database results there for a few minutes or until you deem the data old (this can be done in a number of ways, but most approaches are time based)
You can't directly replace "this" in constructor. Instead, prepare a static function like "getById($id)" that returns object from list.
And as stated above: this will work only per page load.
I have instantiated a class in my index.php file. But then I use jQuery Ajax to call some PHP files, but they can't use my object that I created in the index.php file.
How can I make it work? Because I donĀ“t want to create new objects, because the one I created holds all the property values I want to use.
Use the session to save the object for the next page load.
// Create a new object
$object = new stdClass();
$object->value = 'something';
$object->other_value = 'something else';
// Start the session
session_start();
// Save the object in the user's session
$_SESSION['object'] = $object;
Then in the next page that loads from AJAX
// Start the session saved from last time
session_start();
// Get the object out
$object = $_SESSION['object'];
// Prints "something"
print $object->value;
By using the PHP sessions you can save data across many pages for a certain user. For example, maybe each user has a shopping cart object that contains a list of items they want to buy. Since you are storing that data in THAT USERS session only - each user can have their own shopping cart object that is saved on each page!
Another option if you dont want to use sessions is to serialize your object and send it through a $_POST value in your AJAX call. Not the most elegant way to do it, but a good alternative if you don't want to use sessions.
See Object Serialization in the documentation for more informations.
mm, you should store in session, $_SESSION["someobj"] = $myobj;, and ensure that when you call the Ajax PHP file this includes the class necessary files which defines the class of $myobj and any contained object in it.
Could you be more specific? I can try.
This is how I create an object then assign it to a session variable:
include(whateverfilethathastheclassorincludeit.php)
$theObject = new TheObjectClass();
//do something with the object or not
$_SESSION['myobject'] = $theObject;
This is how I access the object's members in my Ajax call PHP file:
include(whateverfilethathastheclassorincludeit.php)
$theObject = $_SESSION['myobject'];
//do something with the object
If you don't want to move your object that is in your index.php, have your ajax make a request to index.php but add some extra parameters (post/get) that let your index.php know to process it as an ajax request and not return your normal web page html output.
You have not provided code, but what I guess is that you need to make your instantiated object global for other scripts to see it, example:
$myobject = new myobject();
Now I want to use this object elsewhere, probably under some function or class, or any place where it is not getting recognized, so I will make this global with the global keyword and it will be available there as well:
global $myobject;
Once you have the object, you can put it into the session and then utilize it in the Ajax script file.
As others have suggested, $_SESSION is the standard way to do it, in fact, that was one of the reasons, that sessions where invented to solve. Other options, i.e. serializing the object rely on the client side to hold the object and then return it untampered. Depending on the data in the object, it is not a good solution, as a) the object may include information that should not be available on the client side for security reasons and b) you will have to verify the object after receiving it.
That said, and if you still want to use the object on the client side, then JSON is an option for serializing object data, see JSON functions in PHP.
Based on most of the answers here, referring to storing the object in $_SESSION, is it more efficient to store only the individual properties that need to be accessed in AJAX as opposed to the whole object, or does it not matter?
E.g.
$_SESSION['object'] = $object;
vs
$_SESSION['property1'] = $object->property1;
$_SESSION['property2'] = $object->property2;
I know the OP is asking about accessing the entire object, but I guess my question pertains to if it's just a matter of only accessing certain properties of an object, and not needing to access methods of a class to alter the object once it's in AJAX.