2011-11-27 12:46:10 +01:00
|
|
|
<?php
|
2013-01-19 20:36:40 +01:00
|
|
|
namespace chat\system\menu\page;
|
2011-11-27 12:46:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PageMenuItemProvider for chat.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2013-01-19 20:36:40 +01:00
|
|
|
* @copyright 2010-2013 Tim Düsterhus
|
2011-11-27 12:46:10 +01:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2013-01-19 20:36:40 +01:00
|
|
|
* @package be.bastelstu.chat
|
2011-11-27 12:46:10 +01:00
|
|
|
* @subpackage system.menu.page
|
|
|
|
*/
|
2013-01-19 20:36:40 +01:00
|
|
|
class ChatPageMenuItemProvider extends \wcf\system\menu\page\DefaultPageMenuItemProvider {
|
2013-05-24 02:21:49 +02:00
|
|
|
/**
|
|
|
|
* room that the menu item points to
|
|
|
|
*
|
|
|
|
* @var \chat\data\room\Room
|
|
|
|
*/
|
2011-12-15 10:54:18 +01:00
|
|
|
protected $room = null;
|
|
|
|
|
2011-11-27 12:46:10 +01:00
|
|
|
/**
|
|
|
|
* Hides the button when there is no valid room
|
|
|
|
*
|
2012-02-26 17:55:44 +01:00
|
|
|
* @see \wcf\system\menu\page\PageMenuItemProvider::isVisible()
|
2011-11-27 12:46:10 +01:00
|
|
|
*/
|
|
|
|
public function isVisible() {
|
2011-11-27 20:01:28 +01:00
|
|
|
// guests are not supported
|
2011-11-29 16:57:44 +01:00
|
|
|
if (!\wcf\system\WCF::getUser()->userID) return false;
|
2011-11-27 20:01:28 +01:00
|
|
|
|
2013-05-24 02:21:49 +02:00
|
|
|
$rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
2012-09-07 22:32:42 +02:00
|
|
|
|
2013-05-24 02:21:49 +02:00
|
|
|
foreach ($rooms as $this->room) {
|
2012-09-07 22:32:42 +02:00
|
|
|
if ($this->room->canEnter()) {
|
|
|
|
return true;
|
2011-12-26 12:43:19 +01:00
|
|
|
}
|
2011-11-27 12:46:10 +01:00
|
|
|
}
|
2012-09-07 22:32:42 +02:00
|
|
|
|
|
|
|
return false;
|
2011-11-27 12:46:10 +01:00
|
|
|
}
|
2011-12-15 10:54:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Modifies the link to show the Link we would be redirect to.
|
|
|
|
*
|
2012-02-26 17:55:44 +01:00
|
|
|
* @see \wcf\system\menu\page\PageMenuItemProvider::getLink()
|
2011-12-15 10:54:18 +01:00
|
|
|
*/
|
|
|
|
public function getLink() {
|
2011-12-15 17:14:55 +01:00
|
|
|
return \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
2013-01-19 20:36:40 +01:00
|
|
|
'application' => 'chat',
|
2013-12-06 21:56:10 +01:00
|
|
|
'object' => $this->room,
|
|
|
|
'forceFrontend' => true
|
2011-12-15 17:14:55 +01:00
|
|
|
));
|
2011-12-15 10:54:18 +01:00
|
|
|
}
|
2011-11-27 12:46:10 +01:00
|
|
|
}
|