This commit is contained in:
2020-02-01 16:47:12 +07:00
commit 4c619ad6e6
16739 changed files with 3329179 additions and 0 deletions

48
models/AuthAssignment.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "auth_assignment".
*
* @property string $item_name
* @property string $user_id
* @property int $created_at
*/
class AuthAssignment extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'auth_assignment';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['item_name', 'user_id'], 'required'],
[['created_at'], 'integer'],
[['item_name', 'user_id'], 'string', 'max' => 64],
[['item_name', 'user_id'], 'unique', 'targetAttribute' => ['item_name', 'user_id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'item_name' => 'Item Name',
'user_id' => 'User ID',
'created_at' => 'Created At',
];
}
}

98
models/AuthItem.php Normal file
View File

@@ -0,0 +1,98 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "auth_item".
*
* @property string $name
* @property int $type
* @property string $description
* @property string $rule_name
* @property resource $data
* @property int $created_at
* @property int $updated_at
*
* @property AuthItemChild[] $authItemChildren
* @property AuthItemChild[] $authItemChildren0
* @property AuthItem[] $children
* @property AuthItem[] $parents
*/
class AuthItem extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'auth_item';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['name', 'type'], 'required'],
[['type', 'created_at', 'updated_at'], 'integer'],
[['description', 'data'], 'string'],
[['name', 'rule_name'], 'string', 'max' => 64],
[['name'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'name' => 'Name',
'type' => 'Type',
'description' => 'Description',
'rule_name' => 'Rule Name',
'data' => 'Data',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthItemChildren() {
return $this->hasMany(AuthItemChild::className(), ['parent' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthItemChildren0() {
return $this->hasMany(AuthItemChild::className(), ['child' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getChildren() {
return $this->hasMany(AuthItem::className(), ['name' => 'child'])->viaTable('auth_item_child', ['parent' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getParents() {
return $this->hasMany(AuthItem::className(), ['name' => 'parent'])->viaTable('auth_item_child', ['child' => 'name']);
}
public static function roleArray() {
$ls = self::find()->all();
$re = [];
foreach ($ls as $key => $value) {
if (!in_array($value->name, ['hoa_sy', 'kiem_duyet', 'quy_trinh_cu', 'kiem_duyet_kich_ban', 'kiem_duyet_phan_canh', 'kiem_duyet_to_mau', 'kiem_duyet_ve_dong', 'kiem_duyet_sach_xen', 'kiem_duyet_ky_thuat']))
$re[$value->name] = Yii::t("app", $value->description);
}
return $re;
}
}

64
models/ContactForm.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha'],
];
}
/**
* @return array customized attribute labels
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
/**
* Sends an email to the specified email address using the information collected by this model.
* @param string $email the target email address
* @return bool whether the model passes validation
*/
public function contact($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
}
return false;
}
}

75
models/LoginForm.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*
* @property User|null $user This property is read-only.
*
*/
class LoginForm extends Model {
public $username;
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules() {
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params) {
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
/**
* Logs in a user using the provided username and password.
* @return bool whether the user is logged in successfully
*/
public function login() {
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser() {
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}

67
models/Logs.php Normal file
View File

@@ -0,0 +1,67 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "logs".
*
* @property int $id
* @property int $vehicle_id
* @property string $plate_image_in
* @property string $frame_image_in
* @property int $time_in
* @property string $plate_image_out
* @property string $frame_image_out
* @property int $time_out
* @property string $seal_no
* @property string $note
* @property string $factory
*/
class Logs extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'logs';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['vehicle_id'], 'required'],
[['vehicle_id', 'time_in', 'time_out'], 'integer'],
[['plate_image_in', 'frame_image_in', 'plate_image_out', 'frame_image_out', 'seal_no', 'note'], 'string'],
[['factory'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'vehicle_id' => 'Vehicle ID',
'plate_image_in' => 'Ảnh biển vào',
'frame_image_in' => 'Frame Image In',
'time_in' => 'Thời gian vào',
'plate_image_out' => 'Ảnh biển ra',
'frame_image_out' => 'Frame Image Out',
'time_out' => 'Thời gian ra',
'seal_no' => 'SEAL_NO',
'note' => 'Nội dung khác',
'factory' => 'Factory',
'plate' => "Biển số"
];
}
public function getVehicle() {
return $this->hasOne(Vehicle::className(), ["id" => "vehicle_id"]);
}
}

78
models/LogsSearch.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Logs;
/**
* LogsSearch represents the model behind the search form of `app\models\Logs`.
*/
class LogsSearch extends Logs {
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'vehicle_id'], 'integer'],
[['frame_image_in', 'frame_image_out', 'seal_no', 'note', 'factory'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios() {
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params) {
$query = Logs::find();
$query->joinWith("vehicle");
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'vehicle_id' => $this->vehicle_id,
'time_in' => $this->time_in,
'time_out' => $this->time_out,
]);
$query->andFilterWhere(['like', 'plate_image_in', $this->plate_image_in])
->andFilterWhere(['like', 'frame_image_in', $this->frame_image_in])
->andFilterWhere(['like', 'plate_image_out', $this->plate_image_out])
->andFilterWhere(['like', 'frame_image_out', $this->frame_image_out])
->andFilterWhere(['like', 'seal_no', $this->seal_no])
->andFilterWhere(['like', 'note', $this->note])
->andFilterWhere(['like', 'factory', $this->factory])
->andFilterWhere(['like', 'vehicle.plate', $this->vehicle_id]);
return $dataProvider;
}
}

65
models/LogsUnknow.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "logs_unknow".
*
* @property int $id
* @property string $plate
* @property string $plate_image_in
* @property string $frame_image_in
* @property int $time_in
* @property string $plate_image_out
* @property string $frame_image_out
* @property int $time_out
* @property string $seal_no
* @property string $note
* @property string $factory
*/
class LogsUnknow extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'logs_unknow';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['plate'], 'required'],
[['plate_image_in', 'frame_image_in', 'plate_image_out', 'frame_image_out', 'seal_no', 'note'], 'string'],
[['time_in', 'time_out'], 'integer'],
[['plate'], 'string', 'max' => 50],
[['factory'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'plate' => 'Plate',
'plate_image_in' => 'Plate Image In',
'frame_image_in' => 'Frame Image In',
'time_in' => 'Time In',
'plate_image_out' => 'Plate Image Out',
'frame_image_out' => 'Frame Image Out',
'time_out' => 'Time Out',
'seal_no' => 'Seal No',
'note' => 'Note',
'factory' => 'Factory',
];
}
}

204
models/User.php Normal file
View File

@@ -0,0 +1,204 @@
<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
class User extends ActiveRecord implements \yii\web\IdentityInterface {
public static function tableName() {
return 'user';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['username', 'password'], 'required'],
[['email'], 'email'],
[['username', 'email'], 'unique'],
[['phone_number'], 'string', 'max' => 30],
[['username', 'password', 'password_reset_token', 'first_name', 'last_name'], 'string', 'max' => 250],
[['user_image', 'email'], 'string', 'max' => 500],
[['quota'], 'integer']
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'first_name' => "Tên đăng nhập",
'last_name' => 'Last Name',
'username' => "Họ tên",
'phone_number' => "Điện thoại",
'email' => "Email",
'roleName' => "Phân quyền"
];
}
public static function findIdentity($id) {
$user = self::find()
->where([
"id" => $id
])
->one();
if ($user == null) {
return null;
}
return new static($user);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $userType = null) {
$user = self::find()
->where(["accessToken" => $token])
->one();
if (!count($user)) {
return null;
}
return new static($user);
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username) {
$user = self::find()
->where([
"username" => $username
])
->one();
if ($user == null) {
return null;
}
return new static($user);
}
public static function findByUser($username) {
$user = self::find()
->where([
"username" => $username
])
->one();
if ($user == null) {
return null;
}
return $user;
}
/**
* @inheritdoc
*/
public function getId() {
return $this->id;
}
/**
* @inheritdoc
*/
public function getAuthKey() {
return $this->authKey;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey) {
return $this->authKey === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password) {
return $this->password === md5($password);
}
public function create($data) {
$r = $this->load([
'first_name' => $data['Name'],
'username' => $data['Username'],
'password' => $data['Password'] !== "" ? md5($data['Password']) : md5('123456a@'),
'phone_number' => $data['PhoneNumber'],
'email' => $data['Email']
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
public function getRole() {
return AuthAssignment::findOne(['user_id' => $this->id])->item_name;
}
public function getRoleName() {
$roles = $this->roles;
$lists = "";
foreach ($roles as $key => $value) {
$lists .= \yii\helpers\Html::label(Yii::t("app", AuthItem::findOne(['name' => $value])->description), "", ["class" => "label label-info"]) . " ";
}
return $lists;
}
public function getRoleNameLists() {
$roles = $this->roles;
$lists = [];
foreach ($roles as $key => $value) {
$lists[] = AuthItem::findOne(['name' => $value])->description;
}
return implode(",", $lists);
}
public function getRoles() {
$roleArray = [];
$roles = AuthAssignment::find()->andWhere(['user_id' => $this->id])->all();
foreach ($roles as $key => $value) {
$roleArray[] = $value->item_name;
}
return $roleArray;
}
public static function securityArray($all = false) {
$ls = AuthAssignment::find()->andWhere(['IN', 'item_name', ["security"]])->all();
$temp = [];
foreach ($ls as $key => $value) {
$temp[] = $value->user_id;
}
$lsID = array_unique($temp);
$re = [];
foreach ($lsID as $key => $value) {
if ($all) {
$re[$value] = self::findOne($value)->first_name;
} else {
$check = Gate::findOne(['user_id' => $value]);
if (!$check)
$re[$value] = self::findOne($value)->first_name;
}
}
return $re;
}
public function getAvatar() {
$directoryAsset = Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist');
return $this->user_image == null ? $directoryAsset . "/img/user2-160x160.jpg" : Yii::getAlias("@images_folder") . $this->user_image;
}
}

77
models/UserSearch.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\User;
/**
* UserSearch represents the model behind the search form of `app\models\User`.
*/
class UserSearch extends User
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id'], 'integer'],
[['first_name', 'last_name', 'phone_number', 'username', 'email', 'password', 'authKey', 'password_reset_token', 'user_image'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'first_name', $this->first_name])
->andFilterWhere(['like', 'last_name', $this->last_name])
->andFilterWhere(['like', 'phone_number', $this->phone_number])
->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['like', 'password', $this->password])
->andFilterWhere(['like', 'authKey', $this->authKey])
->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])
->andFilterWhere(['like', 'user_image', $this->user_image]);
return $dataProvider;
}
}

81
models/Vehicle.php Normal file
View File

@@ -0,0 +1,81 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "vehicle".
*
* @property int $id
* @property string $plate
* @property string $type
* @property string $company
* @property string $vehicle_type
* @property string $driver
* @property string $telephone
* @property string $indentity_card
* @property int $created_at
* @property int $modified_at
*/
class Vehicle extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'vehicle';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['plate', 'type'], 'required'],
[['company', 'vehicle_type'], 'string'],
[['plate', 'type'], 'string', 'max' => 20],
[['driver', 'telephone', 'indentity_card'], 'string', 'max' => 200],
[['created_at', 'modified_at'], 'integer']
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'plate' => 'Biển số xe',
'type' => 'Loại xe',
'company' => 'Tên công ty',
'vehicle_type' => 'Kiểu xe',
'driver' => 'Lái xe',
'telephone' => 'Điện thoại',
'indentity_card' => 'CMT',
];
}
public function create($data) {
$r = $this->load([
'plate' => $data['plate'],
'type' => $data['type'],
'company' => $data['company'],
'vehicle_type' => $data['vehicle_type'],
'driver' => $data['driver'],
'telephone' => $data['telephone'],
'indentity_card' => $data['indentity_card'],
'created_at' => time(),
'modified_at' => time()
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
}

75
models/VehicleSearch.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Vehicle;
/**
* VehicleSearch represents the model behind the search form of `app\models\Vehicle`.
*/
class VehicleSearch extends Vehicle
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id'], 'integer'],
[['plate', 'type', 'company', 'vehicle_type', 'driver', 'telephone', 'indentity_card'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Vehicle::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'plate', $this->plate])
->andFilterWhere(['like', 'type', $this->type])
->andFilterWhere(['like', 'company', $this->company])
->andFilterWhere(['like', 'vehicle_type', $this->vehicle_type])
->andFilterWhere(['like', 'driver', $this->driver])
->andFilterWhere(['like', 'telephone', $this->telephone])
->andFilterWhere(['like', 'indentity_card', $this->indentity_card]);
return $dataProvider;
}
}

