Tadashi Okoshi
slash****@users*****
2005年 12月 10日 (土) 11:14:12 JST
Index: affelio/lib/Affelio/Managing/MyNewsManager.pm
diff -u affelio/lib/Affelio/Managing/MyNewsManager.pm:1.1 affelio/lib/Affelio/Managing/MyNewsManager.pm:1.2
--- affelio/lib/Affelio/Managing/MyNewsManager.pm:1.1 Sat Dec 10 10:03:32 2005
+++ affelio/lib/Affelio/Managing/MyNewsManager.pm Sat Dec 10 11:14:12 2005
@@ -14,12 +14,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
-# $Id: MyNewsManager.pm,v 1.1 2005/12/10 01:03:32 slash5234 Exp $
+# $Id: MyNewsManager.pm,v 1.2 2005/12/10 02:14:12 slash5234 Exp $
package Affelio::Managing::MyNewsManager;
{
use strict;
use lib("../../../extlib");
+ use Error qw(:try);
use DBI;
use Jcode;
use lib("../../");
@@ -50,75 +51,62 @@
#to get the whole list of message types.
########################################################################
- #retrieve_message
+ #retrieve_news
########################################################################
- #sub SQL_result get_all_group_list
- # result (mid,timestamp,msg_title,msg_type,msg_from,msg_body,readflag)
- sub retrieve_all_messages{
+ sub retrieve_news{
my $self = shift;
+ my %arg = @_;
+ my $laterthan= $arg{laterthan};
+ if(!defined($laterthan)){ $laterthan = 0; }
- debug_print("MM::retrieve: start");
my $af = $self->{af};
+ debug_print("MyNews::retrieve: start [$laterthan]");
##############################
#retrieve all friend records from DB
- my $sth = $af->getDB->prepare(q{SELECT * FROM AFuser_CORE_message}) or die $af->getDB->errstr;
- $sth->execute;
+ my $sth;
+ try{
+ $sth = $af->getDB()->prepare("SELECT nid, datetime, app_install_name, title, description, creator, URL FROM AFuser_CORE_my_news WHERE datetime > $laterthan") or die $af->getDB->errstr;
+ $sth->execute;
+ }catch Error with{
+ my $e = shift;
+ debug_print($e);
+ throw($e);
+ };
- debug_print("MM::retrieve: end");
+ debug_print("MyNews::retrieve: end");
return($sth);
}
#######################################################################
- #post_message
- # arg1 SenderName: (app_name)
- # arg2 Title: (UTF-8)
- # arg3 Type: (Ascii)
- # arg4 Body: (free text including URL)
+ #post_news
+ # arg1 app_install_title (UTF-8)
+ # arg2 title (UTF-8)
+ # arg3 desc (UTF-8)
+ # arg4 creator (UTF-8)
+ # arg5 URL (UTF-8)
#######################################################################
- sub post_message{
+ sub post_news{
my $self = shift;
- my $from = shift; #1
- my $title = shift; #2
- my $type = shift; #3
- my $body = shift; #4
+ my %arg = @_;
+ my $datetime = Affelio::misc::Time::get_timestamp();
+ my $app_install_name = $arg{app};
+ my $title = $arg{title};
+ my $description = $arg{desc};
+ my $creator = $arg{creator};
+ my $URL = $arg{URL};
my $af = $self->{af};
- Affelio::misc::Debug::debug_print("MM::post_message: start.");
-
-# $body = Affelio::misc::Encoding::db_encode($body);
-# $title = Affelio::misc::Encoding::db_encode($title);
-# $from = Affelio::misc::Encoding::db_encode($from);
-
- #mid,timestamp,msg_title,msg_type,msg_from,msg_body,readflag
-
- ##############################
- #Get existing max ID
- my $sth = $af->getDB->prepare(q{SELECT max(mid) FROM AFuser_CORE_message}) or die $af->getDB->errstr;
- $sth->execute;
- my @row = $sth->fetchrow_array;
- my $maxid = $row[0];
- if(defined($row[0])){
- $maxid = $row[0];
- }else{
- $maxid = 0;
- }
- my $newid = $maxid+1;
- Affelio::misc::Debug::debug_print("MM::post_message: newid = $newid");
-
- my $cur_time = Affelio::misc::Time::get_timestamp();
-
- Affelio::misc::Debug::debug_print("MM::post_message: Writing to DB...");
- Affelio::misc::Debug::debug_print("MM::post_message: [$body]");
+ debug_print("MyNews:post_message: start.");
##############################
#Insert a new record
- my $str1 = "insert into AFuser_CORE_message(mid, timestamp, msgtitle, msgtype, msgfrom, msgbody, readflag) values ($newid, '$cur_time', '$title', '$type', '$from', '$body', 0)";
- $sth = $af->getDB->prepare($str1) or die $af->getDB->errstr;
+ my $sth = "insert into AFuser_CORE_my_news(datetime, app_install_name, title, description, creator, URL) values ($datetime, '$app_install_name', '$title', '$description', '$creator', '$URL')";
+ $sth = $af->getDB->prepare($sth) or die $af->getDB->errstr;
$sth->execute or die $af->getDB->errstr;
- Affelio::misc::Debug::debug_print("MM::post_message: end.");
+ Affelio::misc::Debug::debug_print("MyNews::post_message: end.");
return("");
}