Skip to content

Commit

Permalink
Merge pull request #4 from WajoxSoftware/extract-payment-module
Browse files Browse the repository at this point in the history
Extract payment module
  • Loading branch information
ildarusmanov authored Apr 6, 2017
2 parents df0acf1 + fea09d2 commit c8576da
Show file tree
Hide file tree
Showing 352 changed files with 2,209 additions and 2,953 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/vendor/
.php_cs.cache

1 change: 0 additions & 1 deletion .php_cs.cache

This file was deleted.

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"yiisoft/yii2-swiftmailer": "*",
"yiidoc/yii2-redactor": "*",
"yii-dream-team/yii2-upload-behavior": "*",
"wajox/y2modcms": "dev-master",
"baibaratsky/yii2-serialized-attributes-behavior": "*",
"2amigos/yii2-date-picker-widget" : "~1.0",
"2amigos/yii2-date-time-picker-widget" : "~1.0",
Expand All @@ -27,8 +28,8 @@
"kartik-v/yii2-widgets": "dev-master",
"picodi-lab/expertsender-api-client": "*",
"wajox/yii2widgets": "dev-master",
"wajox/y2modcms": "dev-master",
"codemix/yii2-localeurls": "*"
"codemix/yii2-localeurls": "*",
"bower-asset/bootstrap-material-design": "*"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/assets-src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ var HtmlWidgets = function() {


this.init = function() {
$('table.table').stacktable();
// $('table.table').stacktable();
this.bindEvents();
this.renderAll();
};
Expand Down
1 change: 1 addition & 0 deletions src/assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AppAsset extends AssetBundle
'js/app.js',
'js/statistic.js',
];

