Location: PHPKode > projects > Zzap > zzap/app/plugins/twitter/twitterModel.php
<?php 
/**
 * zzap group messaging / microblogging
 * 
 * Copyright (C) 2008 Dirk Ollmetzer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @package Zzap
 * @subpackage plugins
 * @author Dirk Ollmetzer <hide@address.com>
 * @copyright 2008 Dirk Ollmetzer
 * @version $Id: twitterModel.php 148 2008-10-27 20:37:34Z dollmetzer $
 * @license GPLv3 http://www.gnu.org/copyleft/gpl.html
 */

/**
 * blog model
 * 
 * This model provides access to the data in the DB table 'pi_twitter'.
 * 
 * @package Zzap
 * @subpackage plugins
 * @author Dirk Ollmetzer <hide@address.com>
 * @copyright 2008 Dirk Ollmetzer
 * @version $Id: twitterModel.php 148 2008-10-27 20:37:34Z dollmetzer $
 * @license GPLv3 http://www.gnu.org/copyleft/gpl.html
 */

class twitterModel
{
	
	/**
	 * Gets twitter related data from DB table pi_twitter for a defined user.
	 *
	 * @param integer $userid ID of the user
	 *
	 * @return array Array with twitter related data
	 */
	public function getTwitterByUser($userid) {
		
		$sql = "SELECT * FROM pi_twitter WHERE userid=$userid";
		$query = mysql_query($sql) or die ("twitterModel::getTwitterByUser()\n$sql\n".mysql_error());
		if(mysql_num_rows($query) > 0) {
			return mysql_fetch_assoc($query);
		} else {
			return array();
		}
		
	} /* getTwitterByUser($userid) */
	
	
	
	/**
	 * Saves (insertd or updates) twitter related data for a user
	 *
	 * @param integer $userid   ID of the user
	 * @param string  $name     Name of the twitter account
	 * @param string  $password Password for the twitter account
	 * @param integer $push     Flag: push new messages to twitter? (0 = no, 1 = yes)
	 * @param integer $pull     Flag: pull new messages from twitter? (0 = no, 1 = yes)
	 */
	public function saveTwitter($userid, $name, $password, $push, $pull) {
		
		$set = "twittername='$name', ";
		$set .= "twitterpass='$password', ";
		$set .= "push=$push, ";
		$set .= "pull=$pull";
		
		// Insert or update?
		$sql = "SELECT * FROM pi_twitter WHERE userid=$userid";
		$query = mysql_query($sql) or die ("twitterModel::saveTwitter()\n$sql\n".mysql_error());
		if(mysql_num_rows($query) > 0) {
			$sql = "UPDATE pi_twitter SET $set WHERE userid=$userid";
		} else {
			$sql = "INSERT INTO pi_twitter SET userid=$userid, $set";
		}
		//echo $sql."<br />\n";
		$query = mysql_query($sql) or die ("twitter::saveTwitter()\n$sql\n".mysql_error());
		
	} /* saveTwitter($userid, $name, $password, $push, $pull) */
	
	
	
	/**
	 * Updates the 'last checked' timetamp
	 *
	 * @param integer $userId    ID of the user
	 * @param integer $timestamp Unix-timestamp
	 *
	 */
	public function updateLastChecked($userId, $timestamp) {
		
		$sql = "UPDATE pi_twitter SET twitterfetch=$timestamp WHERE userid=$userId";
		$query = mysql_query($sql) or die ("twitterModel::updateLastChecked()\n$sql\n".mysql_error());
		
	} /* updateLastChecked($userId, $timestamp) */
	
	
}
?>
Return current item: Zzap