www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 91b732c3e109b97c0f7e3b100c7fbd3c9753ce6e
parent 711a277173837a5bd2112960e0511f691c85b819
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 27 Jun 2006 20:45:41 +0000

Addresses #87, Add fromArray() and toArray() methods to Item objects

Item.toArray() implemented -- builds up a multidimensional array of item data, converting all type ids to their textual equivalents -- currently has empty placeholder arrays for tags and seeAlso

Sample source output:

'itemID' => "2"
'itemType' => "book"
'title' => "Computer-Mediated Communication: Human-to-Human Communication Across the Internet"
'dateAdded' => "2006-03-12 05:25:50"
'dateModified' => "2006-03-12 05:25:50"
'publisher' => "Allyn & Bacon Publishers"
'year' => "2002"
'pages' => "347"
'ISBN' => "0-205-32145-3"
'creators' ...
	'0' ...
		'firstName' => "Susan B."
		'lastName' => "Barnes"
		'creatorType' => "author"
'notes' ...
	'0' ...
		'note' => "text"
		'tags' ...
		'seeAlso' ...
	'1' ...
		'note' => "text"
		'tags' ...
		'seeAlso' ...
'tags' ...
'seeAlso' ...


Sample note output:

'itemID' => "17"
'itemType' => "note"
'dateAdded' => "2006-06-27 04:21:16"
'dateModified' => "2006-06-27 04:21:16"
'note' => "text"
'sourceItemID' => "2"
'tags' ...
'seeAlso' ...

sourceItemID won't exist if it's an independent note.

We'll use the same format in reverse for fromArray, so Simon, let me know if you need more data (preserving type ids, etc) or want anything in a different form.


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/data_access.js | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+), 0 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -1014,6 +1014,81 @@ Scholar.Item.prototype.toString = function(){ } +/** +* Convert the item data into a multidimensional associative array +* for use by the export functions +**/ +Scholar.Item.prototype.toArray = function(){ + if (this.getID() && !this._itemDataLoaded){ + this._loadItemData(); + } + + var arr = []; + + // Primary fields + for (var i in this._data){ + switch (i){ + case 'itemTypeID': + arr['itemType'] = Scholar.ItemTypes.getName(this._data[i]); + break; + + // Skip certain fields + case 'firstCreator': + case 'numNotes': + continue; + + // For the rest, just copy over + default: + arr[i] = this._data[i]; + } + } + + // Item metadata + for (var i in this._itemData){ + arr[Scholar.ItemFields.getName(i)] = this._itemData[i]; + } + + if (!this.isNote()){ + // Creators + arr['creators'] = this.getCreators(); + // Convert creatorTypeIDs to text + for (var i in arr['creators']){ + arr['creators'][i]['creatorType'] = + Scholar.CreatorTypes.getName(arr['creators'][i]['creatorTypeID']); + delete arr['creators'][i]['creatorTypeID']; + } + + // Source notes + arr['notes'] = [] + var notes = this.getNotes(); + for (var i in notes){ + var note = Scholar.Items.get(notes[i]); + arr['notes'].push({ + note: note.getNote(), + // TODO + tags: [], + seeAlso: [] + }); + } + } + + // Notes + else { + delete arr['title']; + arr['note'] = this.getNote(); + if (this.getNoteSource()){ + arr['sourceItemID'] = this.getNoteSource(); + } + } + + // TODO + arr['tags'] = []; + arr['seeAlso'] = []; + + return arr; +} + + ////////////////////////////////////////////////////////////////////////////// //