Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate username #3

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
06db0cf
Create auto-generate in User model for username
vito-makhatadze Nov 25, 2019
7af7cfc
UserController give access control role also administrator
vito-makhatadze Nov 26, 2019
c1aed66
User create roles change
vito-makhatadze Dec 3, 2019
ac29e05
Date Format Consistency
vito-makhatadze Dec 13, 2019
327b127
Showing created at and Department column under employe index
vito-makhatadze Dec 13, 2019
9bf4b20
Make statuses colorful
vito-makhatadze Dec 13, 2019
3741c50
Workin Day time format
vito-makhatadze Dec 13, 2019
0af6658
show Created at column under Departments
vito-makhatadze Dec 13, 2019
6ff4a3d
Remove index column from everywhere
vito-makhatadze Dec 17, 2019
9eb6cd4
Create different format of requests
vito-makhatadze Dec 17, 2019
824c1d4
Change views
vito-makhatadze Dec 17, 2019
97781b0
Create different formats type of requests
vito-makhatadze Dec 18, 2019
01c764e
Create different formats type of requests
vito-makhatadze Dec 18, 2019
36ae069
Change the colors stripe
vito-makhatadze Dec 23, 2019
18c1a5f
Refactor employ username autofill
vito-makhatadze Dec 23, 2019
94f52cd
Delete unused views
vito-makhatadze Dec 26, 2019
aab31d5
Change Select by {{model}}.tablename
vito-makhatadze Dec 26, 2019
cea972b
Change calendar border and background colors
vito-makhatadze Dec 26, 2019
22066dc
Change status colors
vito-makhatadze Dec 26, 2019
b661802
Allow HR and Admin roles to delete user holiday requests
vito-makhatadze Jan 8, 2020
24d6f7d
Employ colorfull statuses
vito-makhatadze Jan 8, 2020
271c98a
Working day tickbox
vito-makhatadze Jan 8, 2020
d1d95a6
Date format change
vito-makhatadze Jan 8, 2020
bd2ee1f
ID column size same the everywhere
vito-makhatadze Jan 8, 2020
d970f82
change custom request form type by busineess form
vito-makhatadze Jan 8, 2020
58a43f3
change view format
vito-makhatadze Jan 8, 2020
b5953bf
Change Roles checkbox method
vito-makhatadze Jan 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AppAsset extends AssetBundle
'js/bootstrap-tour.min.js',
'js/lobiplugins/bootstrap-datepicker.js',
'js/modal.js',
'js/user-form.js',
];

public $depends = [
Expand Down
43 changes: 37 additions & 6 deletions components/HolidaySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@

class HolidaySettings extends Component
{
/**
* @var string manages holiday color by type on the calendar scheduler.
*/
public $textColor = '#000000d6';

/**
* @var array manages holiday color by type on the calendar scheduler.
*/
public $calendarColor = [
Holiday::TYPE_PERSONAL => '#389638',
Holiday::TYPE_BUSINESS => '#b93224',
Holiday::TYPE_CUSTOM => '#4d8dca'
public $calendarBackgroundColor = [
Holiday::TYPE_PERSONAL => '#08bbbb4d',
Holiday::TYPE_BUSINESS => '#ffd29b4d',
Holiday::TYPE_CUSTOM => '#ea75694d'
];

/**
* @var array manages holiday color by type on the calendar scheduler.
*/
public $calendarBorderColor = [
Holiday::TYPE_PERSONAL => '#63c598',
Holiday::TYPE_BUSINESS => '#ecc262',
Holiday::TYPE_CUSTOM => '#ea7569'
];

public $customHolidayName = 'Custom';
Expand All @@ -29,8 +42,26 @@ class HolidaySettings extends Component
* @param $type
* @return mixed
*/
public function getColorByType($type)
public function getBackgroundColorByType($type)
{
return $this->calendarBackgroundColor[$type];
}

/**
* @param $type
* @return mixed
*/
public function getBorderColorByType($type)
{
return $this->calendarBorderColor[$type];
}

/**
* @param $type
* @return mixed
*/
public function getTextColor()
{
return $this->calendarColor[$type];
return $this->textColor;
}
}
42 changes: 39 additions & 3 deletions controllers/RequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public function behaviors()
'roles' => [User::ROLE_MANAGER],
'actions' => ['index', 'view', 'confirm']
],
[
'actions' => ['delete',],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
if (Yii::$app->user->identity->position == User::POSITION_HR || Yii::$app->user->can('administrator')) {
return true;
}
return false;
}
],
],
],
'verbs' => [
Expand Down Expand Up @@ -62,15 +73,24 @@ public function actionView($id)
$user = Yii::$app->user->identity;
$model = $this->findAllModelExceptOwn($id);

if ($user->position != User::POSITION_HR && $user->department_id != $model->user->department_id) {
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
// if ($user->position != User::POSITION_HR && $user->department_id != $model->user->department_id) {
// throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
// }

return $this->render('view', [
'model' => $model,
]);
}

public function actionDelete($id)
{

$this->findModel($id)->delete();
return $this->redirect(['index']);

}


/**
* @return string|\yii\web\Response
* @throws NotFoundHttpException
Expand Down Expand Up @@ -112,4 +132,20 @@ protected function findAllModelExceptOwn($id)
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}

/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Holiday the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Holiday::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

}
15 changes: 8 additions & 7 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,20 @@ public function actionEvents()
->andWhere(['<=', Holiday::tableName() . '.start_date', \Yii::$app->request->get('end')])
->all();
foreach ($times AS $time) {
try{
try {
$event = new Event();
$event->id = $time->id;
$event->backgroundColor = \Yii::$app->holidaySettings->getColorByType($time->type);
$event->borderColor = \Yii::$app->holidaySettings->getColorByType($time->type);
$event->backgroundColor = \Yii::$app->holidaySettings->getBackgroundColorByType($time->type);
$event->borderColor = \Yii::$app->holidaySettings->getBorderColorByType($time->type);
$event->textColor = \Yii::$app->holidaySettings->getTextColor();
$event->title = $time->user->userProfile->getFullName();
$event->start = date('Y-m-d\TH:i:s\Z', strtotime($time->start_date));
$event->end = date('Y-m-d\TH:i:s\Z', strtotime($time->end_date));
$events[] = $event;
}catch (\Exception $e){
echo '<pre>';
var_dump($e);
exit;
} catch (\Exception $e) {
echo '<pre>';
var_dump($e);
exit;
}

}
Expand Down
10 changes: 8 additions & 2 deletions controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function actionView($id)
*/
public function actionCreate()
{

Yii::$app->authManager->checkAccess(Yii::$app->user->getId(), 'administrator') ? $userRoleName = 'administrator' : $userRoleName = 'manager';

$model = new UserForm();
$model->setScenario('create');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Expand All @@ -81,7 +84,7 @@ public function actionCreate()

return $this->render('create', [
'model' => $model,
'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')
'roles' => ArrayHelper::map(Yii::$app->authManager->getChildRoles($userRoleName), 'name', 'name')
]);
}

