• No se han encontrado resultados

Un modelo matemático simple para la evolución de los cúmulos estelares

Desintegración de cúmulos estelares

7.2 Un modelo matemático simple para la evolución de los cúmulos estelares

Classes should be named "ExtAPI<apiName>" and should be placed in the

include/externalAPI/<apiName> directory (the directory name should be preceeded with "custom/" if this is externally created code) with the filename of "ExtAPI<apiName>.php". There can be other files located in the directory with your class and they will be ignored by the application, the external api class may use these for additional libraries, XML/XSL templates or any other necessory file. In order for the new external api class to be picked up by the system, it is necessary to flush the external api cache of class names by going to the "Admin" module, selecting the "Repair" link and then selecting "Quick Repair and Rebuild", after this is complete any new external api classes that match the naming convention.

Classes based on OAuth methods for authentication and access control should extend the

"OAuthPluginBase" class located at "include/externalAPI/Base/OAuthPluginBase.php". Username and password based api's should extend the "ExternalAPIBase" class located at

"include/externalAPI/Base/ExternalAPIBase.php". Classes should implement the ExternalAPIPlugin API, along with the WebDocument, WebFeed and/or WebMeeting API's depending on their feature set.

Classes may implement more than one of the WebDocument/WebFeed/WebMeeting API's

simultaneously and there should be only one external api class per 3rd party site so a user does not have to authenticate against the same site more than once.

73

Method calls almost always return an array containing at least a "success" element, if this element is true it can be assumed that the method call was successful. If the method returns a "success" value of false, an additional element of "errorMessage" must be set with a user-readable error message explaining the problem.

Classes may optionally use the SugarCRM "Connectors" to allow for site-wide configuration of the class, things such as API keys and system wide URL's may be entered there. Creating a stub-connector and linking it to the class is beyond the scope of this document, for a reference implementation you will want to check the Facebook external API.

Login method definitions Login Introduction

Logins to individual sites are controlled by the External Accounts (EAPM) module within SugarCRM. To access this module click on your username on the top right and select the "External Accounts" tab. This will allow you to create new accounts to associate with a 3rd party system. Currently the system allows for only one active external account per API, when a second one is created all other external accounts for that API will be disabled. If the requested API is OAuth based the user will only have to select the API name and select "Save" for the OAuth authentication to happen. If the requested API is password based, username and password fields will appear for the user to enter the username and password and then this username and password will be validated upon "Save".

For OAuth based classes the constructor should setup the private variables "oauthReq", "oauthAuth", and

"oauthAccess" based on the related OAuth URL's. If this is done correctly, the OAuthPluginBase should handle the rest of the authentication automatically. Username and password based classes will have to define a checkLogin() that returns the correct value upon successful authentication. Optionally code can be placed in to the checkLogin() and loadEAPM() functions to save and restore additional data from the

$eapmBean->api_data API specific data storage location. One optional parameter may be specified in the class for $needsUrl, if true the user will be prompted for a URL for their external account, useful when the 3rd party system has no single system wide URL.

loadEAPM

Parameters

$eapmBean A SugarBean of the External Accounts (EAPM) module

Returns

bool True or false if the EAPM loading was successful.

False indicates invalid data in the EAPM record.

This function is optionally overridden. The loadEAPM function should first call the parent's loadEAPM function while passing through the $eapmBean, if that returns successfully the class may further inspect the $eapmBean or load data from the $eapmBean->api_data. Complex data will need to be serialized and will likely need base64_encoding to sidestep the anti-XSS encoding used by the beans.

74 checkLogin

Parameters

$eapmBean = null A SugarBean of the External Accounts (EAPM) module.

Returns

Reply Array Returns a standard reply array, indicating success by having a "success" element set to true, and failure by having the "success" element set to false and a user readable error message in "errorMessage"

This function is optionally overridden for OAuth based classes. Username and password based classes must define this function and use it to make a remote API call to verify the username and password that was input by the user.