public $depends = [
'yii\web\YiiAsset',
//'yii\bootstrap\BootstrapAsset',
Expand Down
23 changes: 23 additions & 0 deletions src/commands/ActionLogsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace wajox\yii2base\commands;

use yii\console\Controller;

class ActionLogsController extends Controller
{
public function actionCreate($typeId, $itemId, $userId, $jsonParams)
{
$user = \Yii::$app
->usersManager
->findById($userId);

\Yii::$app
->actionLogs
->log(
$typeId,
$itemId,
$userId,
json_decode($jsonParams, true)
);
}
}
2 changes: 1 addition & 1 deletion src/commands/SenderSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function actionCreate()
protected function getSettings()
{
$params = [
'endpoint_url' => 'https://api2.esv2.com',
'endpoint_url' => 'https://api2.esv2.com/Api/',
'api_key' => '5RhLodq9D9oEhHVduhpv',
'transactional_id' => '37',
'base_list_id' => '5',
Expand Down
5 changes: 3 additions & 2 deletions src/commands/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class UsersController extends Controller
{
public function actionCreate()
{
$manager = new UsersManager();
$model = new User(['scenario' => 'signup']);
$model->first_name = 'Jhon';
$model->last_name = 'Doe';
Expand All @@ -22,7 +21,9 @@ public function actionCreate()
$model->guid = md5(uniqid(time(), true));
$model->created_at = time();

$model = $manager->save($model, false, false);
$model = \Yii::$app
->usersManager
->save($model, false, false);

if ($model && !$model->isNewRecord) {
return true;
Expand Down
29 changes: 29 additions & 0 deletions src/components/console/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace wajox\yii2base\components\console;

class Command
{
protected $command;
protected $params = [];

public function __construct($command, $params = [])
{
$this->command = $command;
$this->params = $params;
}

public function run($async = false)
{
$params = [];
foreach ($this->params as $key => $param) {
$params[$key] = '"' . $param . '"';
}

$cmd = 'php ' . \Yii::getAlias('@app/yii')
. ' ' . $this->command
. ' ' . implode(' ', $params);
. ($async ? ' >> /dev/null &' : '');

return shell_exec($cmd);
}
}
12 changes: 12 additions & 0 deletions src/components/console/CommandsManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace wajox\yii2base\components\console;

use wajox\yii2base\components\base\Object;

class CommandsManager extends Object
{
public function run($cmd, $params, $async = false)
{
return (new Command($cmd, $params))->run($async);
}
}
5 changes: 5 additions & 0 deletions src/components/db/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

class ActiveQuery extends \yii\db\ActiveQuery
{
public function byIds(array $ids): ActiveQuery
{
return $this->where(['id' => array_filter($ids, 'intval')]);
}

public function byId(int $id): ActiveQuery
{
return $this->where(['id' => intval($id)]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/db/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public static function find(): ActiveQuery
public function hasOne($class, $link)
{
return parent::hasOne(
$this->getDepencency($class),
$this->getDependency($class),
$link
);
}

public function hasMany($class, $link)
{
return parent::hasMany(
$this->getDepencency($class),
$this->getDependency($class),
$link
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/ConfirmationController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
namespace wajox\yii2base\controllers;

use Yii;
use wajox\yii2base\models\form\ConfirmationForm;
use wajox\yii2base\models\User;
use wajox\yii2base\services\users\UsersManager;

class ConfirmationController extends \wajox\yii2base\controllers\Controller
{
Expand Down Expand Up @@ -57,7 +55,7 @@ public function actionConfirm($token)

public function getManager()
{
return $this->getDependency(UsersManager::className());
return $this->getApp()->usersManager;
;
}
}
2 changes: 1 addition & 1 deletion src/controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function findModelById($className, $id)
{
$model = $this
->getRepository()
->find($className())
->find($className)
->byId($id)
->one();

Expand Down
3 changes: 1 addition & 2 deletions src/controllers/RegistrationControllerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use Yii;
use yii\filters\AccessControl;
use wajox\yii2base\services\users\UsersManager;
use wajox\yii2base\models\form\PartnerRegistrationForm;

abstract class RegistrationControllerAbstract extends \wajox\yii2base\controllers\Controller
Expand Down Expand Up @@ -62,7 +61,7 @@ protected function getRegistrationForm()

protected function getUsersManager()
{
return $this->getDependency(UsersManager::className());
return $this->getApp()->usersManager;
}

abstract protected function goDashboard();
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/SessionControllerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Yii;
use yii\filters\AccessControl;
use wajox\yii2base\models\form\LoginForm;
use wajox\yii2base\services\users\UsersManager;
use wajox\yii2base\services\wajox_software\NetworkAccountsManager;

abstract class SessionControllerAbstract extends \wajox\yii2base\controllers\Controller
Expand Down Expand Up @@ -93,7 +92,7 @@ protected function getLoginForm()

protected function getUsersManager()
{
return $this->getDependency(UsersManager::className());
return $this->getApp()->usersManager;
}

protected function getNetworkAccountManager()
Expand Down
96 changes: 33 additions & 63 deletions src/controllers/TrafficStreamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,26 @@

class TrafficStreamsController extends Controller
{
public function actionView($id, $tag = null)
public function actionView($sourceTag, $streamTag = null)
{
$model = $this->findModel($id);
$source = $this->findSourceByTag($sourceTag);
$stream = $this->findStreamByTag($source->id, $streamTag);

$isIternalRedirect = $this->isInternalRedirect($model);
$targetUrl = $this->getTargetUrl($model);
$this->registerStream($stream);

$this->registerStream($model, $tag, $isIternalRedirect);

return $this->redirect($targetUrl);
}

protected function getSubaccount($user, $tag)
{
$subaccountsManager = $this->getSubaccountsManager($user);
$subaccount = $subaccountsManager->getSubaccount($tag);

return $subaccount;
return $this->redirect($source->getTargetUrl());
}

protected function findModel($id)
protected function findSourceByTag($tag)
{
$conditions = [
'id' => $id,
'status_id' => TrafficStream::STATUS_ID_ACTIVE,
'tag' => $tag,
'status_id' => TrafficSource::STATUS_ID_ACTIVE,
];

$model = $this
->getRepository()
->find(TrafficStream::className())
->find(TrafficSource::className())
->where($conditions)
->one();

Expand All @@ -51,57 +41,37 @@ protected function findModel($id)
throw new NotFoundHttpException('The requested page does not exist.');
}

protected function registerStream($model, $tag, $isIternalRedirect)
{
$subaccount = $this->getSubaccount($model->user, $tag);

$this->getApp()->visitor->setUserSubaccount($subaccount);
$this->getApp()->visitor->setTrafficStream($model);

if ($isIternalRedirect) {
return;
}

$this->getClicksManager()->save();
}

protected function isInternalRedirect($model)
{
$converter = $this->getUrlConverter();

$url = $converter->extract($model->target_url);

return is_array($url);
}

protected function getTargetUrl($model)
protected function findStreamByTag($source, $tag)
{
$converter = $this->getUrlConverter();

$url = $converter->extract($model->target_url);
$conditions = [
'full_tag' => $tag,
'status_id' => TrafficStream::STATUS_ID_ACTIVE,
'traffic_source_id' => $source->id,
];

if (!is_array($url)) {
return $url;
}
$model = $this
->getRepository()
->find(TrafficStream::className())
->where($conditions)
->one();

if (isset($url['model']) && $url['model'] != null) {
return Url::toRoute([
'/shop/goods/view',
'url' => $url['model']->url,
]);
if ($model !== null) {
return $model;
}

throw new NotFoundHttpException('Unknown target url');
}

protected function getUrlConverter()
{
return $this->getDependency(UrlConverter::className());

throw new NotFoundHttpException('The requested page does not exist.');
}

protected function getSubaccountsManager($user)
protected function registerStream($stream)
{
return $this->createObject(SubaccountsManager::className(), [$user]);
$this
->getApp()
->visitor
->setTrafficStream($stream);

$this
->getClicksManager()
->save();
}

protected function getClicksManager()
Expand Down
13 changes: 13 additions & 0 deletions src/events/EmailListEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace wajox\yii2base\events;

use yii\base\Event;

class EmailListEvent extends Event
{
const EVENT_SUBSCRIBE = 'subscribed';
const EVENT_UNSUBSCRIBE = 'unsubscribed';

public $emailList;
public $subscribe;
}
13 changes: 13 additions & 0 deletions src/events/MessageUserStatusEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace wajox\yii2base\events;

use yii\base\Event;

class MessageUserStatusEvent extends Event
{
const EVENT_CREATED = 'created';
const EVENT_READ = 'read';
const EVENT_DELETED = 'deleted';

public $messageUserStatus;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace wajox\yii2base\services\events\types;
namespace wajox\yii2base\events;

use yii\base\Event;

class StatisticEvent extends Event
{
const EVENT_NEW = 'new_view';
const EVENT_NEW = 'view';

public $statistic;
}
Loading

0 comments on commit c8576da

Please sign in to comment.