diff --git a/web_upload/application/plugins/SourceComms/CommsPlugin.php b/web_upload/application/plugins/SourceComms/CommsPlugin.php index 4adc710..a4183b0 100644 --- a/web_upload/application/plugins/SourceComms/CommsPlugin.php +++ b/web_upload/application/plugins/SourceComms/CommsPlugin.php @@ -18,7 +18,7 @@ public function getAuthor() public function getVersion() { - return '1.0.727'; + return '1.0.735'; } public function getUrl() diff --git a/web_upload/application/plugins/SourceComms/controllers/CommsController.php b/web_upload/application/plugins/SourceComms/controllers/CommsController.php index 91c744a..670ce26 100644 --- a/web_upload/application/plugins/SourceComms/controllers/CommsController.php +++ b/web_upload/application/plugins/SourceComms/controllers/CommsController.php @@ -19,6 +19,7 @@ class CommsController extends Controller */ protected static $availableModels = array( 'OldComms', + 'ExtendedComm', 'Comms', ); @@ -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) { diff --git a/web_upload/application/plugins/SourceComms/messages/cs/main.php b/web_upload/application/plugins/SourceComms/messages/cs/main.php index 57ce43b..b8c20e5 100644 --- a/web_upload/application/plugins/SourceComms/messages/cs/main.php +++ b/web_upload/application/plugins/SourceComms/messages/cs/main.php @@ -29,6 +29,7 @@ 'Import' => '', 'Import completed' => '', 'Import punishments' => '', + 'Imported from ExtendedComm' => '', 'Imported from previous SourceComms version' => '', 'Imported from same SourceComms version' => '', 'Mute' => '', diff --git a/web_upload/application/plugins/SourceComms/messages/de/main.php b/web_upload/application/plugins/SourceComms/messages/de/main.php index 57ce43b..b8c20e5 100644 --- a/web_upload/application/plugins/SourceComms/messages/de/main.php +++ b/web_upload/application/plugins/SourceComms/messages/de/main.php @@ -29,6 +29,7 @@ 'Import' => '', 'Import completed' => '', 'Import punishments' => '', + 'Imported from ExtendedComm' => '', 'Imported from previous SourceComms version' => '', 'Imported from same SourceComms version' => '', 'Mute' => '', diff --git a/web_upload/application/plugins/SourceComms/messages/en/main.php b/web_upload/application/plugins/SourceComms/messages/en/main.php index 0639c24..a3a162c 100644 --- a/web_upload/application/plugins/SourceComms/messages/en/main.php +++ b/web_upload/application/plugins/SourceComms/messages/en/main.php @@ -29,6 +29,7 @@ 'Import' => '', 'Import completed' => '', 'Import punishments' => '', + 'Imported from ExtendedComm' => '', 'Imported from previous SourceComms version' => '', 'Imported from same SourceComms version' => '', 'Mute' => '', diff --git a/web_upload/application/plugins/SourceComms/messages/nl/main.php b/web_upload/application/plugins/SourceComms/messages/nl/main.php index fc21e90..4e5972d 100644 --- a/web_upload/application/plugins/SourceComms/messages/nl/main.php +++ b/web_upload/application/plugins/SourceComms/messages/nl/main.php @@ -29,6 +29,7 @@ 'Import' => '', 'Import completed' => '', 'Import punishments' => '', + 'Imported from ExtendedComm' => '', 'Imported from previous SourceComms version' => '', 'Imported from same SourceComms version' => '', 'Mute' => 'Dempen', diff --git a/web_upload/application/plugins/SourceComms/messages/pl/main.php b/web_upload/application/plugins/SourceComms/messages/pl/main.php index 57ce43b..b8c20e5 100644 --- a/web_upload/application/plugins/SourceComms/messages/pl/main.php +++ b/web_upload/application/plugins/SourceComms/messages/pl/main.php @@ -29,6 +29,7 @@ 'Import' => '', 'Import completed' => '', 'Import punishments' => '', + 'Imported from ExtendedComm' => '', 'Imported from previous SourceComms version' => '', 'Imported from same SourceComms version' => '', 'Mute' => '', diff --git a/web_upload/application/plugins/SourceComms/messages/pt_br/main.php b/web_upload/application/plugins/SourceComms/messages/pt_br/main.php index 57ce43b..b8c20e5 100644 --- a/web_upload/application/plugins/SourceComms/messages/pt_br/main.php +++ b/web_upload/application/plugins/SourceComms/messages/pt_br/main.php @@ -29,6 +29,7 @@ 'Import' => '', 'Import completed' => '', 'Import punishments' => '', + 'Imported from ExtendedComm' => '', 'Imported from previous SourceComms version' => '', 'Imported from same SourceComms version' => '', 'Mute' => '', diff --git a/web_upload/application/plugins/SourceComms/messages/ru/main.php b/web_upload/application/plugins/SourceComms/messages/ru/main.php index 10c2c80..540b498 100644 --- a/web_upload/application/plugins/SourceComms/messages/ru/main.php +++ b/web_upload/application/plugins/SourceComms/messages/ru/main.php @@ -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' => 'Микрофон', diff --git a/web_upload/application/plugins/SourceComms/models/Comms.php b/web_upload/application/plugins/SourceComms/models/Comms.php index 4533a70..b79f636 100644 --- a/web_upload/application/plugins/SourceComms/models/Comms.php +++ b/web_upload/application/plugins/SourceComms/models/Comms.php @@ -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. */ diff --git a/web_upload/application/plugins/SourceComms/models/ExtendedComm.php b/web_upload/application/plugins/SourceComms/models/ExtendedComm.php new file mode 100644 index 0000000..0d20523 --- /dev/null +++ b/web_upload/application/plugins/SourceComms/models/ExtendedComm.php @@ -0,0 +1,247 @@ +_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), + ), + ); + } +} diff --git a/web_upload/application/plugins/SourceComms/models/OldComms.php b/web_upload/application/plugins/SourceComms/models/OldComms.php index 9eb62a1..4b59780 100644 --- a/web_upload/application/plugins/SourceComms/models/OldComms.php +++ b/web_upload/application/plugins/SourceComms/models/OldComms.php @@ -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. */