[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[211] trunk/0.4
Status: Beta
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2011-03-26 00:57:40
|
Revision: 211
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=211&view=rev
Author: crazedsanity
Date: 2011-03-26 00:57:34 +0000 (Sat, 26 Mar 2011)
Log Message:
-----------
Generic chat libraries.
Added Paths:
-----------
trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php
trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php
trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php
trunk/0.4/setup/genericChat.pgsql.sql
trunk/0.4/tests/testOfCSGenericChat.php
Copied: trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php (from rev 208, trunk/0.4/abstract/cs_genericGroup.abstract.class.php)
===================================================================
--- trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php (rev 0)
+++ trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211)
@@ -0,0 +1,109 @@
+<?php
+/*
+ * Created on February 25, 2011
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericChatCategoryAbstract extends cs_webapplibsAbstract {
+
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
+ /** Table name used to store categories. */
+ protected $myTable = "cswal_chat_category_table";
+
+ /** Sequence for chat category table. */
+ protected $mySeq = "cswal_chat_category_table_change_category_id_seq";
+
+ /** Table handler object for simple SQL handling */
+ private $dbTableHandler;
+
+ /** Internal categoryId to use... */
+ private $categoryId=0;
+
+ //============================================================================
+ public function __construct(cs_phpDB $db) {
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+
+ //setup table handler.
+ $cleanString = array(
+ 'category_name' => "text"
+ );
+ $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->myTable, $this->mySeq, 'chat_category_id', $cleanString);
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function set_category_id($categoryId) {
+ if(is_numeric($categoryId)) {
+ $this->categoryId=$categoryId;
+ }
+ else{
+ throw new exception(__METHOD__ .": invalid categoryId (". $categoryId .")");
+ }
+ return($this->categoryId);
+ }//end set_category_id()
+ //============================================================================
+
+
+
+ //============================================================================
+ /**
+ * Build the schema for the generic chat system.
+ */
+ protected function build_schema() {
+ try {
+ $result = $this->db->run_sql_file(dirname(__FILE__) .'/../setup/genericChat.pgsql.sql');
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create schema, DETAILS::: ". $e->getMessage());
+ }
+ if($result !== true) {
+ throw new exception(__METHOD__ .":: failed to create schema (no details)");
+ }
+ }//end build_schema()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_category($name) {
+ try {
+ $result = $this->dbTableHandler->create_record(array('category_name' => $name));
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to create record, DETAILS::: ". $e->getMessage());
+ }
+ return($result);
+ }//end create_category()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function update_category($id, $name) {
+ try {
+ $result = $this->update_record($id, array('category_name' => $name));
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .":: failed to update record, DETAILS::: ". $e->getMessage());
+ }
+ return($result);
+ }//end update_category()
+ //============================================================================
+
+}
+
Property changes on: trunk/0.4/abstract/cs_genericChatCategory.abstract.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Author
Revision
HeadURL
Date
Added: svn:mergeinfo
+
Copied: trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php (from rev 208, trunk/0.4/abstract/cs_genericGroup.abstract.class.php)
===================================================================
--- trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php (rev 0)
+++ trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211)
@@ -0,0 +1,123 @@
+<?php
+/*
+ * Created on March 8, 2011
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericChatMessageAbstract extends cs_genericChatRoomAbstract {
+
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
+ /** Table name used to store list of chat messages. */
+ protected $myTable = "cswal_chat_message_table";
+
+ /** Sequence for chat message table. */
+ protected $mySeq = "cswal_chat_message_table_change_message_id_seq";
+
+ /** Table handler object for simple SQL handling */
+ private $dbTableHandler;
+
+ /** */
+ private $categoryId=null;
+
+ /** */
+ protected $uid;
+
+ /** */
+ protected $chatRoomId;
+
+ //============================================================================
+ public function __construct(cs_phpDB $db, $uid, $chatRoomId) {
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+
+ //setup table handler.
+ $cleanString = array(
+ 'uid' => 'int',
+ 'chat_room_id' => 'int',
+ 'private_message_uid' => 'int',
+ 'message' => 'int'
+ );
+
+ if(is_numeric($uid)) {
+ $this->uid = $uid;
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid UID (". $uid .")");
+ }
+ if(is_numeric($chatRoomId)) {
+ $this->chatRoomId = $chatRoomId;
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid room ID (". $chatRoomId .")");
+ }
+ $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->myTable, $this->mySeq, 'chat_message_id', $cleanString);
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_message($messageText, $privateMessageUid=NULL) {
+ if(is_string($messageName) && strlen($message)) {
+ try {
+ $sqlArr = array(
+ 'uid' => $this->uid,
+ 'chat_room_id' => $this->chatRoomId,
+
+ //TODO: should messageText be encoded?
+ 'message' => $messageText
+ );
+ if(!is_null($privateMessageUid) && is_numeric($privateMessageUid)) {
+ $sqlArr['private_message_uid'] = $privateMessageUid;
+ }
+ $messageId = $this->dbTableHandler->create_record($sqlArr);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .": failed to create record, DETAILS::: ". $e->getMessage());
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": (". $messageName .")");
+ }
+
+ return($messageId);
+ }//end create()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function get_messages($lastMessageId=NULL, $limit=NULL) {
+ $messages = array();
+ try {
+ //get_records(array $filter=null, $orderBy=null, $limit=null, $offset=null)
+ $filterArr = array();
+ if(!is_null($lastMessageId) && $lastMessageId > 0) {
+ $filterArr['message_id'] => '> '. $lastMessageId;
+ }
+ $messages = $this->dbTableHandler->get_records_using_custom_filter($filter, NULL, $limit);
+ if(!is_array($messages) && $messages === false) {
+ $messages = array();
+ }
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .": error while retrieving messages, DETAILS::: ". $e->getMessages());
+ }
+ return($messages);
+ }//end get_messages()
+ //============================================================================
+
+}
+
Property changes on: trunk/0.4/abstract/cs_genericChatMessage.abstract.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Author
Revision
HeadURL
Date
Added: svn:mergeinfo
+
Copied: trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php (from rev 208, trunk/0.4/abstract/cs_genericGroup.abstract.class.php)
===================================================================
--- trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php (rev 0)
+++ trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php 2011-03-26 00:57:34 UTC (rev 211)
@@ -0,0 +1,110 @@
+<?php
+/*
+ * Created on February 25, 2011
+ *
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+abstract class cs_genericChatRoomAbstract extends cs_chatCategoryAbstract {
+
+ /** Database object. */
+ public $db;
+
+ /** cs_globalFunctions object, for cleaning strings & such. */
+ public $gfObj;
+
+ /** Table name used to store list of chat rooms. */
+ protected $myTable = "cswal_chat_room_table";
+
+ /** Sequence for chat room table. */
+ protected $mySeq = "cswal_chat_room_table_change_room_id_seq";
+
+ /** Table handler object for simple SQL handling */
+ private $dbTableHandler;
+
+ //============================================================================
+ public function __construct(cs_phpDB $db) {
+ $this->db = $db;
+ $this->gfObj = new cs_globalFunctions;
+
+ //setup table handler.
+ $cleanString = array(
+ 'category_id' => "int",
+ 'room_name' => "text",
+ 'room_description' => "text",
+ 'is_private' => "bool",
+ 'is_closed' => "bool",
+ //'encoding' => "text"
+ );
+ $this->dbTableHandler = new cs_dbTableHandler($this->db, $this->myTable, $this->mySeq, 'chat_room_id', $cleanString);
+ }//end __construct()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function create_room($roomName, $roomDescription=null, $isPrivate=false) {
+ if(is_string($roomName) && strlen($room)) {
+ try {
+ if(!is_bool($isPrivate)) {
+ $isPrivate=false;
+ }
+ $insertArr = array(
+ 'room_name' => $roomName,
+ 'room_description' => $roomDescription,
+ 'is_private' => $isPrivate
+ );
+ if(is_numeric($this->categoryId)) {
+ $insertArr['category_id'] = $this->categoryId;
+ }
+ $roomId = $this->dbTableHandler->create_record($insertArr);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .": failed to create record, DETAILS::: ". $e->getMessage());
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid room name (". $roomName .")");
+ }
+
+ return($roomId);
+ }//end create_room()
+ //============================================================================
+
+
+
+ //============================================================================
+ public function update_room($roomId, array $updates) {
+ try {
+ $retval = $this->dbTableHandler->update_record($roomId, $updates);
+ }
+ catch(Exception $e) {
+ throw new exception(__METHOD__ .": failed to update room, DETAILS::: ". $e->getMessage());
+ }
+ return($retval);
+ }//end update_room();
+ //============================================================================
+
+
+
+ //============================================================================
+ public function close_room($roomId) {
+ if(is_numeric($roomId)) {
+ $retval = $this->update_room($roomId, array('is_closed'=>true));
+ }
+ else {
+ throw new exception(__METHOD__ .": roomId (". $roomId .")");
+ }
+ return($retval);
+ }//end close_room()
+ //============================================================================
+
+
+}
+
Property changes on: trunk/0.4/abstract/cs_genericChatRoom.abstract.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Author
Revision
HeadURL
Date
Added: svn:mergeinfo
+
Added: trunk/0.4/setup/genericChat.pgsql.sql
===================================================================
--- trunk/0.4/setup/genericChat.pgsql.sql (rev 0)
+++ trunk/0.4/setup/genericChat.pgsql.sql 2011-03-26 00:57:34 UTC (rev 211)
@@ -0,0 +1,54 @@
+BEGIN;
+
+--
+-- chat categories (ways to insulate chat rooms)
+--
+CREATE TABLE cswal_chat_category_table (
+ chat_category_id serial NOT NULL PRIMARY KEY,
+ category_name text NOT NULL
+);
+
+INSERT INTO cswal_chat_category_table (chat_category_id, category_name) VALUES (0, 'DEFAULT');
+
+--
+-- Chat rooms
+--
+CREATE TABLE cswal_chat_room_table (
+ chat_room_id serial NOT NULL PRIMARY KEY,
+ chat_category_id integer NOT NULL REFERENCES cswal_chat_category_table(chat_category_id) DEFAULT 0,
+ room_name text NOT NULL,
+ room_description text,
+ creation timestamptz NOT NULL DEFAULT NOW(),
+ is_private boolean NOT NULL DEFAULT false,
+ is_closed boolean NOT NULL DEFAULT false,
+ encoding text
+);
+
+
+--
+-- Chat messages
+-- NOTE::: change the reference on "uid" and "private_message_uid" to match your database schema.
+-- NOTE::: the "private_message_uid" field is for sending private messages (intended for a specific user).
+--
+CREATE TABLE cswal_chat_message_table (
+ chat_message_id serial NOT NULL PRIMARY KEY,
+ uid integer NOT NULL REFERENCES cs_authentication_table(uid),
+ private_message_uid integer DEFAULT NULL REFERENCES cs_authentication_table(uid),
+ chat_room_id integer NOT NULL REFERENCES cswal_chat_room_table(chat_room_id),
+ creation timestamptz NOT NULL DEFAULT NOW(),
+ message text NOT NULL
+);
+
+
+--
+-- Participant table
+-- NOTE: this is a *transient* table; it only has data when the chat room is active.
+--
+CREATE TABLE cswal_chat_participant_table (
+ chat_participant_id serial NOT NULL PRIMARY KEY,
+ chat_room_id integer NOT NULL REFERENCES cswal_chat_room_table(chat_room_id),
+ uid integer NOT NULL REFERENCES cs_authentication_table(uid),
+ enter_timestamp timestamptz NOT NULL DEFAULT NOW(),
+ last_received_message_id integer REFERENCES cswal_chat_message_table(chat_message_id)
+);
+
Copied: trunk/0.4/tests/testOfCSGenericChat.php (from rev 210, trunk/0.4/tests/testOfCSGenericPermissions.php)
===================================================================
--- trunk/0.4/tests/testOfCSGenericChat.php (rev 0)
+++ trunk/0.4/tests/testOfCSGenericChat.php 2011-03-26 00:57:34 UTC (rev 211)
@@ -0,0 +1,53 @@
+<?php
+/*
+ * FILE INFORMATION:
+ *
+ * $HeadURL$
+ * $Id$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * $LastChangedRevision$
+ */
+
+class testOfCSGenericChat extends testDbAbstract {
+
+
+ //--------------------------------------------------------------------------
+ public function __construct() {
+ }//end __construct()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
+ function setUp() {
+ $this->gfObj = new cs_globalFunctions;
+ $this->gfObj->debugPrintOpt=1;
+ parent::__construct('postgres','', 'localhost', '5432');
+
+ }//end setUp()
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
+ public function tearDown() {
+ if(isset($GLOBALS['keepDb'])) {
+ unset($GLOBALS['keepDb']);
+ }
+ else {
+ $this->destroy_db();
+ }
+ }
+ //--------------------------------------------------------------------------
+
+
+
+ //--------------------------------------------------------------------------
+ public function test_chatCategories() {
+ }//end test_chatCategories()
+ //--------------------------------------------------------------------------
+
+
+
+}
Property changes on: trunk/0.4/tests/testOfCSGenericChat.php
___________________________________________________________________
Added: svn:keywords
+ Id
Author
Revision
HeadURL
Date
Added: svn:mergeinfo
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|