Expand All @@ -94,6 +97,9 @@ public function actionCreate()
*/
public function actionUpdate($id)
{
Yii::$app->authManager->checkAccess(Yii::$app->user->getId(), 'administrator') ? $userRoleName = 'administrator' : $userRoleName = 'manager';


$model = new UserForm();
$model->setModel($this->findModel($id));
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Expand All @@ -102,7 +108,7 @@ public function actionUpdate($id)

return $this->render('update', [
'model' => $model,
'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')
'roles' => ArrayHelper::map(Yii::$app->authManager->getChildRoles($userRoleName), 'name', 'name')
]);
}

Expand Down
2 changes: 1 addition & 1 deletion models/search/BankHolidaySearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function search($params)

// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
BankHoliday::tableName() . '.id' => $this->id,
'date' => $this->date,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
Expand Down
15 changes: 11 additions & 4 deletions models/search/DepartmentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class DepartmentSearch extends Department
public function rules()
{
return [
[['id', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'integer'],
[['name'], 'safe'],
[['id', 'updated_at', 'created_by', 'updated_by'], 'integer'],
[['name','created_at'], 'safe'],
[['creator'], 'safe'],

];
}

Expand Down Expand Up @@ -68,13 +69,19 @@ public function search($params)

// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'department.id' => $this->id,
'updated_at' => $this->updated_at,
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
]);

if ($this->created_at) {

$query->andFilterWhere([
'FROM_UNIXTIME(department.created_at, "%Y-%m-%d")' => $this->created_at
]);
}

$query->andFilterWhere(['like', 'name', $this->name]);
if ($this->creator) {

Expand Down
25 changes: 16 additions & 9 deletions models/search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserSearch extends User
{
public function attributes()
{
return ['id', 'fullName', 'username', 'email', 'status', 'created_at', 'updated_at', 'logged_at', 'position'];
return ['id', 'fullName', 'department_id', 'username', 'email', 'status', 'created_at', 'updated_at', 'logged_at', 'position'];
}

/**
Expand All @@ -27,10 +27,11 @@ public function attributes()
public function rules()
{
return [
[['id', 'status', 'position'], 'integer'],
[['created_at', 'updated_at', 'logged_at'], 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true],
[['created_at', 'updated_at', 'logged_at'], 'default', 'value' => null],
[['id', 'status', 'position', 'department_id'], 'integer'],
[['updated_at', 'logged_at'], 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true],
[['updated_at', 'logged_at'], 'default', 'value' => null],
[['fullName', 'username', 'auth_key', 'password_hash', 'email'], 'safe'],
[['created_at'], 'string'],
];
}

Expand Down Expand Up @@ -62,21 +63,27 @@ public function search($params)
'desc' => ["CONCAT(up.firstname, ' ', up.lastname)" => SORT_DESC],
];

if (!( $this->load($params) && $this->validate() )) {

if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}


$query->andFilterWhere([
'id' => $this->id,
'up.id' => $this->id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makhatadze It would be better to use {{Model}}::tableName() instead of hardcoded 'up'.

'position' => $this->position,
'status' => $this->status,
'department_id' => $this->department_id
]);

if ($this->created_at !== null) {
$query->andFilterWhere(['between', 'created_at', $this->created_at, $this->created_at + 3600 * 24]);
if ($this->created_at) {

$query->andFilterWhere([
'FROM_UNIXTIME(created_at, "%Y-%m-%d")' => $this->created_at
]);
}

if ($this->updated_at !== null) {
if ($this->updated_at) {
$query->andFilterWhere(['between', 'updated_at', $this->updated_at, $this->updated_at + 3600 * 24]);
}

Expand Down
Loading