Commit 5aa35456359c65eb9fd41fce1383bf63726c7eb5

Authored by andryeyev
1 parent 39abb017

add ShopCategory

Showing 1 changed file with 86 additions and 0 deletions   Show diff stats
common/models/ShopCategory.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\db\Query;
  8 +
  9 +/**
  10 + * Signup form
  11 + */
  12 +class ShopCategory extends Model
  13 +{
  14 + /**
  15 + * весь список терминов
  16 + */
  17 + static function get ()
  18 + {
  19 + return yii::$app->db->createCommand('
  20 + SELECT
  21 + `termin_relation`.termin_id_1,
  22 + `termin_relation`.termin_id_2,
  23 + `termin_lang`.termin_title
  24 + FROM `termin_relation`
  25 + INNER JOIN `termin_lang` ON `termin_lang`.termin_id = `termin_relation`.termin_id_1
  26 + AND `termin_lang`.lang_id = '.yii::$app->lang_id.'
  27 + INNER JOIN `template` ON `template`.template_id = `termin_lang`.template_id
  28 + ORDER BY `termin_relation`.termin_id_1 ASC, `termin_relation`.termin_id_2 ASC
  29 + ')->queryAll();
  30 + }
  31 +
  32 + // ===================
  33 + // ==== STRUCTURE ====
  34 + // ===================
  35 +
  36 + var $mass = array ();
  37 +
  38 + public function build ()
  39 + {
  40 + if ($this->mass = self::get ())
  41 + {
  42 + return $this->getRecrusive (8);
  43 + }
  44 + }
  45 +
  46 + public function findChild ($id)
  47 + {
  48 + $mass = array ();
  49 +
  50 + foreach ($this->mass as $row)
  51 + {
  52 + if ($row['termin_id_2'] == $id)
  53 + {
  54 + $mass[] = $row;
  55 + }
  56 + }
  57 +
  58 + return $mass;
  59 + }
  60 +
  61 + public function getRecrusive ($menu_id)
  62 + {
  63 + $items = $this->findChild($menu_id);
  64 +
  65 + if (! empty ($items))
  66 + {
  67 + echo '<ul>';
  68 +
  69 + foreach ($items as $row)
  70 + {
  71 + echo '<li>'.$row['termin_title'].'</li>';
  72 +
  73 + if ($row['termin_id_2'] != 0)
  74 + {
  75 + $this->getRecrusive($row['termin_id_1']);
  76 + }
  77 + }
  78 +
  79 + echo '</ul>';
  80 + }
  81 +
  82 + }
  83 +
  84 + // =====
  85 +
  86 +}
... ...