本文整理汇总了PHP中Messages::getNewMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Messages::getNewMessages方法的具体用法?PHP Messages::getNewMessages怎么用?PHP Messages::getNewMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Messages
的用法示例。
在下文中一共展示了Messages::getNewMessages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeAction
/**
* Before action load knight data of user
* @param unknown_type $action
*/
public function beforeAction($action)
{
//Load user's knight data
if (!Yii::app()->user->isGuest) {
$this->user_data['knights'] = Knights::model()->with('knightsCard', 'knightsStats')->find('id=:id', array(':id' => Yii::app()->user->knights_id));
$this->user_data['knights_card'] =& $this->user_data['knights']->knightsCard;
//Load stats of knight
$this->user_data['knights_stats'] =& $this->user_data['knights']->knightsStats;
//Load if user has new friendship request
$sql = 'SELECT friends.id as id, k1.name as name, k1.avatars_id as avatars_id FROM friends
INNER JOIN users ON users.id = friends.from_user
INNER JOIN knights as k1 ON k1.users_id = users.id
WHERE friends.status = :status AND to_user = :users_knights_id1
ORDER BY start_date DESC';
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(':status', Friends::STATUS_ONWAITING, PDO::PARAM_INT);
$command->bindValue(':users_knights_id1', $this->user_data['knights']->id, PDO::PARAM_INT);
$this->user_data['knights_new_friends'] = $command->queryAll();
//Load last messages
$this->user_data['new_messages'] = Messages::getNewMessages(Yii::app()->user->users_id);
//Load all attributes name attributes
$this->app_data['attribute_list'] = Constants::model()->findAll('type=:type', array(':type' => Constants::KNIGHTS_ATTRIBUTES));
}
return true;
}
示例2: init
/**
* Load data for widget template
*/
public function init()
{
//Check if user is login
if (!Yii::app()->user->isGuest) {
//Load if user has new friendship request
$sql = 'SELECT friends.id as id, k1.name as name, k1.avatars_id as avatars_id FROM friends
INNER JOIN users ON users.id = friends.from_user
INNER JOIN knights as k1 ON k1.users_id = users.id
WHERE friends.status = :status AND to_user = :users_knights_id1
ORDER BY start_date DESC';
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(':status', Friends::STATUS_ONWAITING, PDO::PARAM_INT);
$command->bindValue(':users_knights_id1', Yii::app()->user->users_id, PDO::PARAM_INT);
$this->_newFriends = $command->queryAll();
//Load new messages
$this->_newMessages = Messages::getNewMessages(Yii::app()->user->users_id);
}
}
示例3: beforeAction
/**
* Before action load knight data of user
* @param unknown_type $action
*/
public function beforeAction($action)
{
//Check if user is login and load knight data of user
if (!Yii::app()->user->isGuest) {
//Update cache connected
Yii::app()->cache->set(Yii::app()->params['cachekeys']['knight_connected'] . Yii::app()->user->knights_id, true, Yii::app()->params['cachetime']['knight']);
$withStatement = array('knightsCard', 'knightsStats');
//Load data of knight
//$this->user_data['knights'] = Knights::model()->cache( Yii::app()->params['cachetime']['knight'] )->with( $withStatement )->find( 'id=:id', array(':id'=>Yii::app()->user->knights_id) );
if (!($this->user_data['knights'] = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['knights'] . Yii::app()->user->knights_id))) {
$this->user_data['knights'] = Knights::model()->findByPk(Yii::app()->user->knights_id);
Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights'] . Yii::app()->user->knights_id, $this->user_data['knights'], Yii::app()->params['cachetime']['knight']);
}
//Load knights card
if (!($this->user_data['knights_card'] = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['knights_card'] . Yii::app()->user->knights_id))) {
$this->user_data['knights_card'] = $this->user_data['knights']->knightsCard;
Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights_card'] . Yii::app()->user->knights_id, $this->user_data['knights_card'], Yii::app()->params['cachetime']['knight']);
}
//Load stats of knight
if (!($this->user_data['knights_stats'] = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['knights_stats'] . Yii::app()->user->knights_id))) {
$this->user_data['knights_stats'] = $this->user_data['knights']->knightsStats;
Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights_stats'] . Yii::app()->user->knights_id, $this->user_data['knights_stats'], Yii::app()->params['cachetime']['knight']);
}
//Load if user has new friendship request
$sql = 'SELECT friends.id as id, k1.name as name, k1.avatars_id as avatars_id FROM friends
INNER JOIN users ON users.id = friends.from_user
INNER JOIN knights as k1 ON k1.users_id = users.id
WHERE friends.status = :status AND to_user = :users_knights_id1
ORDER BY start_date DESC';
$command = Yii::app()->db->cache(Yii::app()->params['cachetime']['friends'])->createCommand($sql);
$command->bindValue(':status', Friends::STATUS_ONWAITING, PDO::PARAM_INT);
$command->bindValue(':users_knights_id1', $this->user_data['knights']->id, PDO::PARAM_INT);
$this->user_data['knights_new_friends'] = $command->queryAll();
//Load last messages
$this->user_data['new_messages'] = Messages::getNewMessages(Yii::app()->user->users_id);
//Load all attributes name attributes
$this->app_data['attribute_list'] = Constants::model()->cache(Yii::app()->params['cachetime']['appSetting'])->findAll('type=:type', array(':type' => Constants::KNIGHTS_ATTRIBUTES));
//Check if user is in combat
if ($this->user_data['knights']->status == Knights::STATUS_AT_COMBAT) {
//Check combat identificator
if ($combat_id = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['combat_for_knights_id'] . Yii::app()->user->knights_id)) {
$this->user_data['combat'] = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['combat'] . $combat_id);
} else {
//Load from database
$this->user_data['combat'] = Combats::model()->cache(Yii::app()->params['cachetime']['combat'])->find('status = :status AND (from_knight = :from_knight OR to_knight = :to_knight)', array(':status' => Combats::STATUS_ENABLE, ':from_knight' => Yii::app()->user->knights_id, ':to_knight' => Yii::app()->user->knights_id));
Yii::app()->cache->set(Yii::app()->params['cacheKeys']['combat_for_knights_id'] . Yii::app()->user->knights_id, $this->user_data['combat']->id, Yii::app()->params['cachetime']['combat']);
Yii::app()->cache->set(Yii::app()->params['cacheKeys']['combat'] . $this->user_data['combat']->id, $this->user_data['combat'], Yii::app()->params['cachetime']['combat']);
}
}
}
//Load knight data
if (!Yii::app()->user->isGuest && (!isset($_GET['sir']) || $_GET['sir'] == $this->user_data['knights']->name)) {
//Load the user knight in the knight
$this->knight = $this->user_data['knights'];
$this->knight_is_online = true;
} else {
//Load knight data
//$this->knight = Knights::model()->cache(Yii::app()->params['cachetime']['knight'])->find( 'name=:name', array( ':name'=>$_GET['sir']) );
if (!($this->knight = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['knights_by_name'] . $_GET['sir']))) {
if ($this->knight = Knights::model()->cache(Yii::app()->params['cachetime']['knight'])->find('name=:name', array(':name' => $_GET['sir']))) {
Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights_by_name'] . $_GET['sir'], $this->knight, Yii::app()->params['cachetime']['knight']);
}
}
if ($this->knight) {
if ($this->knight->status != Knights::STATUS_PENDING_VALIDATION) {
if (!Yii::app()->user->isGuest) {
//Load stats vs
$this->user_data['knights_stats_vs'] = KnightsStatsVs::model()->cache(Yii::app()->params['cachetime']['knight'])->find('knights_id = :knights_id AND opponent = :opponent', array(':knights_id' => Yii::app()->user->knights_id, ':opponent' => $this->knight->id));
if ($this->knight->status != Knights::STATUS_PENDING_VALIDATION) {
//Check if knight and user knight are friends.
$condition = "(from_user = :user_knight1 AND to_user = :knight1 AND status = :status1) OR (from_user = :knight2 AND to_user = :user_knight2 AND status = :status2)";
$params = array(':knight1' => $this->knight->users_id, ':knight2' => $this->knight->users_id, ':user_knight1' => $this->user_data['knights']->users_id, ':user_knight2' => $this->user_data['knights']->users_id, ':status1' => Friends::STATUS_ACCEPT, ':status2' => Friends::STATUS_ACCEPT);
$friendRelationship = Friends::model()->cache(Yii::app()->params['cachetime']['knight'])->find($condition, $params);
$this->are_they_friends = $friendRelationship != null;
//Load if knight is online knight
//$this->knight_is_online = Sessions::model()->exists( 'users_id = :users_id AND expire > :expire', array(':users_id'=>$this->knight->users_id, ':expire'=>time() ) );
$this->knight_is_online = Yii::app()->cache->get(Yii::app()->params['cacheKeys']['knight_connected'] . $this->knight->id);
} else {
$this->render('pending_activation');
}
}
} else {
//Knight is not exist
throw new CHttpException(404, 'Upsss! El caballero está pendiente de validar su cuenta.');
}
} else {
//Knight is not exist
throw new CHttpException(404, 'Upsss! El caballero que buscas no existe.');
}
}
//var_dump( Yii::app()->cache->getMemCache()->getAllKeys() );
return true;
}