-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0dfa016
commit f74e93e
Showing
8 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
use DateTime; | ||
use hipanel\modules\server\models\Server; | ||
use hipanel\modules\finance\cart\AbstractCartPosition; | ||
use Yii; | ||
|
||
abstract class AbstractServerProduct extends AbstractCartPosition | ||
{ | ||
/** | ||
* @var Server | ||
*/ | ||
protected $_model; | ||
|
||
/** | ||
* @var string the operation name | ||
*/ | ||
protected $_operation; | ||
|
||
/** {@inheritdoc} */ | ||
protected $_calculationModel = Calculation::class; | ||
|
||
/** {@inheritdoc} */ | ||
public function getIcon() | ||
{ | ||
return '<i class="fa fa-server"></i>'; | ||
} | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
[['name'], 'required'], | ||
]; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getQuantityOptions() | ||
{ | ||
$result = []; | ||
foreach ([1, 3, 6, 12] as $n) { | ||
$date = (new DateTime($this->_model->expires))->add(new \DateInterval("P{$n}M")); | ||
|
||
$result[$n] = Yii::t('hipanel/server', '{n, plural, one{# month} other{# months}} till {date}', [ | ||
'n' => $n, | ||
'date' => Yii::$app->formatter->asDate($date) | ||
]); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getCalculationModel($options = []) | ||
{ | ||
return parent::getCalculationModel(array_merge([ | ||
'type' => $this->_operation, | ||
'server' => $this->name, | ||
'expires' => $this->_model->expires, | ||
], $options)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
/** | ||
* Abstract class AbstractServerPurchase. | ||
*/ | ||
abstract class AbstractServerPurchase extends \hipanel\modules\finance\cart\AbstractPurchase | ||
{ | ||
use \hipanel\base\ModelTrait; | ||
|
||
/** {@inheritdoc} */ | ||
public static function type() | ||
{ | ||
return 'server'; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$this->server = $this->position->name; | ||
$this->amount = $this->position->getQuantity(); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['server', 'expires'], 'safe'], | ||
[['amount'], 'number'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
class Calculation extends \hipanel\modules\finance\models\Calculation | ||
{ | ||
use \hipanel\base\ModelTrait; | ||
|
||
/** {@inheritdoc} */ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$this->client = $this->position->getModel()->client; | ||
$this->seller = $this->position->getModel()->seller; | ||
$this->object = 'server'; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['server', 'expires'], 'safe'], | ||
[['id'], 'integer'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* | ||
* Domain plugin for HiPanel | ||
* | ||
* @link https://github.com/hiqdev/hipanel-module-domain | ||
* @package hipanel-module-domain | ||
* @license BSD-3-Clause | ||
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
use hipanel\modules\server\models\Server; | ||
use Yii; | ||
|
||
class ServerRenewProduct extends AbstractServerProduct | ||
{ | ||
/** {@inheritdoc} */ | ||
protected $_purchaseModel = 'hipanel\modules\server\cart\ServerRenewPurchase'; | ||
|
||
/** {@inheritdoc} */ | ||
protected $_operation = 'renew'; | ||
|
||
/** {@inheritdoc} */ | ||
public static function primaryKey() | ||
{ | ||
return ['model_id']; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function load($data, $formName = null) | ||
{ | ||
$result = parent::load($data, ''); | ||
if ($result) { | ||
$this->loadRelatedData(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
private function loadRelatedData() | ||
{ | ||
$this->_model = Server::findOne(['id' => $this->model_id]); | ||
$this->name = $this->_model->name; | ||
$this->description = Yii::t('hipanel/server', 'Renewal'); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getId() | ||
{ | ||
return hash('crc32b', implode('_', ['server', 'renew', $this->_model->id])); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getCalculationModel($options = []) | ||
{ | ||
return parent::getCalculationModel(array_merge([ | ||
'id' => $this->model_id, | ||
], $options)); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getPurchaseModel($options = []) | ||
{ | ||
$this->loadRelatedData(); // To get fresh domain expiration date | ||
return parent::getPurchaseModel(array_merge(['expires' => $this->_model->expires], $options)); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['model_id'], 'integer'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
class ServerRenewPurchase extends AbstractServerPurchase | ||
{ | ||
/** {@inheritdoc} */ | ||
public static function operation() | ||
{ | ||
return 'Renew'; | ||
} | ||
|
||
/** | ||
* @var string domain expiration datetime | ||
*/ | ||
public $expires; | ||
|
||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['expires'], 'required'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters