Dear sirs,
I'd like to add a some custom functuions.
For examplem , add a notice and ad banner function. Every registered member can see a game notice.
How to start the custom function in combu ?
Give a some guide line. Notice is very essentials in every game.
Give a good advice.
thanks,
vincent
You can create new classes (and related database tables) seeing how it's written one of the other core classes in the web application.
For example, as you can see, every class extends the base class DataClass and defines the constructor (the body would be almost the same, you can see for example CB_Friend for a generic purpose or CB_Account for specific code where you can pass to the constructor a numeric value or text string to load a record from database), overrides the methods Save and Delete (to do respectively store into database and delete from it), and creates a new method Load (to load the records from the database). Once you have created the new classes (usually you want to save all of them in the folder /lib with the other ones), you have to add them to the preloader /lib/api.php that is included in all the webservices and finally create your own webservice to catch your requests (take look at those already implemented).
This is an example of custom class:
<?php
class MyCustomClass extends DataClass {
const TABLE_NAME = "My_Table_Name";
// The public fields must have the same name and letter-case as in the table definition
public $Id = 0; // e.g. let's assume we have a field Id defined in the table as BIGINT Auto-Increment
public $TextMessage = "";/**
* Contructor
*/
public function __construct($src = null, $stripSlashes = false) {
if ($src == null)
return;
if (is_array($src)) {
// Load by array
$this->_loadByRow($src, $stripSlashes);
}
}/**
* Get records from database, the parameters depend on your needs
*
* @param string $filterText Filter TextMessage
* @param int $limit The maximum number of records
* @param int $offset The first row index to load (to be used together with "limit" to create pagination)
* @param int $count Will be valorized by DataClass::_load* functions with the total number of records selected by the "where" clause
* @param boolean $returnArray If TRUE then it will return an associative arrays, else an array of objects
* @return array Returns the array of records
*/
public static function Load ($filterText, $limit = null, $offset = null, &$count = null, $returnArray = false) {
global $Database;
$where = sprintf("TextMessage = '%s'", $filterText, $Database->Escape($filterText));
$orderBy = "Id";
return self::_load(self::TABLE_NAME, ($returnArray ? "" : "MyCustomClass"), $where, $orderBy, $limit, $offset, $count);
}/**
* Save the record in the database
*
* @return bool Returns TRUE on success
*/
public function Save() {
global $Database;
if ($this->Id > 0) {
$query = sprintf("UPDATE %s SET TextMessage = '%s' WHERE Id = %d",
self::TABLE_NAME,
$Database->Escape($this->TextMessage),
$this->Id);
} else {
$query = sprintf("INSERT INTO %s (TextMessage) VALUES ('%s')",
self::TABLE_NAME,
$Database->Escape($this->TextMessage));
}
if ($Database->Query($query)) {
// The following lines are needed if "Id" is an auto-increment field
if ($this->Id < 1)
$this->Id = $Database->InsertedId();
return TRUE;
}
return FALSE;
}/**
* Delete the record from the database
*
* @return bool Returns TRUE on success
*/
public function Delete() {
return $this->_Delete(self::TABLE_NAME, sprintf("Id = %d", $this->Id));
}
}
FRANCESCO CROCETTI @ SKARED CREATIONS