Skip to content

Commit

Permalink
Added draft model for converting from extendedcomm
Browse files Browse the repository at this point in the history
Relates #36
  • Loading branch information
Alexandr D committed Jan 12, 2014
1 parent e32b8e1 commit 44fe8c3
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web_upload/application/plugins/SourceComms/CommsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getAuthor()

public function getVersion()
{
return '1.0.727';
return '1.0.735';
}

public function getUrl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CommsController extends Controller
*/
protected static $availableModels = array(
'OldComms',
'ExtendedComm',
'Comms',
);

Expand Down Expand Up @@ -297,7 +298,7 @@ public function actionImport()
$criteria = new CDbCriteria();
$criteria->offset = $offset;
$criteria->limit = self::ITEMS_PER_ITERATION;
$data = $model->with('admin','server','unban_admin')->FindAll($criteria);
$data = $model->with($modelName::$availableRelations)->FindAll($criteria);

if (!$data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Import' => '',
'Import completed' => '',
'Import punishments' => '',
'Imported from ExtendedComm' => '',
'Imported from previous SourceComms version' => '',
'Imported from same SourceComms version' => '',
'Mute' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Import' => '',
'Import completed' => '',
'Import punishments' => '',
'Imported from ExtendedComm' => '',
'Imported from previous SourceComms version' => '',
'Imported from same SourceComms version' => '',
'Mute' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Import' => '',
'Import completed' => '',
'Import punishments' => '',
'Imported from ExtendedComm' => '',
'Imported from previous SourceComms version' => '',
'Imported from same SourceComms version' => '',
'Mute' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Import' => '',
'Import completed' => '',
'Import punishments' => '',
'Imported from ExtendedComm' => '',
'Imported from previous SourceComms version' => '',
'Imported from same SourceComms version' => '',
'Mute' => 'Dempen',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Import' => '',
'Import completed' => '',
'Import punishments' => '',
'Imported from ExtendedComm' => '',
'Imported from previous SourceComms version' => '',
'Imported from same SourceComms version' => '',
'Mute' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'Import' => '',
'Import completed' => '',
'Import punishments' => '',
'Imported from ExtendedComm' => '',
'Imported from previous SourceComms version' => '',
'Imported from same SourceComms version' => '',
'Mute' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'Import' => 'Импортировать',
'Import completed' => 'Импорт завершен',
'Import punishments' => 'Импортировать блокировки',
'Imported from ExtendedComm' => 'Импортировано из ExtendedComm',
'Imported from previous SourceComms version' => 'Импортировано из SourceComms предыдущей версии',
'Imported from same SourceComms version' => 'Импортировано из SourceComms аналогичной версии',
'Mute' => 'Микрофон',
Expand Down
5 changes: 5 additions & 0 deletions web_upload/application/plugins/SourceComms/models/Comms.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public function rules()
);
}

/**
* @var $availableRelations - Array of relations which could be used at import
*/
public static $availableRelations = array('admin','server','unban_admin');