This function is called only when the user validates their login by clicking "Save" or "Revalidate" in the External Accounts (EAPM) module. Many classes use this function to collect per-user information and store serialized in $eapmBean->api_data, this data will be accessable to the loadEAPM() function call.

quickCheckLogin

Parameters

None Not applicable.

Returns

Reply Array Returns a standard reply array, indicating success by having a "success" element set to true, and failure by having the "success" element set to false and a user readable error message in "errorMessage"

This function is optionally overridden all classes. This function is called when a user has selected this class for interaction the system will fire off an AJAX request to validate the authentication while the user continues to fill in the form. This should be a very fast and quick authenticaton check to notify the user of a failed authentication before the user attempts (and fails) saving a record.

logOff

This function is unused.

Document Method Definitions Document Introduction

Any module that implements the webDocument class should also define the $supportedModules with at least the array elements of "Notes" and "Documents". This indicates to the system that it should show your API to any user that has a valid EAPM record for your class when they are attempting to upload a document. Unless document searching is totally not supported by your API, you should set the

$docSearch class property to true.

uploadDoc

Parameters

$bean The Document/Note bean that this upload is attached to

$fileToUpload The file for uploading, located on the SugarCRM server

75

$docName The filename as specified by the user's web browser

$mimetype The mimetype as specified by the user's web browser

Modifies

$bean->doc_id Should be the remote API's ID for the document. Is only used by other functions of the API class.

$bean->doc_direct_url (Optional) A link to directly download the document

$bean->doc_url A link to the document's information page on the external API, this page should contain a link to download the document.

Returns

Reply Array Returns a standard reply array, indicating success by having a "success" element set to true, and failure by having the "success" element set to false and a user readable error message in "errorMessage"

This function does the heavy lifting of the WebDocument implementation. It takes a file as uploaded by the user to the SugarCRM instance and pushes it to the external site. After it has successfully uploaded the document to the external site, it must record information about the external file so SugarCRM knows how to connect back to that document in the future.

downloadDoc This function is unused.

shareDoc

Parameters

$doc_id The Document ID that was stored as $bean->doc_id in

the uploadDoc() function

$emails The array of email addresses to share the document with.

The document sharing system should notify the user that this file is being shared with them

Returns

Reply Array Returns a standard reply array, indicating success by having a "success" element set to true, and failure by having the "success" element set to false and a user readable error message in "errorMessage"

Currently this function is not called, but it may be called in a future release.

deleteDoc

This function is unused.

searchDoc

Parameters

$keywords Keywords used for searching the documents, if the

document store does not support full text indexing, this should search the filenames

76

$flushDocCache = false (Optional) This is used to indicate if a locally stored cache of the file listing should be cleared before searching

Returns

List of results Returns an array of results, each element having the following fields: id, name, date_modified, url, direct_url This function allows users to search and display the list of documents stored on the remote server. It has hooks to connect to the local document cache, but the document cache should only be used if the remote server is too slow to handle type-ahead searches. If you are implementing the document cache and need a sample search function you can refer to the ExtAPILotusLive class as a guide.

loadDocCache

Parameters

$forceReload = true Should the local listing of documents be cleared away and fetched fresh from the remote server

Returns

List of results Returns an array of results, each element having the following fields: id, name, date_modified, url, direct_url This function is optional and is only necessary when an external API cannot perform document searches fast enough to keep up with a type-ahead search field (roughly 0.5-1 second). This function should pull down a complete list of files that the user will be active with and store them locally for searching using the searchDoc() function.

77

Chapter 3 Module Framework Overview

A Sugar Module consists of the following files:

A Vardefs file that specifies the Sugar metadata for the database table, fields, data types, and relationships.

A SugarBean file that implements the functionality to create, retrieve, update, and delete objects in Sugar. SugarBean is the base class for all business objects in Sugar. Each module implements this base class with additional properties and methods specific to that module.

Metadata files that define the contents and layout of the Sugar screens.

o ListView: lists existing records in the module.

o Detail View: displays record details.

o EditView: allows user to edit the record.

o SubPanels: displays the module's relationship with other Sugar modules.

o Popups: displays list of records to link with another record.