Skip to content

Instantly share code, notes, and snippets.

@voskobovich
Created January 13, 2017 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voskobovich/5d87b770542f8c78eab9bf094d72bb70 to your computer and use it in GitHub Desktop.
Save voskobovich/5d87b770542f8c78eab9bf094d72bb70 to your computer and use it in GitHub Desktop.
<?php
namespace dashboard\controllers;
use dashboard\extensions\Controller;
use dashboard\forms\CompanyDeliveryMethodsSearchForm;
use dashboard\forms\CompanyOrderStatusesSearchForm;
use dashboard\forms\CompanyPaymentMethodsSearchForm;
use dashboard\forms\CompanyPhotoDeleteForm;
use dashboard\forms\CompanyPhotoForm;
use dashboard\forms\CompanyTariffForm;
use dashboard\forms\CompanyTransactionsSearchForm;
use dashboard\forms\CompanyUpdateForm;
use dashboard\forms\CompanyUsersSearchForm;
use dashboard\models\Company;
use dashboard\models\Identity;
use common\extensions\croppie\actions\UploadAction;
use voskobovich\crud\actions\RelationAction;
use voskobovich\crud\actions\UpdateAction;
use voskobovich\pnotify\helpers\PNotifyHelper;
use Yii;
/**
* Class CompanyController
* @package dashboard\controllers
*/
class CompanyController extends Controller
{
/**
* @var string
*/
public $modelClass = 'dashboard\models\Company';
/**
* @var array
*/
public $urlAfterUpdate = ['update'];
/**
* Behaviors
* @return array
*/
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access']['rules'] = [
[
'allow' => true,
'roles' => [Identity::ROLE_USER],
'actions' => ['locked']
],
[
'allow' => true,
'roles' => [Identity::ROLE_OWNER],
],
];
$behaviors['verbs']['actions']['photo'] = ['post'];
$behaviors['verbs']['actions']['photo-delete'] = ['post'];
return $behaviors;
}
/**
* @return array
*/
public function actions()
{
$company = Company::loadCurrent();
$successCallback = function () {
PNotifyHelper::success(Yii::t('common/interface/common', 'Done'));
};
$errorCallback = function () {
PNotifyHelper::error(
Yii::t('common/interface/common', 'Note the marked errors'),
Yii::t('common/interface/common', 'Failed')
);
};
$actions = parent::actions();
unset($actions['index'], $actions['create'], $actions['delete']);
$actions['update']['modelClass'] = CompanyUpdateForm::className();
$actions['update']['modelPk'] = $company->id;
$actions['users'] = [
'class' => RelationAction::className(),
'modelClass' => $this->modelClass,
'modelPk' => $company->id,
'formClass' => CompanyUsersSearchForm::className(),
'viewFile' => 'users'
];
$actions['account'] = [
'class' => RelationAction::className(),
'modelClass' => $this->modelClass,
'formClass' => CompanyTransactionsSearchForm::className(),
'modelPk' => $company->id,
'viewFile' => 'account'
];
$actions['tariff'] = [
'class' => UpdateAction::className(),
'modelClass' => CompanyTariffForm::className(),
'modelPk' => $company->id,
'redirectUrl' => false,
'successCallback' => $successCallback,
'errorCallback' => $errorCallback,
'viewFile' => 'tariff'
];
$actions['order-statuses'] = [
'class' => RelationAction::className(),
'modelClass' => $this->modelClass,
'modelPk' => $company->id,
'formClass' => CompanyOrderStatusesSearchForm::className(),
'viewFile' => 'order-statuses'
];
$actions['delivery-methods'] = [
'class' => RelationAction::className(),
'modelClass' => $this->modelClass,
'modelPk' => $company->id,
'formClass' => CompanyDeliveryMethodsSearchForm::className(),
'viewFile' => 'delivery-methods'
];
$actions['payment-methods'] = [
'class' => RelationAction::className(),
'modelClass' => $this->modelClass,
'modelPk' => $company->id,
'formClass' => CompanyPaymentMethodsSearchForm::className(),
'viewFile' => 'payment-methods'
];
$actions['photo'] = [
'class' => UploadAction::className(),
'modelClass' => CompanyPhotoForm::className(),
'modelPk' => $company->id,
'viewFile' => false,
'successCallback' => false,
'errorCallback' => false,
];
$actions['photo-delete'] = [
'class' => UpdateAction::className(),
'modelClass' => CompanyPhotoDeleteForm::className(),
'modelPk' => $company->id,
'viewFile' => false,
'successCallback' => false,
'errorCallback' => false,
];
return $actions;
}
/**
* @return string
*/
public function actionLocked()
{
$model = Company::loadCurrent();
return $this->render('locked', ['model' => $model]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment