add city, customer and card model + crud
This commit is contained in:
52
common/components/CardNumberTypeahead.php
Normal file
52
common/components/CardNumberTypeahead.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use Yii;
|
||||
use kartik\widgets\Typeahead;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\JsExpression;
|
||||
|
||||
|
||||
class CardNumberTypeahead extends Typeahead{
|
||||
|
||||
public $item_template = '<div><p class="">{{txt}}</p></div>';
|
||||
|
||||
public $options = ['placeholder' => 'Válassz bérletkártyát!'];
|
||||
|
||||
public $pluginOptions = ['highlight'=>true , 'minLength' => 3 ];
|
||||
|
||||
public $scrollable = true;
|
||||
|
||||
public $display = 'number';
|
||||
|
||||
public $pluginEvents = [ "typeahead:select" => "function(a,b) { }",];
|
||||
|
||||
public $onlyFreeCards = true;
|
||||
|
||||
|
||||
|
||||
public function init(){
|
||||
parent::init();
|
||||
$this->dataset = $this->createDefaultDataset();
|
||||
}
|
||||
|
||||
protected function createDefaultDataset(){
|
||||
return [
|
||||
[
|
||||
'limit' => 20,
|
||||
'remote' => [
|
||||
'ttl' => 1,
|
||||
'url' => Url::to(['card/list']) . '&onlyFree='.($this->onlyFreeCards ? '1' :'0').'&search=%QUERY&' . rand(0, 100000000),
|
||||
'wildcard' => '%QUERY'
|
||||
],
|
||||
'limit' => 10,
|
||||
'display' => $this->display,
|
||||
'templates' => [
|
||||
'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find number for selected query.</div>',
|
||||
'suggestion' => new JsExpression("Handlebars.compile('{$this->item_template}')")
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
50
common/components/CityNameTypeahead.php
Normal file
50
common/components/CityNameTypeahead.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use Yii;
|
||||
use kartik\widgets\Typeahead;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\JsExpression;
|
||||
|
||||
|
||||
class CityNameTypeahead extends Typeahead{
|
||||
|
||||
public $item_template = '<div><p class="">{{fullname}}</p></div>';
|
||||
|
||||
public $options = ['placeholder' => 'Válassz várost'];
|
||||
|
||||
public $pluginOptions = ['highlight'=>true];
|
||||
|
||||
public $scrollable = true;
|
||||
|
||||
public $display = 'name';
|
||||
|
||||
public $pluginEvents = [ "typeahead:select" => "function(a,b) { }",];
|
||||
|
||||
|
||||
|
||||
public function init(){
|
||||
parent::init();
|
||||
$this->dataset = $this->createDefaultDataset();
|
||||
}
|
||||
|
||||
protected function createDefaultDataset(){
|
||||
return [
|
||||
[
|
||||
'limit' => 20,
|
||||
'remote' => [
|
||||
'ttl' => 1,
|
||||
'url' => Url::to(['city/name-list']) . '&search=%QUERY&' . rand(0, 100000000),
|
||||
'wildcard' => '%QUERY'
|
||||
],
|
||||
'limit' => 10,
|
||||
'display' => $this->display,
|
||||
'templates' => [
|
||||
'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>',
|
||||
'suggestion' => new JsExpression("Handlebars.compile('{$this->item_template}')")
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
50
common/components/CityZipTypeahead.php
Normal file
50
common/components/CityZipTypeahead.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace common\components;
|
||||
|
||||
use Yii;
|
||||
use kartik\widgets\Typeahead;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\JsExpression;
|
||||
|
||||
|
||||
class CityZipTypeahead extends Typeahead{
|
||||
|
||||
public $item_template = '<div><p class="">{{fullname}}</p></div>';
|
||||
|
||||
public $options = ['placeholder' => 'Válassz irányítószám'];
|
||||
|
||||
public $pluginOptions = ['highlight'=>true];
|
||||
|
||||
public $scrollable = true;
|
||||
|
||||
public $display = 'zip';
|
||||
|
||||
public $pluginEvents = [ "typeahead:select" => "function(a,b) { }",];
|
||||
|
||||
|
||||
|
||||
public function init(){
|
||||
parent::init();
|
||||
$this->dataset = $this->createDefaultDataset();
|
||||
}
|
||||
|
||||
protected function createDefaultDataset(){
|
||||
return [
|
||||
[
|
||||
'limit' => 20,
|
||||
'remote' => [
|
||||
'ttl' => 1,
|
||||
'url' => Url::to(['city/zip-list']) . '&search=%QUERY&' . rand(0, 100000000),
|
||||
'wildcard' => '%QUERY'
|
||||
],
|
||||
'limit' => 10,
|
||||
'display' => $this->display,
|
||||
'templates' => [
|
||||
'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>',
|
||||
'suggestion' => new JsExpression("Handlebars.compile('{$this->item_template}')")
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
4154
common/data/telepulesek.txt
Normal file
4154
common/data/telepulesek.txt
Normal file
File diff suppressed because it is too large
Load Diff
137
common/models/Card.php
Normal file
137
common/models/Card.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "card".
|
||||
*
|
||||
* @property integer $id_card
|
||||
* @property string $number
|
||||
* @property integer $status
|
||||
* @property integer $type
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
class Card extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
|
||||
const TYPE_RFID = 10;
|
||||
const TYPE_QRCODE = 20;
|
||||
const TYPE_BARCODE = 30;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'card';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['number', 'type','status'], 'required'],
|
||||
[['status', 'type'], 'integer'],
|
||||
[['number'], 'string', 'max' => 20],
|
||||
[['number'], 'unique' ]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id_card' => Yii::t('common/card', 'Id Card'),
|
||||
'number' => Yii::t('common/card', 'Number'),
|
||||
'status' => Yii::t('common/card', 'Status'),
|
||||
'type' => Yii::t('common/card', 'Type'),
|
||||
'created_at' => Yii::t('common/card', 'Created At'),
|
||||
'updated_at' => Yii::t('common/card', 'Updated At'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
static function statuses() {
|
||||
return [
|
||||
self::STATUS_ACTIVE => Yii::t('common/card', 'Active'),
|
||||
self::STATUS_DELETED => Yii::t('common/card', 'Inactive'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatusHuman(){
|
||||
$result = null;
|
||||
$s = self::statuses($this->status);
|
||||
if ( array_key_exists($this->status, $s)){
|
||||
$result = $s[$this->status];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static function types() {
|
||||
return [
|
||||
self::TYPE_RFID => Yii::t('common/card', 'RFID'),
|
||||
self::TYPE_QRCODE => Yii::t('common/card', 'QRCODE'),
|
||||
self::TYPE_BARCODE => Yii::t('common/card', 'BARCODE'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTypeHuman(){
|
||||
$result = null;
|
||||
$s = self::types($this->type);
|
||||
if ( array_key_exists($this->type, $s)){
|
||||
$result = $s[$this->type];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isInactive(){
|
||||
return $this->status == self::STATUS_DELETED;
|
||||
}
|
||||
|
||||
public static function readCard($number,$free = null){
|
||||
$card = null;
|
||||
$query = Card::find()
|
||||
->leftJoin(Customer::tableName(), 'card.id_card = customer.id_customer_card ' )
|
||||
->andWhere(['number'=>$number ]);
|
||||
|
||||
if ( isset($free) ){
|
||||
if ( $free == true){
|
||||
$query->andWhere('customer.id_customer is null');
|
||||
}else{
|
||||
$query->andWhere('customer.id_customer is not null');
|
||||
}
|
||||
}
|
||||
|
||||
$cards = $query->all();
|
||||
|
||||
if ( count($cards) == 1){
|
||||
$card = $cards[0];
|
||||
}
|
||||
return $card;
|
||||
}
|
||||
|
||||
|
||||
public function getCustomer(){
|
||||
return $this->hasOne(Customer::className(), ['id_customer_card' => 'id_card']);
|
||||
}
|
||||
|
||||
public function getCustomerName(){
|
||||
$name = null;
|
||||
$customer = $this->customer;
|
||||
if ( $this->customer != null){
|
||||
$name = $this->customer->name;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
}
|
||||
66
common/models/City.php
Normal file
66
common/models/City.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "city".
|
||||
*
|
||||
* @property integer $id_city
|
||||
* @property string $zip
|
||||
* @property string $name
|
||||
* @property string $city_code
|
||||
* @property double $latitude
|
||||
* @property double $longitude
|
||||
* @property integer $cso_code
|
||||
* @property integer $rig_id
|
||||
* @property double $range
|
||||
* @property integer $population
|
||||
* @property integer $homes
|
||||
*/
|
||||
class City extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'city';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['zip', 'name', 'city_code'], 'required'],
|
||||
[['latitude', 'longitude', 'range'], 'number'],
|
||||
[['cso_code', 'rig_id', 'population', 'homes'], 'integer'],
|
||||
[['zip'], 'string', 'max' => 8],
|
||||
[['name'], 'string', 'max' => 64],
|
||||
[['city_code'], 'string', 'max' => 2]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id_city' => Yii::t('common/city', 'Id City'),
|
||||
'zip' => Yii::t('common/city', 'Zip'),
|
||||
'name' => Yii::t('common/city', 'Name'),
|
||||
'city_code' => Yii::t('common/city', 'City Code'),
|
||||
'latitude' => Yii::t('common/city', 'Latitude'),
|
||||
'longitude' => Yii::t('common/city', 'Longitude'),
|
||||
'cso_code' => Yii::t('common/city', 'Cso Code'),
|
||||
'rig_id' => Yii::t('common/city', 'Rig ID'),
|
||||
'range' => Yii::t('common/city', 'Range'),
|
||||
'population' => Yii::t('common/city', 'Population'),
|
||||
'homes' => Yii::t('common/city', 'Homes'),
|
||||
];
|
||||
}
|
||||
}
|
||||
168
common/models/Customer.php
Normal file
168
common/models/Customer.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "customer".
|
||||
*
|
||||
* @property integer $id_customer
|
||||
* @property integer $id_customer_card
|
||||
* @property integer $id_user
|
||||
* @property integer $id_partner_card
|
||||
* @property integer $id_proposer
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $phone
|
||||
* @property integer $sex
|
||||
* @property string $date_stundent_card_expire
|
||||
* @property string $birthdate
|
||||
* @property string $image
|
||||
* @property string $description
|
||||
* @property string $tax_number
|
||||
* @property string $country
|
||||
* @property string $zip
|
||||
* @property string $city
|
||||
* @property string $address
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
class Customer extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
|
||||
const SEX_UNKNOWN = 0;
|
||||
const SEX_MAN = 10;
|
||||
const SEX_WOMAN = 20;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'customer';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_customer_card', 'id_user', 'id_partner_card', 'id_proposer', 'sex'], 'integer'],
|
||||
[['date_stundent_card_expire', 'birthdate', 'created_at', 'updated_at'], 'safe'],
|
||||
[['name'], 'string', 'max' => 128],
|
||||
[['email', 'image', 'description', 'address'], 'string', 'max' => 255],
|
||||
[['password'], 'string', 'max' => 32],
|
||||
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
|
||||
[['zip'], 'string', 'max' => 8],
|
||||
[['city'], 'string', 'max' => 30]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id_customer' => Yii::t('common/customer', 'Id Customer'),
|
||||
'id_customer_card' => Yii::t('common/customer', 'Id Customer Card'),
|
||||
'id_user' => Yii::t('common/customer', 'Id User'),
|
||||
'id_partner_card' => Yii::t('common/customer', 'Id Partner Card'),
|
||||
'id_proposer' => Yii::t('common/customer', 'Id Proposer'),
|
||||
'name' => Yii::t('common/customer', 'Name'),
|
||||
'email' => Yii::t('common/customer', 'Email'),
|
||||
'password' => Yii::t('common/customer', 'Password'),
|
||||
'phone' => Yii::t('common/customer', 'Phone'),
|
||||
'sex' => Yii::t('common/customer', 'Sex'),
|
||||
'date_stundent_card_expire' => Yii::t('common/customer', 'Date Stundent Card Expire'),
|
||||
'birthdate' => Yii::t('common/customer', 'Birthdate'),
|
||||
'image' => Yii::t('common/customer', 'Image'),
|
||||
'description' => Yii::t('common/customer', 'Description'),
|
||||
'tax_number' => Yii::t('common/customer', 'Tax Number'),
|
||||
'country' => Yii::t('common/customer', 'Country'),
|
||||
'zip' => Yii::t('common/customer', 'Zip'),
|
||||
'city' => Yii::t('common/customer', 'City'),
|
||||
'address' => Yii::t('common/customer', 'Address'),
|
||||
'created_at' => Yii::t('common/customer', 'Created At'),
|
||||
'updated_at' => Yii::t('common/customer', 'Updated At'),
|
||||
'customerCardNumber' => Yii::t('common/customer', 'Card number'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
static function statuses() {
|
||||
return [
|
||||
self::STATUS_ACTIVE => Yii::t('common/account', 'Active'),
|
||||
self::STATUS_DELETED => Yii::t('common/account', 'Inactive'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatusHuman(){
|
||||
$result = null;
|
||||
$s = self::statuses($this->status);
|
||||
if ( array_key_exists($this->status, $s)){
|
||||
$result = $s[$this->status];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static function sexes() {
|
||||
return [
|
||||
self::SEX_UNKNOWN => Yii::t('common/sex', 'Nincs megadva'),
|
||||
self::SEX_MAN => Yii::t('common/sex', 'Férfi'),
|
||||
self::SEX_WOMAN => Yii::t('common/sex', 'Nő'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getSexHuman(){
|
||||
$result = null;
|
||||
$s = self::sexes( );
|
||||
if ( array_key_exists($this->sex, $s)){
|
||||
$result = $s[$this->sex];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isInactive(){
|
||||
return $this->status == self::STATUS_DELETED;
|
||||
}
|
||||
|
||||
|
||||
public function getCard(){
|
||||
return $this->hasOne ( Card::className (), [
|
||||
'id_card' => 'id_customer_card'
|
||||
] );
|
||||
}
|
||||
public function getUser(){
|
||||
return $this->hasOne ( User::className (), [
|
||||
'id' => 'id_user'
|
||||
] );
|
||||
}
|
||||
|
||||
public function getCustomerCardNumber(){
|
||||
$result = null;
|
||||
$card = $this->card;
|
||||
if ( $card != null) {
|
||||
$result = $card->number;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function getUsername(){
|
||||
$result = null;
|
||||
$user = $this->user;
|
||||
if ( $user != null) {
|
||||
$result = $user->username;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user