Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeyemi Olaoye committed Jun 20, 2017
2 parents 594e16a + c4cc2b7 commit 8140360
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/Action/UpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ public function run()
if (!$this->model->save()) {
return $controller->returnError($this->model->getErrors());
}

} catch (IntegrityException $ex) {
return $controller->returnError($this->integrityExceptionMessage);
}
return $controller->returnSuccess($this->successMessage);
}
}

42 changes: 25 additions & 17 deletions src/Model/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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]
);
}


Expand Down

0 comments on commit 8140360

Please sign in to comment.