Skip to content
Browse files

More work on sync plugins. Roster view now uses plugins to display sp…

…ecific things.

Version changed to 0.6.3
  • Loading branch information...
1 parent 6505cf4 commit c66f78f52684abb27bd0c27dfdf542e18e6c5368 @Taracque committed Apr 27, 2012
View
38 administrator/com_raidplanner/helper.php
@@ -17,32 +17,34 @@
jimport( 'joomla.error.error' );
jimport( 'joomla.filesystem.file' );
+require_once ( JPATH_COMPONENT_ADMINISTRATOR . DS . 'includes' . DS . 'plugin.php' );
+
class RaidPlannerHelper
{
private static $invite_alert_requested = false;
- public static function RosterSync( $guild_id , $sync_interval , $showOkStatus = false )
+ public static function getGuildPlugin( $guild_id )
{
$db = & JFactory::getDBO();
- $query = "SELECT *,(DATE_ADD(lastSync, INTERVAL " . intval( $sync_interval ) . " HOUR)-NOW()) AS needSync FROM #__raidplanner_guild WHERE guild_id=" . intval($guild_id);
+ $query = "SELECT guild_id, guild_name, sync_plugin, params FROM #__raidplanner_guild WHERE guild_id=" . intval($guild_id);
$db->setQuery($query);
- if ($tmp = $db->loadObject())
+ if ($guild = $db->loadObject()) {
+ $guild->params = json_decode( $guild->params, true );
+ $plug_class = "RaidPlannerPlugin" . ucfirst( $guild->sync_plugin);
+
+ JLoader::register( $plug_class, JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_raidplanner' . DS . 'plugins' . DS . $guild->sync_plugin . DS . $guild->sync_plugin . '.php' );
+
+ return new $plug_class( $guild_id, $guild->guild_name, $guild->params );
+ } else {
+ return null;
+ }
+ }
+
+ public static function RosterSync( $guild_id , $sync_interval , $showOkStatus = false )
+ {
+ if ( ($plugin = self::getGuildPlugin( $guild_id ) ) && ($plugin->needSync($sync_interval)) )
{
- $guild_id = $tmp->guild_id;
- $needsync = $tmp->needSync;
- $plug_class = $tmp->sync_plugin;
-
- if ( ( $needsync<=0 ) && ($plug_class != '') )
- {
- $tmp->params = json_decode($tmp->params, true);
-
- /* Load plugin */
-
- JLoader::register( $plug_class, JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_raidplanner' . DS . 'plugins' . DS . $plug_class . DS . $plug_class . '.php' );
-
- $sync_module = new $plug_class();
- $sync_module->Sync( $tmp, $sync_interval , $showOkStatus );
- }
+ $plugin->doSync( $showOkStatus );
}
}
View
54 administrator/com_raidplanner/includes/plugin.php
@@ -0,0 +1,54 @@
+<?php
+/*------------------------------------------------------------------------
+# RaidPlanner Sync Plugin master class
+# com_raidplanner - RaidPlanner Component
+# ------------------------------------------------------------------------
+# author Taracque
+# copyright Copyright (C) 2012 Taracque. All Rights Reserved.
+# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+# Website: http://www.taracque.hu/raidplanner
+-------------------------------------------------------------------------*/
+// no direct access
+defined( '_JEXEC' ) or die( 'Restricted access' );
+
+class RaidPlannerPlugin
+{
+ protected $params = array();
+ protected $guild_name = null;
+ protected $guild_id = null;
+
+ function __construct( $guild_id, $guild_name, $params)
+ {
+ $this->params = $params;
+ $this->guild_name = $guild_name;
+ $this->guild_id = $guild_id;
+ }
+
+ public function needSync( $sync_interval = 4)
+ {
+ $db = & JFactory::getDBO();
+ $query = "SELECT (DATE_ADD(lastSync, INTERVAL " . intval( $sync_interval ) . " HOUR)-NOW()) AS needSync FROM #__raidplanner_guild WHERE guild_id=" . intval($this->guild_id);
+ $db->setQuery($query);
+ if ( ($needsync = $db->loadResult()) && ( $needsync<0 ) )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public function doSync( $showOkStatus = false )
+ {
+ return false;
+ }
+
+ public function characterLink()
+ {
+ return "#";
+ }
+
+ public function guildHeader()
+ {
+ return "<h2>" . $this->guild_name . "</h2>";
+ }
+}
View
8 administrator/com_raidplanner/plugins/lotro/lotro.php
@@ -11,10 +11,14 @@
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
-class lotro
+class RaidPlannerPluginLotro extends RaidPlannerPlugin
{
+ function __construct( $guild_id, $guild_name, $params)
+ {
+ parent::__construct( $guild_id, $guild_name, $params);
+ }
- public function Sync( $guild_data , $sync_interval , $showOkStatus = false )
+ public function doSync( $showOkStatus = false )
{
$db = & JFactory::getDBO();
View
63 administrator/com_raidplanner/plugins/wow_armory/wow_armory.php
@@ -11,21 +11,24 @@
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
-class wow_armory
+class RaidPlannerPluginWow_armory extends RaidPlannerPlugin
{
- public function Sync( $guild_data , $sync_interval , $showOkStatus = false )
+ function __construct( $guild_id, $guild_name, $params)
+ {
+ parent::__construct( $guild_id, $guild_name, $params);
+ }
+
+ public function doSync( $showOkStatus = false )
{
$db = & JFactory::getDBO();
- $guild_id = $guild_data->guild_id;
-
- $region = $guild_data->params['guild_region'];
- $realm = $guild_data->params['guild_realm'];
+ $region = $this->params['guild_region'];
+ $realm = $this->params['guild_realm'];
$url = "http://" . $region . ".battle.net/api/wow/guild/";
$url .= rawurlencode( $realm ) . "/";
- $url .= rawurlencode( $guild_data->guild_name );
+ $url .= rawurlencode( $this->guild_name );
$url = $url . "?fields=members";
// Init cURL
@@ -59,15 +62,8 @@ public function Sync( $guild_data , $sync_interval , $showOkStatus = false )
JError::raiseWarning('100','ArmorySync failed');
return null;
}
- if (!$guild_id)
- {
- $query = "INSERT INTO #__raidplanner_guild (guild_name) VALUES (".$db->Quote($data->name).")";
- $db->setQuery($query);
- $db->query();
- $guild_id=$db->insertid();
- }
- if (($guild_data->guild_name == @$data->name) && ($data->name!=''))
+ if (($this->guild_name == @$data->name) && ($data->name!=''))
{
$params = array(
'achievementPoints' => $data->achievementPoints,
@@ -80,18 +76,18 @@ public function Sync( $guild_data , $sync_interval , $showOkStatus = false )
'guild_level' => $data->level
);
- $params = array_merge( $guild_data->params, $params );
+ $this->params = array_merge( $this->params, $params );
$query = "UPDATE #__raidplanner_guild SET
guild_name=".$db->Quote($data->name).",
params=".$db->Quote(json_encode($params)).",
lastSync=NOW()
- WHERE guild_id=".intval($guild_id);
+ WHERE guild_id=".intval($this->guild_id);
$db->setQuery($query);
$db->query();
/* detach characters from guild */
- $query = "UPDATE #__raidplanner_character SET guild_id=0 WHERE guild_id=".intval($guild_id)."";
+ $query = "UPDATE #__raidplanner_character SET guild_id=0 WHERE guild_id=".intval($this->guild_id)."";
$db->setQuery($query);
$db->query();
@@ -113,7 +109,7 @@ public function Sync( $guild_data , $sync_interval , $showOkStatus = false )
,gender_id='".(intval($member->character->gender) + 1)."'
,char_level='".intval($member->character->level)."'
,rank='".intval($member->rank)."'
- ,guild_id='".intval($guild_id)."'
+ ,guild_id='".intval($this->guild_id)."'
WHERE character_id=".$char_id;
$db->setQuery($query);
$db->query();
@@ -132,4 +128,33 @@ public function Sync( $guild_data , $sync_interval , $showOkStatus = false )
JError::raiseWarning('100', 'ArmorySync data doesn\'t match');
}
}
+
+ public function characterLink( $char_name )
+ {
+ return sprintf($this->params['char_link'], rawurlencode($this->params['guild_realm']), rawurlencode($char_name) ) . '" target="_blank';
+ }
+
+ public function guildHeader()
+ {
+ JHTML::script('guild-tabard.js', 'components/com_raidplanner/assets/');
+
+ $header = array();
+ $header[] = '<canvas id="rp_guild_tabard" width="120" height="120"></canvas>';
+ $header[] = '<script type="text/javascript">';
+ $header[] = ' window.addEvent("domready",function(){';
+ $header[] = ' var tabard = new GuildTabard("rp_guild_tabard", {';
+ $header[] = ' "ring": "' . $this->params['side'] . '",';
+ $header[] = ' "bg": [ 0, "' . $this->params['emblem']['backgroundColor'] . '" ], ';
+ $header[] = ' "border": [ "' . $this->params['emblem']['border'] . '", "' . $this->params['emblem']['borderColor'] . '" ], ';
+ $header[] = ' "emblem": [ "' . $this->params['emblem']['icon'] . '", "' . $this->params['emblem']['iconColor'] . '" ], ';
+ $header[] = ' }, "' . JURI::base() . 'images/raidplanner/tabards/");';
+ $header[] = ' });';
+ $header[] = '</script>';
+ $header[] = '<h2><a href="' . $this->params['link'] . '" target="_blank">' . $this->guild_name . '</a></h2>';
+ $header[] = '<strong>' . JText::_('COM_RAIDPLANNER_LEVEL') . " " . $this->params['guild_level'] . " " . $this->params['side'] . " " . JText::_('COM_RAIDPLANNER_GUILD') . '<br />';
+ $header[] = $this->params['guild_realm'] . " - " . strtoupper($this->params['guild_region']) . '</strong>';
+
+ return implode("\n", $header);
+ }
+
}
View
10 com_raidplanner/models/roster.php
@@ -46,16 +46,6 @@ public function getGuildInfo($guild_id = null)
$tmp = $db->loadObject();
$tmp->params = json_decode($tmp->params);
- if ( (!isset($tmp->params)) || ($tmp->params->emblem == null) )
- {
- $tmp->params->side = '';
- $tmp->params->char_link = '#';
- $tmp->params->link='#';
- $tmp->params->armory = false;
- } else {
- $tmp->params->armory = true;
- }
-
return ( $tmp );
}
View
29 com_raidplanner/views/roster/tmpl/default.php
@@ -54,27 +54,7 @@ classHeaderFilterContorlDiv:'rp_filter'
}
});
</script>
- <?php if ($this->guildinfo->params->armory): ?>
- <canvas id="rp_guild_tabard" width="120" height="120">
- </canvas>
- <script type="text/javascript">
- window.addEvent('domready',function(){
- var tabard = new GuildTabard('rp_guild_tabard', {
- 'ring': '<?php echo $this->guildinfo->params->side;?>',
- 'bg': [ 0, '<?php echo $this->guildinfo->params->emblem->backgroundColor;?>' ],
- 'border': [ <?php echo $this->guildinfo->params->emblem->border;?>, '<?php echo $this->guildinfo->params->emblem->borderColor;?>' ],
- 'emblem': [ <?php echo $this->guildinfo->params->emblem->icon;?>, '<?php echo $this->guildinfo->params->emblem->iconColor;?>' ]
- }, '<?php echo JURI::base();?>images/raidplanner/tabards/');
- });
- </script>
- <?php endif; ?>
- <h2><a href="<?php echo @$this->guildinfo->params->link;?>"<?php if ($this->guildinfo->params->armory) {?> target="_blank"<?php } ?>><?php echo $this->guildinfo->guild_name;?></a></h2>
- <?php if ($this->guildinfo->params->armory): ?>
- <strong>
- <?php echo JText::_('COM_RAIDPLANNER_LEVEL');?> <?php echo $this->guildinfo->params->guild_level;?> <?php echo @$this->guildinfo->params->side;?> <?php echo JText::_('COM_RAIDPLANNER_GUILD');?><br />
- <?php echo @$this->guildinfo->params->guild_realm;?> - <?php echo strtoupper(@$this->guildinfo->params->guild_region);?>
- </strong>
- <?php endif; ?>
+ <?php echo $this->guild_plugin->guildHeader(); ?>
</div>
<div class="rp_roster_table">
<table class="rp_container" id="roster_table">
@@ -95,12 +75,7 @@ classHeaderFilterContorlDiv:'rp_filter'
<?php foreach($this->characters as $character) : ?>
<tr class="rp_roster">
<td>
- <?php if ($this->guildinfo->params->armory) :?>
- <a href="<?php echo sprintf($this->guildinfo->params->char_link, rawurlencode($this->guildinfo->params->guild_realm), rawurlencode($character['char_name']) );?>" target="_blank">
- <?php else: ?>
- <a href="javascript:return(false);">
- <?php endif; ?>
- <?php echo $character['char_name']; ?></a>
+ <a href="<?php echo $this->guild_plugin->characterLink($character['char_name']);?>"><?php echo $character['char_name']; ?></a>
</td>
<?php if ($this->show_account == 1) : ?>
<td><a href="<?php echo "#";?>"><?php echo $character['username'];?></a>
View
7 com_raidplanner/views/roster/view.html.php
@@ -19,7 +19,6 @@
JHTML::script('mootools.more.125.additional.js', 'components/com_raidplanner/assets/');
}
JHTML::script('HtmlTable.Extended.js', 'components/com_raidplanner/assets/');
-JHTML::script('guild-tabard.js', 'components/com_raidplanner/assets/');
class RaidPlannerViewRoster extends JView
{
@@ -37,12 +36,14 @@ function display($tpl = null)
$guild_id = $paramsObj->get('guild_id', '0');
$show_account = $paramsObj->get('show_account', '0');
- if ($paramsObj->get('armory_sync', '0') == 1)
+ $guild_plugin = RaidPlannerHelper::getGuildPlugin( $guild_id );
+ if (($paramsObj->get('armory_sync', '0') == 1) && ($guild_plugin) && ($guild_plugin->needSync( $paramsObj->get( 'sync_interval', 4 ) ) ))
{
// sync armory
- RaidPlannerHelper::RosterSync( $guild_id, $paramsObj->get( 'sync_interval', 4 ) );
+ $guild_plugin->doSync();
}
+ $this->assignRef( 'guild_plugin', $guild_plugin );
$this->assignRef( 'characters', $model->getGuildCharacters( $guild_id ) );
$this->assignRef( 'guildinfo', $model->getGuildInfo( $guild_id ) );
$this->assignRef( 'ranks', RaidPlannerHelper::getRanks() );
View
5 manifest.xml
@@ -8,8 +8,8 @@
<authorUrl>http://taracque.hu</authorUrl>
<copyright>Copyright Info</copyright>
<license>http://www.gnu.org/licenseses/gpl-2.0.html GNU/GPL</license>
- <version>0.6.2</version>
- <releaseDate>2012-04-21</releaseDate>
+ <version>0.6.3</version>
+ <releaseDate>2012-04-27</releaseDate>
<releaseType>Bugfix release</releaseType>
<downloadUrl>https://nodeload.github.com/Taracque/RaidPlanner/zipball/master</downloadUrl>
<!-- The description is optional and defaults to the name -->
@@ -80,6 +80,7 @@
<filename>controller.php</filename>
<filename>config.xml</filename>
<folder>assets</folder>
+ <folder>includes</folder>
<folder>models</folder>
<folder>views</folder>
<folder>controllers</folder>
View
6 raidplanner-updates.xml
@@ -5,7 +5,7 @@
<description>RaidPlanner Component</description>
<element>com_raidplanner</element>
<type>component</type>
- <version>0.6.2</version>
+ <version>0.6.3</version>
<client_id>1</client_id>
<infourl title="RaidPlanner URL">http://taracque.hu/raidplanner</infourl>
@@ -22,7 +22,7 @@
<description>RaidPlanner Component</description>
<element>com_raidplanner</element>
<type>component</type>
- <version>0.6.2</version>
+ <version>0.6.3</version>
<client_id>1</client_id>
<infourl title="RaidPlanner URL">http://taracque.hu/raidplanner</infourl>
@@ -39,7 +39,7 @@
<description>RaidPlanner Component</description>
<element>com_raidplanner</element>
<type>component</type>
- <version>0.6.2</version>
+ <version>0.6.3</version>
<client_id>1</client_id>
<infourl title="RaidPlanner URL">http://taracque.hu/raidplanner</infourl>

0 comments on commit c66f78f

Please sign in to comment.
Something went wrong with that request. Please try again.