tableName() public static method

public static tableName ( )
Exemplo n.º 1
0
 public function actionNameFilter($q = null, $id = null)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $output = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($q)) {
         $sql = 'SELECT id, name AS text FROM ' . School::tableName() . ' WHERE name LIKE :like ORDER BY name ASC LIMIT 25';
         $output['results'] = Yii::$app->db->createCommand($sql, [':like' => "%{$q}%"])->queryAll();
     } elseif ($id > 0 && ($school = School::findOne($id))) {
         $output['results'] = ['id' => $id, 'text' => $school->name];
     }
     return $output;
 }
Exemplo n.º 2
0
 public function getAllSchools($lastIds = [], $lastDate = 0, $orderBy = self::ORDER_BY_LIKE_SHOW, $dateCreateType = self::DATE_CREATE_ALL, $userId = false, $limit = false)
 {
     $query = School::find()->from(["t" => School::tableName()])->andWhere('t.deleted = 0')->addSelect('*');
     if ($lastDate != 0) {
         if ($dateCreateType == self::DATE_CREATE_AFTER) {
             $query = $query->andWhere('t.date >= :date', [':date' => $lastDate]);
         } elseif ($dateCreateType != self::DATE_CREATE_ALL) {
             $query = $query->andWhere('t.date <= :date', [':date' => $lastDate]);
         }
         if (!empty($lastIds)) {
             $query = $query->andWhere(['not in', 'id', $lastIds]);
         }
     }
     // Определяем сортировку
     if ($orderBy == self::ORDER_BY_ID) {
         $query = $query->orderBy('id DESC');
     } elseif ($orderBy == self::ORDER_BY_DATE) {
         if ($dateCreateType == self::DATE_CREATE_AFTER) {
             $query = $query->orderBy('date ASC');
         } else {
             $query = $query->orderBy('date DESC');
         }
     } elseif ($orderBy == self::ORDER_BY_LIKE) {
         $query = $query->orderBy('like_count DESC');
     } elseif ($orderBy == self::ORDER_BY_SHOW) {
         $query = $query->orderBy('show_count DESC');
     } elseif ($orderBy == self::ORDER_BY_LIKE_SHOW) {
         $query = $query->addSelect(['(like_count * 15 + show_count) as like_show_count'])->orderBy('like_show_count DESC');
     }
     // Определяем за какой период будем показывать
     if (!empty($limit)) {
         $query = $query->limit((int) $limit);
     } elseif ($dateCreateType == self::DATE_CREATE_ALL) {
         $query = $query->limit(self::DEFAULT_LIMIT);
     } elseif ($dateCreateType == self::DATE_CREATE_BEFORE) {
         $query = $query->andWhere('t.date <= :date', [':date' => time()])->limit(self::DEFAULT_LIMIT);
     } elseif ($dateCreateType == self::DATE_CREATE_AFTER) {
         $query = $query->andWhere('t.date >= :date', [':date' => time()])->limit(self::DEFAULT_LIMIT);
     }
     if (!empty($userId)) {
         $query = $query->andWhere('user_id = :userId', [':userId' => $userId]);
     }
     $query = $query->with(['tagEntity', 'tagEntity.tags', 'locations']);
     return $query->all();
 }
Exemplo n.º 3
0
 public function actionNameFilter($q = null, $id = null)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $output = ['results' => ['id' => '', 'text' => '']];
     if (!is_null($q)) {
         $sql = 'SELECT t0.id, CONCAT(t1.name, \'-\', t0.name) AS text FROM ' . Store::tableName() . ' AS t0 LEFT JOIN ' . School::tableName() . ' AS t1 ON t0.school_id = t1.id WHERE t0.name LIKE :like ORDER BY t0.school_id ASC LIMIT 25';
         $output['results'] = Yii::$app->db->createCommand($sql, [':like' => "%{$q}%"])->queryAll();
     } elseif ($id > 0 && ($store = Store::findOne($id))) {
         $output['results'] = ['id' => $id, 'text' => $store->school->name . '-' . $store->name];
     }
     return $output;
 }
Exemplo n.º 4
0
 public function actionData()
 {
     $schools = School::find()->from(["t" => School::tableName()])->andWhere('t.deleted = 0')->addSelect('*')->addSelect(['(like_count * 15 + show_count) as like_show_count'])->orderBy('like_show_count DESC')->with(['locations'])->all();
     $data = [];
     foreach ($schools as $school) {
         $locations = $school->locations;
         foreach ($locations as $location) {
             $value = ['lat' => $location->lat, 'lng' => $location->lng, 'zoom' => $location->zoom, 'title' => $location->title, 'title-url' => $school->getUrl(), 'site-url' => $school->site, 'type' => $location->getTypeLocal(), 'description' => $location->getDescription(), 'school-title' => $school->getTitle()];
             $data[] = $value;
         }
     }
     return json_encode($data);
 }