/**
* @return array relational rules.
*/
Expand Down
247 changes: 247 additions & 0 deletions web_upload/application/plugins/SourceComms/models/ExtendedComm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
<?php
/**
* This is the model class for old sourcecomms table.
*
* @author Alex
* @copyright (C)2014 Alexandr Duplishchev.
* @link https://github.com/d-ai/SourceComms
*
* The followings are the available columns in table 'extendedcomm':
* @property integer $bid ID
* @property string $authid SteamID
* @property string $name Name
* @property integer $created creation Date/Time
* @property integer $ends ends Date/Time
* @property integer $length Length in seconds
* @property string $reason Reason
* @property integer $aid Admin ID
* @property string $adminIp Admin IP address
* @property integer $sid Server ID
* @property integer $RemovedBy Unbanned by Admin ID
* @property string $RemoveType Unban type
* @property integer $RemovedOn Unbanned on Date/Time
* @property integer $type Type
* @property string $ureason Unban reason
*
* The followings are the available model relations:
* @property SBAdmin $admin Admin
* @property SBServer $server Server
* @property SBAdmin $unban_admin Unban admin
*/
class ExtendedComm extends CActiveRecord
{
const GAG_TYPE = 2;
const MUTE_TYPE = 1;
const COMM_TIME = 1;
const COMM_PERM = 2;

/**
* @var $_tableName - Name of table which is associated with model
*/
protected $_tableName;

/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Comms the static model class
*/
public static function model($className=__CLASS__, $table)
{
return parent::model($className);
}

/**
* Constructor.
* @param $scenario - scenario name
* @param $tableName - name of source table for creating model.
*/
public function __construct($scenario = 'insert', $tableName = null)
{
$this->_tableName = $tableName;
parent::__construct($scenario);
}

/**
* @return string the associated database table name
*/
public function tableName()
{
if ($this->_tableName)
return $this->_tableName;
else
return 'extendedcomm';
}

/**
* Checks table in the database for the compatibility with this model.
* @param string $table - name of table for check
* @return boolean - whether the table is compatible
*/
public static function isTableValidForModel($table)
{
return in_array($table, Yii::app()->db->getSchema()->getTableNames(), true)
&& Yii::app()->db->getSchema()->getTable($table)->getColumnNames()
=== array('steam_id',
'mute_type',
'mute_length',
'mute_admin',
'mute_time',
'mute_reason',
'mute_level',
'gag_type',
'gag_length',
'gag_admin',
'gag_time',
'gag_reason',
'gag_level',
);
}

/**
* @var $availableRelations - Array of relations which could be used at import
*/
public static $availableRelations = array();

/**
* @var integer punishment type
* @return boolean - whether the record is valid
*/
private function isValid($type)
{
return preg_match(SourceBans::STEAM_PATTERN, $this->steam_id)
&& ( $type == self::GAG_TYPE
&& ($this->gag_type == self::COMM_TIME
|| $this->gag_type == self::COMM_PERM)
|| $type == self::MUTE_TYPE
&& ($this->mute_type == self::COMM_TIME
|| $this->mute_type == self::COMM_PERM)
);
}

/**
* @return integer steam account id
*/
public function getSteamAccountID()
{
return substr($this->steam_id, 8, 1) + 2 * substr($this->steam_id, 10, 10);
}

/**
* @var integer punishment type
* @return integer length of punishment in minutes
*/
private function getLength($type)
{
switch ($type)
{
case self::GAG_TYPE:
$length = $this->gag_length;
break;
case self::MUTE_TYPE:
$length = $this->mute_length;
break;
default:
$length = -1;
break;
}

if ($length > 0)
return (int) $length / 60;
else if ($length == 0)
return 0;
else
return -1;
}

/**
* @var integer punishment type
* @return integer creation time
*/
private function getCreateTime($type)
{
switch ($type)
{
case self::GAG_TYPE:
return $this->gag_time;
case self::MUTE_TYPE:
return $this->mute_time;
default:
return null;
}
}

/**
* @var integer punishment type
* @return string punishment reason
*/
private function getReason($type)
{
switch ($type)
{
case self::GAG_TYPE:
return $this->gag_reason;
case self::MUTE_TYPE:
return $this->mute_reason;
default:
return null;
}
}

/**
* @var integer punishment type
* @return array attributes for search the related Comms model
*/
private function getAttributesForSearch($type)
{
if ($this->isValid($type))
return array(
'type' => $type,
'steam_account_id' => $this->getSteamAccountID(),
'create_time' => $this->getCreateTime($type),
);
else
return null;
}

/**
* @var integer punishment type
* @return array attributes for saving to new Comms record
*/
private function getAttributesForSave($type)
{
if ($this->isValid($type))
return array(
'type' => $type,
'steam_account_id' => $this->getSteamAccountID(),
'name' => null,
'reason' => $this->getReason($type) ? $this->getReason($type) : Yii::t('CommsPlugin.main', 'Imported from ExtendedComm'),
'length' => $this->getLength($type),
'server_id' => null,
'admin_id' => null,
'admin_ip' => $_SERVER['SERVER_ADDR'],
'unban_admin_id' => null,
'unban_reason' => null,
'unban_time' => null,
'create_time' => $this->getCreateTime($type),
);
else
return null;
}

/**
* @return array of arrays of attributes for search and saving Comms model
*/
public function getDataForImport()
{
return array(
array(
'search' => $this->getAttributesForSearch(self::GAG_TYPE),
'save' => $this->getAttributesForSave(self::GAG_TYPE),
),
array(
'search' => $this->getAttributesForSearch(self::MUTE_TYPE),
'save' => $this->getAttributesForSave(self::MUTE_TYPE),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public static function isTableValidForModel($table)
);
}

/**
* @var $availableRelations - Array of relations which could be used at import
*/
public static $availableRelations = array('admin','server','unban_admin');

/**
* @return array relational rules.
*/
Expand Down

0 comments on commit 44fe8c3

Please sign in to comment.