Skip to content

Commit

Permalink
Add LangQuery model
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Loban committed Apr 21, 2016
1 parent 614894e commit c5f063a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/models/Lang.php
Expand Up @@ -93,30 +93,46 @@ public function getStatusList()
}

/**
* @param bool $active
* @param bool $active default false so it is most often used in backend
* @return array
*/
public static function getList($active = false)
{
$condition = $active ? ['status' => self::STATUS_ACTIVE] : [];

return static::find()
$query = static::find()
->select(['name', 'id'])
->filterWhere($condition)
->orderBy('id')
->indexBy('id')
->column();
->indexBy('id');

if ($active == true) {
$query->active();
}

return $query->column();
}

/**
* @param bool $active default true so it is most often used in frontend
* @return array
*/
public static function getLocaleList()
public static function getLocaleList($active = true)
{
return static::find()
$query = static::find()
->select(['locale', 'id'])
->where(['status' => self::STATUS_ACTIVE])
->indexBy('id')
->column();
->indexBy('id');

if ($active == true) {
$query->active();
}

return $query->column();
}

/**
* @inheritdoc
* @return LangQuery the active query used by this AR class.
*/
public static function find()
{
return new LangQuery(get_called_class());
}
}
18 changes: 18 additions & 0 deletions src/models/LangQuery.php
@@ -0,0 +1,18 @@
<?php

namespace lav45\translate\models;

use yii\db\ActiveQuery;

/**
* This is the ActiveQuery class for [[Lang]].
*
* @see Lang
*/
class LangQuery extends ActiveQuery
{
public function active()
{
return $this->andWhere(['status' => Lang::STATUS_ACTIVE]);
}
}

0 comments on commit c5f063a

Please sign in to comment.