diff --git a/backend/modules/document/views/document/_form.php b/backend/modules/document/views/document/_form.php
index f9c6d6c..c1effaa 100644
--- a/backend/modules/document/views/document/_form.php
+++ b/backend/modules/document/views/document/_form.php
@@ -2,9 +2,10 @@
use backend\modules\company\models\Company;
use backend\modules\document\models\DocumentTemplate;
-use backend\modules\employee\models\Manager;
+use kartik\depdrop\DepDrop;
use kartik\select2\Select2;
use yii\helpers\Html;
+use yii\helpers\Url;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
@@ -16,48 +17,6 @@ use yii\widgets\ActiveForm;
- = $form->field($model, 'company_id')->widget(Select2::class,
- [
- 'data' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
- 'options' => ['placeholder' => '...','class' => 'form-control'],
- 'pluginOptions' => [
- 'allowClear' => true
- ],
- ]
- ); ?>
-
- = $form->field($model, 'manager_id')->widget(Select2::class,
- [
- 'data' => Manager::find()->select(['fio', 'manager.id'])
- ->joinWith('userCard')->indexBy('manager.id')->column(),
- 'options' => ['placeholder' => '...','class' => 'form-control'],
- 'pluginOptions' => [
- 'allowClear' => true
- ],
- ]
- ); ?>
-
- = $form->field($model, 'contractor_company_id')->widget(Select2::class,
- [
- 'data' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
- 'options' => ['placeholder' => '...','class' => 'form-control'],
- 'pluginOptions' => [
- 'allowClear' => true
- ],
- ]
- ); ?>
-
- = $form->field($model, 'contractor_manager_id')->widget(Select2::class,
- [
- 'data' => Manager::find()->select(['fio', 'manager.id'])
- ->joinWith('userCard')->indexBy('manager.id')->column(),
- 'options' => ['placeholder' => '...','class' => 'form-control'],
- 'pluginOptions' => [
- 'allowClear' => true
- ],
- ]
- ); ?>
-
= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
= $form->field($model, 'template_id')->widget(Select2::class,
@@ -70,6 +29,52 @@ use yii\widgets\ActiveForm;
]
); ?>
+
+
Не обязательные поля:
+
+
+ = $form->field($model, 'company_id')->dropDownList(
+ Company::find()->select(['name', 'id'])->indexBy('id')->column(),
+ [
+ 'id' => 'company-id',
+ 'prompt' => 'Выберите'
+ ]
+ );
+ ?>
+
+ = $form->field($model, 'manager_id')->widget(DepDrop::className(),
+ [
+ 'options' => ['id' => 'manager-id'],
+ 'pluginOptions' => [
+ 'depends' => ['company-id'],
+ 'placeholder' => 'Выберите',
+ 'url' => Url::to(['/document/document/managers'])
+ ]
+ ]
+ ); ?>
+
+ = $form->field($model, 'contractor_company_id')->widget(Select2::class,
+ [
+ 'data' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
+ 'options' => ['id' => 'contractor-company-id','placeholder' => '...','class' => 'form-control'],
+ 'pluginOptions' => [
+ 'allowClear' => true
+ ],
+ ]
+ ); ?>
+
+ = $form->field($model, 'contractor_manager_id')->widget(DepDrop::className(),
+ [
+ 'options' => ['id' => 'contractor-manager-id'],
+ 'pluginOptions' => [
+ 'depends' => ['contractor-company-id'],
+ 'placeholder' => 'Выберите',
+ 'url' => Url::to(['/document/document/managers']),
+ 'params' => ['contractor-company-id']
+ ]
+ ]
+ ); ?>
+
= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
diff --git a/backend/modules/document/views/document/download.php b/backend/modules/document/views/document/download.php
index 1813cd9..de40f1e 100644
--- a/backend/modules/document/views/document/download.php
+++ b/backend/modules/document/views/document/download.php
@@ -1,6 +1,6 @@
params['breadcrumbs'][] = 'Загрузить';
'action' => Url::to(['document/update-document-body', 'id' => $model->id]),
'options' => ['method' => 'post']])
?>
- = $form->field($model, 'body')->widget(EditorClassic::className(), [
- 'clientOptions' => [
- 'language' => 'ru',
- ]
- ]); ?>
+
+ = $form->field($model, 'body')->widget(CKEditor::className(),[
+ 'editorOptions' => [
+ 'preset' => 'full',
+ 'inline' => false,
+ ],
+ ]); ?>
= Html::submitButton('Сохраниить изменения', ['class' => 'btn btn-primary']) ?>
diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php
index 9288e59..16789bc 100755
--- a/backend/views/layouts/left.php
+++ b/backend/views/layouts/left.php
@@ -30,6 +30,13 @@
['label' => 'Шаблоны резюме', 'icon' => 'address-card ', 'url' => ['/card/resume-template'], 'active' => \Yii::$app->controller->id == 'resume-template'],
['label' => 'Шаблоны документов', 'icon' => 'file', 'url' => ['/document/document-template'], 'active' => \Yii::$app->controller->id == 'document-template'],
['label' => 'Поля документов', 'icon' => 'file-text', 'url' => ['/document/document-field'], 'active' => \Yii::$app->controller->id == 'document-field'],
+ [
+ 'label' => 'Роли', 'icon' => 'users', 'url' => '#',
+ 'items' => [
+ ['label' => 'Управление ролями', 'icon' => ' fa-sort-amount-asc', 'url' => ['/permit/access/role'], 'active' => \Yii::$app->controller->id == 'access'],
+ ['label' => 'Правила доступа', 'icon' => 'list-alt', 'url' => ['/permit/access/permission'], 'active' => \Yii::$app->controller->id == 'access'],
+ ]
+ ]
],
'visible' => Yii::$app->user->can('confidential_information')
],
@@ -60,7 +67,14 @@
],
'visible' => Yii::$app->user->can('confidential_information')
],
- ['label' => 'Компании', 'icon' => 'building', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company', ], // 'visible' => Yii::$app->user->can('confidential_information')
+ [
+ 'label' => 'Компании', 'icon' => 'building', 'url' => '#',
+ 'items' => [
+ ['label' => 'Компании', 'icon' => 'building-o', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company'],
+ ['label' => 'Менеджеры компаний', 'icon' => 'user-circle-o', 'url' => ['/company/company-manager'], 'active' => \Yii::$app->controller->id == 'company-manager'],
+ ],
+ 'visible' => Yii::$app->user->can('confidential_information')
+ ],
[
'label' => 'Hh.ru', 'icon' => 'user-circle', 'url' => '#',
'items' => [
diff --git a/common/models/CompanyManager.php b/common/models/CompanyManager.php
new file mode 100644
index 0000000..2f13bf5
--- /dev/null
+++ b/common/models/CompanyManager.php
@@ -0,0 +1,74 @@
+ ['company_id', 'user_card_id'], 'message'=>'Этот менеджер уже закреплён за компанией'],
+ [['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']],
+ [['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => 'ID',
+ 'company_id' => 'Компания',
+ 'user_card_id' => 'Менеджер',
+ ];
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getCompany()
+ {
+ return $this->hasOne(Company::className(), ['id' => 'company_id']);
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getUserCard()
+ {
+ return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
+ }
+
+ public static function getManagersByCompany($company_id): array
+ {
+ return self::find()->where(['company_id' => $company_id])->all();
+ }
+}
diff --git a/common/models/Document.php b/common/models/Document.php
index 7e773b7..d84b0af 100644
--- a/common/models/Document.php
+++ b/common/models/Document.php
@@ -21,9 +21,9 @@ use yii\db\Expression;
*
* @property Company $company
* @property Company $contractorCompany
- * @property Manager $contractorManager
+ * @property CompanyManager $contractorManager
* @property DocumentTemplate $template
- * @property Manager $manager
+ * @property CompanyManager $manager
*/
class Document extends \yii\db\ActiveRecord
{
@@ -56,19 +56,19 @@ class Document extends \yii\db\ActiveRecord
public function rules()
{
return [
- [['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'title', 'template_id'], 'required'],
+ [['title', 'template_id'], 'required'],
[['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'template_id'], 'integer'],
[['body'], 'string'],
[['created_at', 'updated_at'], 'safe'],
[['title'], 'string', 'max' => 255],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']],
[['contractor_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['contractor_company_id' => 'id']],
- [['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']],
+ [['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyManager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']],
[['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentTemplate::className(), 'targetAttribute' => ['template_id' => 'id']],
- [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']],
+ [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyManager::className(), 'targetAttribute' => ['manager_id' => 'id']],
['body', 'required', 'on' => self::SCENARIO_UPDATE_DOCUMENT_BODY],
['body', function ($attribute, $params) {
- preg_match_all('/(\${\w+|№|№+w})/', $this->$attribute,$out);
+ preg_match_all('/\${(\w+|№|№+w)}/', $this->$attribute,$out);
if (!empty($out[0])) {
$this->addError('body', 'В теле документа все переменные должны быть заменены!');
}
@@ -125,7 +125,7 @@ class Document extends \yii\db\ActiveRecord
*/
public function getContractorManager()
{
- return $this->hasOne(Manager::className(), ['id' => 'contractor_manager_id']);
+ return $this->hasOne(CompanyManager::className(), ['id' => 'contractor_manager_id']);
}
/**
@@ -133,6 +133,6 @@ class Document extends \yii\db\ActiveRecord
*/
public function getManager()
{
- return $this->hasOne(Manager::className(), ['id' => 'manager_id']);
+ return $this->hasOne(CompanyManager::className(), ['id' => 'manager_id']);
}
}
diff --git a/common/models/User.php b/common/models/User.php
index d724ffc..f9c66be 100755
--- a/common/models/User.php
+++ b/common/models/User.php
@@ -2,6 +2,7 @@
namespace common\models;
+use developeruz\db_rbac\interfaces\UserRbacInterface;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
@@ -23,7 +24,7 @@ use yii\web\UnauthorizedHttpException;
* @property $access_token_expired_at
* @property string $password write-only password
*/
-class User extends ActiveRecord implements IdentityInterface
+class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
@@ -76,6 +77,11 @@ class User extends ActiveRecord implements IdentityInterface
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
+ public function getUserName()
+ {
+ return $this->username;
+ }
+
public function generateAccessToken()
{
$this->access_token = Yii::$app->security->generateRandomString();
diff --git a/common/models/UserCard.php b/common/models/UserCard.php
index 41ac519..bc3b283 100755
--- a/common/models/UserCard.php
+++ b/common/models/UserCard.php
@@ -63,7 +63,6 @@ class UserCard extends \yii\db\ActiveRecord
const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text';
const SCENARIO_DOWNLOAD_RESUME = 'download_resume_text';
-// public $resumeTemplateId;
/**
* @return string[]
@@ -251,6 +250,14 @@ class UserCard extends \yii\db\ActiveRecord
return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']);
}
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getCompanyManagers()
+ {
+ return $this->hasMany(CompanyManager::className(), ['user_card_id' => 'id']);
+ }
+
public static function generateUserForUserCard($card_id = null)
{
$userCardQuery = self::find();
@@ -327,4 +334,12 @@ class UserCard extends \yii\db\ActiveRecord
return $userCard['id'];
}
+
+ public static function getCardByUserRole($role): array
+ {
+ $auth = Yii::$app->authManager;
+ $usersId = $auth->getUserIdsByRole($role);
+
+ return UserCard::find()->where([ 'IN', 'id_user', $usersId])->all();
+ }
}
diff --git a/common/services/DocumentService.php b/common/services/DocumentService.php
index 5a69863..ec0007b 100644
--- a/common/services/DocumentService.php
+++ b/common/services/DocumentService.php
@@ -54,7 +54,6 @@ class DocumentService
$pdf = new Pdf(); // or new Pdf();
$mpdf = $pdf->api; // fetches mpdf api
- $mpdf->SetFooter('{PAGENO}');
$mpdf->WriteHtml($model->body); // call mpdf write html
echo $mpdf->Output("{$model->title}", 'D'); // call the mpdf api output as needed
}
@@ -67,11 +66,11 @@ class DocumentService
// (B) ADD HTML CONTENT
$section = $pw->addSection();
- $documentText = str_replace(array('
', '
', ''), ' ', $model->body);
- \PhpOffice\PhpWord\Shared\Html::addHtml($section, $documentText, false, false);
- // (C) SAVE TO DOCX ON SERVER
- // $pw->save("convert.docx", "Word2007");
+ $html = str_replace(array('
', '
', ''), ' ', $model->body);
+ \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
+
+ $section->setStyle();
// (D) OR FORCE DOWNLOAD
header("Content-Type: application/octet-stream");
diff --git a/composer.json b/composer.json
index 584460e..c3d40cd 100755
--- a/composer.json
+++ b/composer.json
@@ -36,7 +36,8 @@
"phpoffice/phpword": "^0.18.2",
"kartik-v/yii2-widget-fileinput": "@dev",
"kartik-v/yii2-mpdf": "dev-master",
- "mihaildev/yii2-ckeditor": "*"
+ "mihaildev/yii2-ckeditor": "*",
+ "developeruz/yii2-db-rbac": "*"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
diff --git a/console/controllers/RbacController.php b/console/controllers/RbacController.php
index 94a5c6c..dd01012 100755
--- a/console/controllers/RbacController.php
+++ b/console/controllers/RbacController.php
@@ -35,6 +35,20 @@ class RbacController extends Controller
$auth->assign($admin, 1);
}
+ /**
+ * Add company manager role
+ */
+ public function actionCreateCompanyManagerRole()
+ {
+ $auth = Yii::$app->getAuthManager();
+
+ $role = $auth->createRole('company_manager');
+ $role->description = 'Менеджер компании контр агента';
+ $auth->add($role);
+
+ $this->stdout('Done!' . PHP_EOL);
+ }
+
public function actionCreateEditor()
{
$auth = Yii::$app->authManager;
diff --git a/console/migrations/m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table.php b/console/migrations/m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table.php
new file mode 100644
index 0000000..9d29071
--- /dev/null
+++ b/console/migrations/m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table.php
@@ -0,0 +1,47 @@
+alterColumn('document', 'company_id', $this->integer(11)->null());
+ $this->alterColumn('document', 'contractor_company_id', $this->integer(11)->null());
+ $this->alterColumn('document', 'manager_id', $this->integer(11)->null());
+ $this->alterColumn('document', 'contractor_manager_id', $this->integer(11)->null());
+
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->alterColumn('document', 'company_id', $this->integer(11)->notNull());
+ $this->alterColumn('document', 'contractor_company_id', $this->integer(11)->notNull());
+ $this->alterColumn('document', 'manager_id', $this->integer(11)->notNull());
+ $this->alterColumn('document', 'contractor_manager_id', $this->integer(11)->notNull());
+ }
+
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}
diff --git a/console/migrations/m221129_100558_create_company_manager_table.php b/console/migrations/m221129_100558_create_company_manager_table.php
new file mode 100644
index 0000000..33449e5
--- /dev/null
+++ b/console/migrations/m221129_100558_create_company_manager_table.php
@@ -0,0 +1,33 @@
+createTable('{{%company_manager}}', [
+ 'id' => $this->primaryKey(),
+ 'company_id' => $this->integer(),
+ 'user_card_id' => $this->integer(),
+ ]);
+ $this->addForeignKey('company_company_manager', 'company_manager', 'company_id', 'company', 'id');
+ $this->addForeignKey('user_card_company_manager', 'company_manager', 'user_card_id', 'user_card', 'id');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('company_company_manager', 'company_manager');
+ $this->dropForeignKey('user_card_company_manager', 'company_manager');
+ $this->dropTable('{{%company_manager}}');
+ }
+}
diff --git a/console/migrations/m221130_090104_change_keys_in_document_table_from_manager_to_company_manager.php b/console/migrations/m221130_090104_change_keys_in_document_table_from_manager_to_company_manager.php
new file mode 100644
index 0000000..33f5232
--- /dev/null
+++ b/console/migrations/m221130_090104_change_keys_in_document_table_from_manager_to_company_manager.php
@@ -0,0 +1,48 @@
+dropForeignKey('manager_document', 'document');
+ $this->dropForeignKey('contractor_manager_document', 'document');
+
+ $this->addForeignKey('company_manager_document', 'document', 'manager_id', 'company_manager', 'id');
+ $this->addForeignKey('contractor_company_manager_document', 'document', 'contractor_manager_id', 'company_manager', 'id');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('company_manager_document', 'document');
+ $this->dropForeignKey('contractor_company_manager_document', 'document');
+
+ $this->addForeignKey('manager_document', 'document', 'manager_id','manager', 'id');
+ $this->addForeignKey('contractor_manager_document', 'document', 'contractor_manager_id','manager', 'id');
+ }
+
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m221130_090104_change_keys_in_document_table_from_manager_to_company_manager cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}