-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
2 changed files
with
25 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,30 +127,32 @@ public static function getTotalCount($countField = null) | |
* Gets all active | ||
* @author Adegoke Obasa <[email protected]> | ||
* @author Olawale Lawal <[email protected]> | ||
* @author Adeyemi Olaoye <[email protected]> | ||
* @param array $orderBy | ||
* @return array|\yii\db\ActiveRecord[] | ||
* @param string $activeColumn | ||
* @param int $activeValue | ||
* @return array|ActiveRecord[] | ||
*/ | ||
public static function getActive($orderBy = []) | ||
public static function getActive($orderBy = [], $activeColumn = 'is_active', $activeValue = 1) | ||
{ | ||
$model = get_called_class(); | ||
$model = new $model; | ||
return self::find() | ||
->asArray() | ||
->orderBy($orderBy) | ||
->all(); | ||
return self::findActive($orderBy, $activeColumn, $activeValue)->all(); | ||
} | ||
|
||
/** | ||
* Gets all active | ||
* @author Adeyemi Olaoye <[email protected]> | ||
* @return array|\yii\db\ActiveRecord[] | ||
* @param array $orderBy | ||
* @param string $activeColumn | ||
* @param int $activeValue | ||
* @return ActiveQuery | ||
*/ | ||
public static function findActive() | ||
public static function findActive($orderBy = [], $activeColumn = 'is_active', $activeValue = 1) | ||
{ | ||
/** @var self $model */ | ||
$model = get_called_class(); | ||
$model = new $model; | ||
return self::find() | ||
->all(); | ||
return $model::find() | ||
->where([$activeColumn => $activeValue]) | ||
->orderBy($orderBy); | ||
} | ||
|
||
|
||
|
@@ -172,16 +174,22 @@ public static function getIdByField($field, $value) | |
* @author Olawale Lawal <[email protected]> | ||
* @param $startDate | ||
* @param $endDate | ||
* @param string $createdAtColumn | ||
* @return array|ActiveQuery | ||
*/ | ||
public static function getByCreatedDateRange($startDate, $endDate) | ||
{ | ||
public static function getByCreatedDateRange( | ||
$startDate, | ||
$endDate, | ||
$createdAtColumn = 'created_at' | ||
) { | ||
$model = get_called_class(); | ||
$model = new $model; | ||
|
||
return self::find() | ||
->andWhere($model::tableName() . '.created_at BETWEEN :start_date AND :end_date') | ||
->params(['start_date' => $startDate, 'end_date' => $endDate]); | ||
->andWhere( | ||
$model::tableName() . '.' . $createdAtColumn . ' BETWEEN :start_date AND :end_date', | ||
['start_date' => $startDate, 'end_date' => $endDate] | ||
); | ||
} | ||
|
||
|
||
|