diff --git a/common/config/main.php b/common/config/main.php index f821653..1003a10 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -166,199 +166,5 @@ return [ 'artbox-comment' => [ 'class' => 'common\modules\comment\Module', ], - 'relation' => [ - 'class' => 'common\modules\relation\Module', - 'relations' => [ - 'product_categories' => [ - 'name' => Yii::t('product', 'Categories'), - 'field' => 'categories', - 'entity1' => [ - 'model' => '\common\modules\product\models\Product', - 'label' => 'Product', - 'listField' => 'name', - 'searchField' => 'name', - 'key' => 'product_id', - 'linked_key' => 'product_id', - ], - 'entity2' => [ - 'model' => '\common\modules\product\models\Category', - 'label' => 'Category', - 'listField' => 'categoryName.value', - 'searchField' => 'category_name.value', - 'searchJoin' => 'categoryName', - 'key' => 'category_id', - 'linked_key' => 'category_id', - 'hierarchy' => [ - 'key' => 'category_id', - 'parentKey' => 'parent_id', - ] - ], - 'via' => [ - 'model' => '\common\modules\product\models\ProductCategory', - ] - ], - 'product_option' => [ - 'name' => Yii::t('product', 'Properties'), - 'field' => 'options', - 'entity1' => [ - 'model' => '\common\modules\product\models\Product', - 'label' => 'Product', - 'listField' => 'fullname', - 'key' => 'product_id', - 'linked_key' => 'product_id', - ], - 'entity2' => [ - 'model' => '\common\modules\rubrication\models\TaxOption', - 'label' => 'Option', - 'listField' => 'ValueRenderFlash', - 'key' => 'tax_option_id', - 'linked_key' => 'option_id', - ], - 'via' => [ - 'model' => 'common\modules\product\models\ProductOption', - ] - ], - 'product_variant_option' => [ - 'name' => Yii::t('product', 'Properties'), - 'field' => 'options', - 'entity1' => [ - 'model' => '\common\modules\product\models\ProductVariant', - 'label' => 'Variant', - 'listField' => 'fullname', - 'key' => 'product_variant_id', - 'linked_key' => 'product_variant_id', - ], - 'entity2' => [ - 'model' => '\common\modules\rubrication\models\TaxOption', - 'label' => 'Option', - 'listField' => 'ValueRenderFlash', - 'key' => 'tax_option_id', - 'linked_key' => 'option_id', - ], - 'via' => [ - 'model' => 'common\modules\product\models\ProductVariantOption', - ] - ], - 'tax_group_to_category' => [ - 'name' => Yii::t('product', 'Характеристики по категориям'), - 'field' => 'group_to_category', - 'entity1' => [ - 'model' => '\common\modules\rubrication\models\TaxGroup', - 'label' => 'Group', - 'listField' => 'name', - 'key' => 'tax_group_id', - 'linked_key' => 'entity1_id', - ], - 'entity2' => [ - 'model' => '\common\modules\product\models\Category', - 'label' => 'Category', - 'listField' => 'name', - 'key' => 'category_id', - 'linked_key' => 'entity2_id', - 'hierarchy' => [ - 'key' => 'category_id', - 'parentKey' => 'parent_id', - ] - ], - 'via' => [ - 'model' => '\common\modules\relation\models\Relation', - 'alias' => 'alias', - ] - ], - /* - 'relation_categories' => [ - 'name' => Yii::t('relation', 'Relation categories'), - 'field' => 'categories', - 'entity1' => [ - 'model' => '\common\modules\product\models\Product', - 'label' => 'Product', - 'listField' => 'fullname', - 'key' => 'product_id', - 'linked_key' => 'product_id', - ], - 'entity2' => [ - 'model' => '\common\modules\rubrication\models\TaxOption', - 'label' => 'Category', - 'listField' => 'ValueRenderFlash', - 'key' => 'tax_option_id', - 'linked_key' => 'category_id', - 'where' => [ - 'tax_group_id' => 1 - ] - ], - 'via' => [ - 'model' => '\common\modules\relation\models\Relation', - 'alias' => 'alias', - ] - ], - 'tax_option_to_group' => [ - 'name' => 'Options-Groups', - 'field' => 'tax_option_to_group', - 'linked_table' => 'tax_option_to_group', - 'entity1' => [ - 'label' => 'Option', - 'listField' => 'ValueRenderFlash', - 'model' => '\common\modules\rubrication\models\TaxOption', - 'key' => 'tax_option_id', - 'linked_key' => 'tax_option_id', - ], - 'entity2' => [ - 'label' => 'Group', - 'listField' => 'name', - 'model' => '\common\modules\rubrication\models\TaxGroup', - 'key' => 'tax_group_id', - 'linked_key' => 'tax_group_id', - ], - 'via' => [ - 'model' => 'common\modules\rubrication\models\TaxOptionToGroup', - 'alias' => 'alias', - ] - ], - 'tax_option_to_option' => [ - 'name' => 'Options-Options', - 'field' => 'tax_option_to_option', - 'entity1' => [ - 'label' => 'Option', - 'listField' => 'ValueRenderFlash', - 'model' => '\common\modules\rubrication\models\TaxOption', - 'key' => 'tax_option_id', - 'linked_key' => 'tax_option1_id', - ], - 'entity2' => [ - 'label' => 'Option', - 'listField' => 'ValueRenderFlash', - 'model' => '\common\modules\rubrication\models\TaxOption', - 'key' => 'tax_option_id', - 'linked_key' => 'tax_option2_id', - ], - 'via' => [ - 'model' => 'common\modules\rubrication\models\TaxOptionRelation', - 'alias' => 'alias', - ] - ], - 'brand_cats' => [ - 'name' => 'Категории производителей', - 'field' => 'tax_option_to_option', - 'entity1' => [ - 'label' => 'Бренд', - 'listField' => 'ValueRenderFlash', - 'model' => '\common\modules\rubrication\models\TaxOption', - 'key' => 'tax_option_id', - 'linked_key' => 'tax_option1_id', - ], - 'entity2' => [ - 'label' => 'Категория', - 'listField' => 'ValueRenderFlash', - 'model' => '\common\modules\rubrication\models\TaxOption', - 'key' => 'tax_option_id', - 'linked_key' => 'tax_option2_id', - ], - 'via' => [ - 'model' => 'common\modules\rubrication\models\TaxOptionRelation', - 'alias' => 'alias', - ] - ]*/ - ] - ], ], ]; diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index f17aeaf..ae5b228 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -5,7 +5,6 @@ namespace common\modules\product\models; use common\behaviors\RuSlug; use common\components\artboxtree\ArtboxTreeBehavior; use common\components\artboxtree\ArtboxTreeHelper; -use common\modules\relation\relationBehavior; use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; use common\modules\rubrication\models\TaxGroup; use Yii; @@ -62,13 +61,7 @@ class Category extends \yii\db\ActiveRecord 'translit' => true ] ], - [ - 'class' => relationBehavior::className(), - 'relations' => [ - 'product_categories' => 'entity2', // Products of category - 'tax_group_to_category' => 'entity2', - ] - ], + ]; } diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index ac88a09..6b05538 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -10,7 +10,6 @@ use common\modules\product\behaviors\FilterBehavior; use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; use Yii; -use common\modules\relation\relationBehavior; use yii\db\ActiveQuery; use yii\db\ActiveRecord; use yii\helpers\ArrayHelper; @@ -50,13 +49,6 @@ class Product extends \yii\db\ActiveRecord { return [ [ - 'class' => relationBehavior::className(), - 'relations' => [ - 'product_categories' => 'entity1', // Product category - 'product_option' => 'entity1' // Product category - ] - ], - [ 'class' =>FilterBehavior::className(), ], [ diff --git a/common/modules/product/models/ProductCategory.php b/common/modules/product/models/ProductCategory.php index f4d9727..36d2ed8 100755 --- a/common/modules/product/models/ProductCategory.php +++ b/common/modules/product/models/ProductCategory.php @@ -2,7 +2,6 @@ namespace common\modules\product\models; -use common\modules\relation\models\Relation; use common\modules\rubrication\models\TaxOption; use Yii; @@ -14,7 +13,7 @@ use Yii; * * @property TaxOption $devCategory */ -class ProductCategory extends Relation +class ProductCategory extends \yii\db\ActiveRecord { public $alias = 'product_categories'; diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index 1054655..52809f4 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -2,8 +2,7 @@ namespace common\modules\product\models; -use common\modules\product\behaviors\FilterBehavior; -use common\modules\relation\relationBehavior; + use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; use Yii; @@ -42,22 +41,7 @@ class ProductVariant extends \yii\db\ActiveRecord /** @var array $_images */ - public $imagesUpload = []; - - /** - * @inheritdoc - */ - public function behaviors() - { - return [ - [ - 'class' => relationBehavior::className(), - 'relations' => [ - 'product_variant_option' => 'entity1' // Product variant options - ] - ], - ]; - } + public $imagesUpload = ''; /** * @inheritdoc diff --git a/common/modules/relation/Module.php b/common/modules/relation/Module.php deleted file mode 100755 index f7cac20..0000000 --- a/common/modules/relation/Module.php +++ /dev/null @@ -1,40 +0,0 @@ -render('index'); - } -} diff --git a/common/modules/relation/controllers/ManageController.php b/common/modules/relation/controllers/ManageController.php deleted file mode 100755 index 49242a1..0000000 --- a/common/modules/relation/controllers/ManageController.php +++ /dev/null @@ -1,238 +0,0 @@ - [ - 'class' => ContentNegotiator::className(), - 'only' => ['autocomplete'], - 'formats' => [ 'application/json' => Response::FORMAT_JSON], - 'languages' => [ - 'ru', - ], - ],*/ - ]; - } - - /** - * Renders the relations view - * @return string - */ - public function actionIndex() - { - $relations = relationHelper::getRelations(); - $list = []; - foreach ($relations as $key => $relation) { - $list[] = [ - 'key' => $key, - 'name' => $relation['name'], - 'entity1_label' => $relation['entity1']['label'], - 'entity1_model' => $relation['entity1']['model'], - 'entity2_label' => $relation['entity2']['label'], - 'entity2_model' => $relation['entity2']['model'], - ]; - } - return $this->render('relations', [ - 'relations' => $list - ]); - } - /** - * Renders the pars view for - * @return string - */ - public function actionPars($relation) - { - $relation_key = strtolower($relation); - $relation = relationHelper::getRelation($relation_key); - - $dataProvider = new ActiveDataProvider([ - 'query' => $relation['via']['model']::find(), - ]); - - return $this->render('pars', [ - 'dataProvider' => $dataProvider, - 'relation_key' => $relation_key, - 'relation' => $relation, - ]); - } - - public function actionCreate($relation) { - $relation_key = strtolower($relation); - $relation = relationHelper::getRelation($relation_key); - - $model = new $relation['via']['model']; - - if ($model->load(Yii::$app->request->post())) { - $model->save(); - return $this->redirect(['pars', 'relation' => $relation_key]); -// return $this->redirect(['update', 'id' => $model->{$relation['entity1']['linked_key']}. ':' .$model->{$relation['entity2']['linked_key']}]); - } else { - return $this->render('create', [ - 'model' => $model, -// 'items1' => $query1->limit(100)->all(), -// 'items2' => $query2->asArray()->all(), - 'relation_key' => $relation_key, - 'relation' => $relation, - ]); - } - } - - /** - * Updates an existing TaxGroup model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param integer $id - * @return mixed - */ - public function actionUpdate($relation, $id) { - $relation_key = strtolower($relation); - $relation = relationHelper::getRelation($relation_key); - - list($id1, $id2) = explode(':', $id); - - $model = $this->findModel($relation_key, $id1, $id2); - - if ($model->load(Yii::$app->request->post())) { - $connection = Yii::$app->getDb(); - $transaction = $connection->beginTransaction(); - try { - // Delete links from viaTable - $connection->createCommand() - ->update - ( - $relation['linked_table'], - [ - $relation['entity1']['linked_key'] => $model->getAttribute($relation['entity1']['linked_key']), - $relation['entity2']['linked_key'] => $model->getAttribute($relation['entity2']['linked_key']) - ], - $this->getWhere($relation_key, $id1, $id2) - ) - ->execute(); - $transaction->commit(); - } catch (Exception $ex) { - $transaction->rollback(); - throw $ex; - } - - return $this->redirect(['pars', 'relation' => $relation_key]); - } else { - return $this->render('update', [ - 'model' => $model, - 'value1' => $model->entity1->getAttribute($relation['entity1']['listField']), - 'value2' => $model->entity2->getAttribute($relation['entity2']['listField']), - 'relation_key' => $relation_key, - 'relation' => $relation, - ]); - } - } - - /** - * Deletes an existing TaxGroup model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param integer $id - * @return mixed - */ - public function actionDelete($relation, $id) - { - $relation_key = strtolower($relation); - $relation = relationHelper::getRelation($relation_key); - - list($id1, $id2) = explode(':', $id); - - $connection = Yii::$app->getDb(); - $transaction = $connection->beginTransaction(); - try { - // Delete links from viaTable - $connection->createCommand() - ->delete - ( - $relation['linked_table'], - $this->getWhere($relation_key, $id1, $id2) - ) - ->execute(); - $transaction->commit(); - } catch (Exception $ex) { - $transaction->rollback(); - throw $ex; - } - - return $this->redirect(['pars', 'relation' => $relation_key]); - } - - public function actionAutocomplete() { - $relation_key = Yii::$app->request->get('relation_key'); - $entity = Yii::$app->request->get('entity'); - $term = Yii::$app->request->get('term'); - $relation_key = strtolower($relation_key); - $relation = relationHelper::getRelation($relation_key); - - /** @var ActiveQuery $query */ - $query = $relation[$entity]['model']::find(); - - if (!empty($relation[$entity]['searchJoin'])) { - $query->innerJoinWith($relation[$entity]['searchJoin']); - } - if (!empty($relation[$entity]['where'])) { - $query->where($relation[$entity]['where']); - } - $query->where(['ilike', $relation[$entity]['searchField'], $term]); - - print json_encode(ArrayHelper::map($query->limit(50)->all(), $relation[$entity]['key'], $relation[$entity]['listField'])); - exit; - } - - /** - * Finds the based model for relation on its primaries keys value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param string $relation - * @param integer $id1 - * @param integer $id2 - * @return ActiveRecord the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($relation, $id1, $id2) - { - $relation_key = strtolower($relation); - $relation = relationHelper::getRelation($relation_key); - if (($model = $relation['via']['model']::findOne($this->getWhere($relation_key, $id1, $id2))) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } - } - - protected function getWhere($relation_key, $id1, $id2) { - $relation = relationHelper::getRelation($relation_key); - // @todo Just think - if you need to search keys in the reverse order - $where = [ - $relation['entity1']['linked_key'] => $id1, - $relation['entity2']['linked_key'] => $id2, - ]; - if (!empty($relation['alias'])) { - $where[$relation['alias']] = $relation_key; - } - return $where; - } - -} diff --git a/common/modules/relation/models/Relation.php b/common/modules/relation/models/Relation.php deleted file mode 100755 index a7fe4df..0000000 --- a/common/modules/relation/models/Relation.php +++ /dev/null @@ -1,78 +0,0 @@ - 50] - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'alias' => Yii::t('relation', 'Alias'), - 'entity1_id' => Yii::t('relation', 'Entity1 ID'), - 'entity2_id' => Yii::t('relation', 'Entity2 ID'), - 'entity1' => Yii::t('relation', 'Entity1 ID'), - 'entity2' => Yii::t('relation', 'Entity2 ID'), - ]; - } - - /** - * @inheritdoc - * @return RelationQuery the active query used by this AR class. - */ - public static function find() - { - return new RelationQuery(get_called_class()); - } - - public function getRelationSection() { - return relationHelper::getRelation($this->alias); - } - - public function getEntity1() { - return $this->getEntity('entity1'); - } - - public function getEntity2() { - return $this->getEntity('entity2'); - } - - protected function getEntity($entity) { - $relation = $this->getRelationSection(); - if (!$relation) - return; - return $this->hasOne($relation[$entity]['model']::className(), [$relation[$entity]['key'] => $relation[$entity]['linked_key']]); - } -} diff --git a/common/modules/relation/models/RelationQuery.php b/common/modules/relation/models/RelationQuery.php deleted file mode 100755 index 7948f50..0000000 --- a/common/modules/relation/models/RelationQuery.php +++ /dev/null @@ -1,35 +0,0 @@ -andWhere('[[status]]=1'); - return $this; - }*/ - - /** - * @inheritdoc - * @return Relation[]|array - */ - public function all($db = null) - { - return parent::all($db); - } - - /** - * @inheritdoc - * @return Relation|array|null - */ - public function one($db = null) - { - return parent::one($db); - } -} \ No newline at end of file diff --git a/common/modules/relation/relationBehavior.php b/common/modules/relation/relationBehavior.php deleted file mode 100755 index 138977f..0000000 --- a/common/modules/relation/relationBehavior.php +++ /dev/null @@ -1,243 +0,0 @@ -relations as $relation_key => &$relation) { - if (is_string($relation)) { - // Get data from module's data - $relation_entity = $relation; - $relation = $this->_getRelationParams($relation_key); - $relation['inner'] = $relation[$relation_entity]; - $relation['outer'] = $relation[$relation_entity == 'entity1' ? 'entity2' : 'entity1']; - $relation['linked_table'] = $relation['via']['model']::tableName(); - if (!empty($relation['via']['alias'])) { - $relation['linked_alias'] = $relation['via']['alias']; - } - } - $this->fields[$relation['field']] = $relation_key; - - } - } - - /* - * Events for auto-drive relations data - */ - public function events() - { - return [ - ActiveRecord::EVENT_AFTER_INSERT => 'relationsAfterSave', - ActiveRecord::EVENT_AFTER_UPDATE => 'relationsAfterSave', - ActiveRecord::EVENT_BEFORE_DELETE => 'relationBeforeDelete', - ]; - } - - public function relationsAfterSave($insert) { - - if (is_array($modelPrimaryKey = $this->owner->getPrimaryKey())) { - throw new ErrorException('This behavior does not support composite primary keys'); - } - - foreach ($this->relations as $relation_key => $relation) { - if (empty($relation['field']) || !is_array($this->{$relation['field']})) - continue; - - $values = $this->{$relation['field']}; - - /** @var ActiveRecord $model */ - $model = new $relation['inner']['model']; - - $connection = $model::getDb(); - $transaction = $connection->beginTransaction(); - - $delete_where = [$relation['inner']['linked_key'] => $this->owner->{$relation['inner']['key']}]; - if (!empty($relation['linked_alias'])) { - $delete_where[$relation['linked_alias']] = $relation_key; - } - - try { - // Delete all links from viaTable - $connection->createCommand() - ->delete - ( - $relation['linked_table'], - $delete_where - ) - ->execute(); - - if (!empty($values)) { - - foreach($values as $value) { - $insertData = [ - $relation['inner']['linked_key'] => $this->owner->{$relation['inner']['key']}, - $relation['outer']['linked_key'] => $value - ]; - if (!empty($relation['linked_alias'])) { - $insertData[$relation['linked_alias']] = $relation_key; - } - - - $connection->createCommand() - ->insert - ( - $relation['linked_table'], - $insertData - ) - ->execute(); - } - } - $transaction->commit(); - -// $model->link($relation_key, ) - } catch (Exception $ex) { -// var_dump($relation_key, $relation);exit; - $transaction->rollback(); - throw $ex; - } - } - } - - public function relationBeforeDelete() { - if (is_array($modelPrimaryKey = $this->owner->getPrimaryKey())) { - throw new ErrorException('This behavior does not support composite primary keys'); - } - foreach ($this->relations as $relation_key => $relation) { - if (empty($relation['field'])) - continue; - $values = $this->{$relation['field']}; - - /** @var ActiveRecord $model */ - $model = new $relation['inner']['model']; - - $connection = $model::getDb(); - $transaction = $connection->beginTransaction(); - - // @todo Refix to ActiveRecord format - try { - // Delete all links from viaTable - $connection->createCommand() - ->delete - ( - $relation['linked_table'], - [$relation['inner']['linked_key'] => $this->owner->{$relation['inner']['key']}] - ) - ->execute(); - $transaction->commit(); - } catch (Exception $ex) { - $transaction->rollback(); - throw $ex; - } - } - } - - /** - * Get related data for $relation - * @params string $relation Relation key - */ - public function getRelations($relation) { - $relation = $this->_getRelation($relation); - return - $this->owner - ->hasMany($relation['outer']['model'], [$relation['outer']['key'] => $relation['outer']['linked_key']]) - ->viaTable($relation['linked_table'], [$relation['inner']['linked_key'] => $relation['inner']['key']]); - } - - /* - * Get relation params for $relation - * @param string $relation Relation key - */ - protected function _getRelation($relation) { - $relation = strtolower($relation); - return isset($this->relations[$relation]) ? $this->relations[$relation] : null; - } - - /** - * Return relation data from main app config - * @params string $section Relations key - */ - protected function _getRelationParams($section) { - $relation = relationHelper::getRelation($section); - if (!$relation) - throw new Exception('Relation "' . $section . '" not set on this application.'); - return $relation; - } - - protected function _getRelationNameByField($field) { - return isset($this->fields[$field]) ? $this->fields[$field] : null; - } - - protected function _getRelationByField($field) { - return ( isset($this->fields[$field]) && isset($this->relations[$this->fields[$field]]) ) ? $this->relations[$this->fields[$field]] : null; - } - - /** - * @inheritdoc - */ - public function canGetProperty($name, $checkVars = true) - { - return true; - } - - /** - * @inheritdoc - */ - public function canSetProperty($name, $checkVars = true) - { - return array_key_exists($name, $this->fields) ? - true : parent::canSetProperty($name, $checkVars = true); - } - - /** - * @inheritdoc - */ - public function __set($name, $value) { - if (isset($this->fields[$name])) { - $this->values[$name] = $value; - } - } - - /** - * @inheritdoc - */ - public function __get($name) { - if (isset($this->values[$name])) { - return $this->values[$name]; - } else { - $relation_key = $this->_getRelationNameByField($name); - if (!$relation_key) - return; - - return $this->getRelations($relation_key); - } - } -} \ No newline at end of file diff --git a/common/modules/relation/relationHelper.php b/common/modules/relation/relationHelper.php deleted file mode 100755 index f90cfab..0000000 --- a/common/modules/relation/relationHelper.php +++ /dev/null @@ -1,60 +0,0 @@ -getModule('relation'); - - if (!is_array($module->relations)) - return []; - - return $module->relations; - } - - /** - * Return one relation for key $name - * @param string $name - * @return string (@todo refix to relationOject) - */ - public static function getRelation($name) { - $name = strtolower($name); - if (isset(self::$relations[$name])) { - return self::$relations[$name]; - } - $relations = self::getRelations(); - if (isset($relations[$name])) { - self::$relations[$name] = self::prepareRelation($relations[$name]); - } else { - self::$relations[$name] = null; - } - return self::$relations[$name]; - } - - - private static function prepareRelation($relation) { - if (!isset($relation['linked_table']) && isset($relation['via']['model'])) { - $relation['linked_table'] = $relation['via']['model']::tableName(); - } - return $relation; - } - - /** - * @param string $name - * @return bool - */ - public static function issetRelation($name) { - $relations = self::getRelations(); - return isset($relations[$name]); - } -} \ No newline at end of file diff --git a/common/modules/relation/relationObject.php b/common/modules/relation/relationObject.php deleted file mode 100755 index ae04cb8..0000000 --- a/common/modules/relation/relationObject.php +++ /dev/null @@ -1,29 +0,0 @@ -_getRelationParams($relation_key); - $relation['inner'] = $relation[$relation_entity]; - $relation['outer'] = $relation[$relation_entity == 'entity1' ? 'entity2' : 'entity1']; - $relation['linked_table'] = $relation['via']['model']::tableName(); - } - - $this->moduleRelations = relationHelper::getRelations(); - - - } -} \ No newline at end of file diff --git a/common/modules/relation/relationQueryTrait.php b/common/modules/relation/relationQueryTrait.php deleted file mode 100755 index 27a0354..0000000 --- a/common/modules/relation/relationQueryTrait.php +++ /dev/null @@ -1,33 +0,0 @@ -modelClass; - self::$model = new $class; - } - return self::$model; - } - - /*public function getRelations($relation) { - $model = $this->getModel(); - - $relation = $model->_getRelation($relation); - return - $model->owner - ->hasMany($relation['outer']['model'], [$relation['outer']['key'] => $relation['outer']['linked_key']]) - ->viaTable($relation['linked_table'], [$relation['inner']['linked_key'] => $relation['inner']['key']]); - }*/ -} \ No newline at end of file diff --git a/common/modules/relation/views/default/index.php b/common/modules/relation/views/default/index.php deleted file mode 100755 index dc021a6..0000000 --- a/common/modules/relation/views/default/index.php +++ /dev/null @@ -1,12 +0,0 @@ -
- This is the view content for action "= $this->context->action->id ?>". - The action belongs to the controller "= get_class($this->context) ?>" - in the "= $this->context->module->id ?>" module. -
-
- You may customize this page by editing the following file:
- = __FILE__ ?>
-
- = Html::a(Yii::t('relation', 'Create relation'), ['create?relation='. $relation_key], ['class' => 'btn btn-success']) ?> -
- - = GridView::widget([ - 'dataProvider' => $dataProvider, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - 'alias', - 'entity1.'. $relation['entity1']['listField'], - 'entity2.'. $relation['entity2']['listField'], - [ - 'class' => 'yii\grid\ActionColumn', - 'template' => '{update} {delete}', - 'buttons' => [ - 'update' => function ($url, $model) { - return Html::a('', $url, [ - 'title' => Yii::t('relation', 'Edit par'), - ]); - }, - 'delete' => function ($url, $model) { - return Html::a('', $url, [ - 'title' => Yii::t('relation', 'Delete par'), - ]); - }, - ], - 'urlCreator' => function ($action, $model, $key, $index) use ($relation, $relation_key) { - if ($action === 'update') { - $url ='/admin/relation/manage/update?relation='. $relation_key .'&id='. $model->{$relation['entity1']['linked_key']} .':'. $model->{$relation['entity2']['linked_key']}; - return $url; - } - if ($action === 'delete') { - $url ='/admin/relation/manage/delete?relation='. $relation_key .'&id='. $model->{$relation['entity1']['linked_key']} .':'. $model->{$relation['entity2']['linked_key']}; - return $url; - } - } - ], - ], - ]); ?> -