174
models/common.php Normal file
View File

@@ -0,0 +1,174 @@
<?php
namespace app\models;
use Yii;
class common extends \yii\db\ActiveRecord {
public function formatName($name) {
return preg_replace('/[^a-zA-Z0-9 _-]/', '', $this->vn2latin($name, true));
}
public function vn2latin($cs, $tolower = false) {
/* Mảng chứa tất cả ký tự có dấu trong Tiếng Việt */
$marTViet = array("à", "á", "", "", "ã", "â", "", "", "", "", "", "ă",
"", "", "", "", "", "è", "é", "", "", "", "ê", "",
"ế", "", "", "",
"ì", "í", "", "", "ĩ",
"ò", "ó", "", "", "õ", "ô", "", "", "", "", "", "ơ",
"", "", "", "", "",
"ù", "ú", "", "", "ũ", "ư", "", "", "", "", "",
"", "ý", "", "", "",
"đ",
"À", "Á", "", "", "Ã", "Â", "", "", "", "", "", "Ă",
"", "", "", "", "",
"È", "É", "", "", "", "Ê", "", "", "", "", "",
"Ì", "Í", "", "", "Ĩ",
"Ò", "Ó", "", "", "Õ", "Ô", "", "", "", "", "", "Ơ", "", "", "", "", "",
"Ù", "Ú", "", "", "Ũ", "Ư", "", "", "", "", "",
"", "Ý", "", "", "",
"Đ", " ");
/* Mảng chứa tất cả ký tự không dấu tương ứng với mảng $marTViet bên trên */
$marKoDau = array("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a",
"a", "a", "a", "a", "a", "a",
"e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e",
"i", "i", "i", "i", "i",
"o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o", "o",
"o", "o", "o", "o", "o",
"u", "u", "u", "u", "u", "u", "u", "u", "u", "u", "u",
"y", "y", "y", "y", "y",
"d",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A",
"E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E",
"I", "I", "I", "I", "I",
"O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O",
"U", "U", "U", "U", "U", "U", "U", "U", "U", "U", "U",
"Y", "Y", "Y", "Y", "Y",
"D", "-");
if ($tolower) {
return strtolower(str_replace($marTViet, $marKoDau, $cs));
}
return str_replace($marTViet, $marKoDau, $cs);
}
public function formatTime($time, $format = "d/m/Y") {
// $now = time();
// $range = $now - $time;
// if ($range > 60 * 60 * 12) {
return date($format, $time);
// } else {
// return Yii::$app->formatter->asRelativeTime($time);
// }
}
//Upload
public function UploadFile($file, $fileTypes, $dir) {
$LocalPath = "data/" . $dir;
$RootFolder = Yii::getAlias('@webroot') . "/" . $LocalPath;
$name = $_FILES[$file]["name"];
$array = explode(".", $name);
$nr = count($array);
$ext = $array[$nr - 1];
$fileName = preg_replace('/[^a-zA-Z0-9 _-]/', '', $this->vn2latin($array[0], true));
$destfile = time() . "_" . $fileName . "." . $ext;
if (!empty($_FILES)) {
$tempFile = $_FILES[$file]['tmp_name'];
$targetPath = $RootFolder;
if (!file_exists($targetPath)) {
@mkdir($targetPath, 0777, true);
}
$targetFile = $targetPath . '/' . $destfile;
$targetFileLocal = $LocalPath . '/' . $destfile;
// Validate the file type
$fileParts = pathinfo($_FILES[$file]['name']);
if (in_array(strtoupper($fileParts['extension']), $fileTypes)) {
move_uploaded_file($tempFile, $targetFile);
if (file_exists($targetFile)) {
return $targetFileLocal;
} else {
return false;
}
} else {
return 2;
}
}
}
//Move file
public function MoveFile($file, $folder) {
$exp = explode("/", $file);
$t = [];
foreach ($exp as $key => $value) {
if ($key < count($exp) - 1) {
$t[] = $value;
}
}
$folderOld = implode("/", $t);
$root = \Yii::getAlias('@app') . '/web/data/uploads' . trim($folderOld);
chdir($root);
$nameArr = explode(".", basename($file));
$name = $this->formatName($nameArr[0]);
$ext = $nameArr[count($nameArr) - 1];
rename(basename($file), $name . "." . $ext);
$tempdir = $root . "/" . $name . "." . $ext;
if (file_exists($tempdir)) {
$destfile = basename($tempdir);
$dir = Yii::getAlias('@webroot') . "/data/uploads" . $folder;
$file_dir = $dir . '/' . $destfile;
if (!file_exists($dir)) {
@mkdir($dir, 0777, true);
}
$output = shell_exec("mv {$tempdir} {$file_dir}");
$link = $folder . "/" . $destfile;
} else {
$link = $file;
}
return $link;
}
//File size
public function filesize_formatted($path) {
$size = filesize($path);
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), 2, '.', ',') . " " . $units[$power];
}
public function getExtension($file) {
$f = basename($file);
$ls = explode(".", $file);
return strtolower($ls[count($ls) - 1]);
}
public function convertIntToTime($seconds) {
$hours = floor($seconds / 3600);
$mins = floor($seconds / 60 % 60);
$secs = floor($seconds % 60);
if ($hours > 0) {
return sprintf('%02d:%02d:%02d', $hours, $mins, $secs);
} else {
return sprintf('%02d:%02d', $mins, $secs);
}
}
public function visiblePharse($stt, $tab, $pharse) {
$visible = false;
if ($stt != 0) {
if ($stt == -1) {
if ($tab == $pharse) {
$visible = true;
}
} else {
$visible = true;
}
} else {
$visible = true;
}
return $visible;
}
}