Path

ez projects / sqliimport / forum / general / updating by node id and ite...


Updating by Node ID and Iterating through fields

You need to be logged in to post messages in the forums. New users may register here.

Jani Tarvainen

Member since:
11 February 2008

Posts: 6

Friday 15 October 2010 8:44:02 am

I had a use case where the CSV row contains a value that that is used to match to a value of a certain attribute (I did this with a normal fetch). I needed to update a matrix in the content object using all the values in the CSV (separate files with different number of columns).

I did not find a reasonable method to do the following:

- Use the content publisher to modify a specified node by ID
- Loop through all the fields of the row and push the to a string for importing

Should these be possible?
Up

Jérôme Vieilledent

Member since:
09 January 2008

Posts: 98

Friday 15 October 2010 10:19:28 am

Hi Jani




- Use the content publisher to modify a specified node by ID




Actually you can initiate an SQLIContent object from an eZContentObject, eZContentObjectTreeNode, a NodeID, a ContentObjectID, and of course a RemoteID.




// Assume that $myFetchedNode is an eZContentObjectTreeNode object previously fetched


$mySQLIContent = SQLIContent::fromNode( $myFetchedNode );



Et voilà !
Take a look in the API doc, you'll see other fromXXX methods ;-)




Loop through all the fields of the row and push the to a string for importing



SQLCSVRow does implement Iterator interface, so you can smoothly loop against its fields with a foreach loop :



foreach( $myCSVRow as $fieldName => $field )


{


    // Do stuffs with your field


}




Hope this helps :)
Up

You need to be logged in to post messages in the forums. New users may register here.