1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P58 doc

5 181 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 98,13 KB

Nội dung

■ Sets an object variable called fields, which holds a comma separated list of fields from the std_fields set earlier. ■ Sets the object variable dbi to point to the class.DBI.php-provided object, which is passed to the constructor by an application. The dbi member variable holds the DBI object that is used to communicate with the back-end database. ■ Calls setDocID()to set the document ID of the object. ■ Sets an object variable called std_fields, which is an array that con- tains the LD_DOCUMENT table attributes and their data type. ◆ loadDocInfo(): This method loads all attribute values into the document object from the LD_DOCUMENT table by the specified document ID. This is how it works: ■ setDocID() is called to set the passed document ID to the current object. If no document ID is passed, the current object’s document ID is taken. ■ The $this->dbi object is used to retrieve all the attribute values of the given document from the LD_DOCUMENT table. ■ Each of the values is set to the current object so that they can be retrieved at any time using the other get methods of this class. For example $this->DOC_NAME is set the value of the DOC_NAME of the given document. This method sets all the attributes such as document ID, category number, heading, body of the document, and publish date for a given document. ◆ addDoc(): This method adds new documents to the database. Attributes such as document ID, category number, heading, body of the document, and publish date are passed in an associative array as parameters to this method. It works as follows: ■ The SQL statement is prepared using the $this->std_fields array that contains all the attributes of the LD_DOCUMENT table and the values from the associative array that has been passed as parameter. ■ The values of the parameter are formatted using the quote() method of the $this->dbi object. ■ After executing the SQL statement, the newly added document’s DOC_ID is retrieved using another SQL statement. ■ If the insertion query is successful, this method returns the category ID of the newly added category. Otherwise, it returns FALSE. 256 Part II: Developing Intranet Solutions 11 549669 ch08.qxd 4/4/03 9:25 AM Page 256 ◆ modifyDoc(): This method updates document information in the data- base. Attributes such as document ID, category number, heading, body of the document, and publish date are passed in an associative array as para- meters to this method. It works as follows: ■ The SQL statement is prepared using the $this->std_fields array that contains all the attributes of the LD_DOCUMENT table and the values from the associative array that has been passed as a parameter. ■ The values of the parameter are formatted using the quote() method of the $this->dbi object. ■ If the update query is successful, this method returns TRUE. Otherwise, it returns FALSE. ◆ getDocsByCatID(): This method returns all documents that are to be published until the current time related to the given category from the database. This method takes category ID as the parameter. It works as follows: ■ It executes a SQL statement that retrieves all the documents up to the current timestamp for the given category. ■ It stores the result into an array if the result set is not empty. ■ It returns the array, or, if the result is empty, it returns null. ◆ getAllDocsByCatID(): This method returns all documents that fall under the given category. This also takes category ID as a parameter. It works as follows: ■ It executes a SQL statement that retrieves all the documents for the given category. ■ It stores the result into an array if the result set is not empty. ■ It returns null if the result is empty. Otherwise, it returns the array. ◆ getTrackDetails(): This method returns all tracking information for the given document. It works as follows: ■ It executes a SQL query that retrieves all the user IDs and their visit timestamps for the given document ID. ■ The result is stored in an array if it is not empty. ■ The method returns null when the result set is empty. Otherwise, it returns the array. Chapter 8: Intranet Simple Document Publisher 257 11 549669 ch08.qxd 4/4/03 9:25 AM Page 257 The following are other methods of this class: Method Description setDocID() Sets the document ID. If the document ID is provided as a parameter, it is set as the object’s document ID; otherwise, the current object’s document ID is returned. getHeading() Returns the heading of the current document object. It takes document ID as a parameter. getPublishDate() Returns the publishing date of the current document object. It also takes document ID as a parameter. getBody() Returns the body of the current document object. Document ID is passed into this method as a parameter. getCategory() Returns the category of the current document object. It takes document ID as a parameter. deleteDoc() Deletes the document from the database. It will delete all data related to the document from the database. It takes the ID of the document to be deleted as the parameter. deleteResponsesByDocID() Deletes all responses related for any doc from the database. It takes document ID as the parameter. trackVisit() Tracks visits to the given document and enters new track information (document ID, user ID, and visit timestamp) into the LD_TRACK table of the database. It takes document ID, user ID, and the timestamp as parameters. It returns TRUE upon successful insertion; otherwise, it returns FALSE. The Response class The Response class provides the response object. The response object is used to manipulate response data. Applications can add or remove responses using the response object. The ch08/apps/class/class.Response.php file in the CDROM is an implementation of this class. 258 Part II: Developing Intranet Solutions 11 549669 ch08.qxd 4/4/03 9:25 AM Page 258 Following are the response class methods: ◆ Response(): This is the constructor method that creates the response object. This method does the following: ■ Sets the object variable cat_tbl, which holds the category table name, to $LD_CATEGORY_TBL, which is loaded from the ld.conf file. ■ Sets the object variable doc_tbl, which holds the document table name, to $LD_DOC_TBL, which is loaded from the ld.conf file. ■ Sets the object variable resp_tbl, which holds the response table name, to $LD_RESPONSE_TBL, which is loaded from the ld.conf file. ■ Sets the object variable dbi to point to the class.DBI.php-provided object, which is passed to the constructor by an application. The dbi member variable holds the DBI object that is used to communicate with the back-end database. ■ Calls setResponseID() to set the response ID of the object. Sets the object variable std_fields, which is an array that contains the LD_RESPONSE table attributes and their data type. ◆ loadResponseInfo(): This method loads all attribute values into the response object from the LD_RESPONSE table by the specified response ID. This is how it works: ■ It calls setResponseID() to set the passed response ID to the current object. If no response ID is passed, the current object’s response ID is taken. ■ The $this->dbi object is used to retrieve all the attribute values of the given response from the LD_RESPONSE table. ■ Each of the values is set to the current object so that they can be retrieved at any time using the other get methods of this class. For example $this->RESPONDER is set the username who responded (i.e. provided feedback) to a document. ◆ getResponsesByDocID(): This method returns all responses for a given document ID. This is how it works: ■ It executes a SQL query that retrieves all the attributes of the LD_RESPONSE table for a given document ID. ■ It stores the result of the query in an array unless the result set is empty. ■ The method returns null when there is no result found from the query; otherwise, it returns the array. Chapter 8: Intranet Simple Document Publisher 259 11 549669 ch08.qxd 4/4/03 9:25 AM Page 259 ◆ addResponse(): This method adds new response to the LD_RESPONSE table of the database. The attributes such as response ID, category number, subject, document ID, rate, response time, and so on are passed into an associative array as parameters to this method. It works as follows: ■ The SQL statement is prepared using the $this->std_fields array that contains all the attributes of the LD_RESPONSE table and the values from the associative array that has been passed as parameter. ■ The values of the parameter are formatted using the quote() method of the $this->dbi object. ■ After executing the SQL statement, the newly added response’s RESPONSE_ID is retrieved using another SQL statement. ■ If the insertion query is successful, this method returns the response ID of the newly added response. Otherwise, it returns FALSE. Following are the other methods in this class: Method Description setResponseID() Sets the response ID. If the response ID is provided as the parameter, it is set as the object’s response ID; otherwise, the current response ID is returned. getResponseSubject() Returns the subject of the current response. It takes the response ID as the parameter. getResponseDocID() Returns the document ID of the current response. It takes the response ID as the parameter. getResponder() Returns the responder of the current response. It takes response ID as the parameter. getResponseBody() Returns the body of the current response. Response ID is passed to this method as the parameter. getAvgRatingByDocID() Returns the average rating of a given document. It takes the document ID as the parameter. getTotalResponseByDocID() Returns the total number of responses for the given document. This method takes the document ID as the parameter. deleteResponse() Deletes the response from the database. It will delete all data related to the response from the database. It takes response ID as the parameter. 260 Part II: Developing Intranet Solutions 11 549669 ch08.qxd 4/4/03 9:25 AM Page 260 . into the document object from the LD_DOCUMENT table by the specified document ID. This is how it works: ■ setDocID() is called to set the passed document ID to the current object. If no document. For example $this-> ;DOC_ NAME is set the value of the DOC_ NAME of the given document. This method sets all the attributes such as document ID, category number, heading, body of the document, and publish. publish date for a given document. ◆ addDoc(): This method adds new documents to the database. Attributes such as document ID, category number, heading, body of the document, and publish date

Ngày đăng: 07/07/2014, 07:20