diff --git a/src/Action/UpdateAction.php b/src/Action/UpdateAction.php index 8d00641..4050577 100644 --- a/src/Action/UpdateAction.php +++ b/src/Action/UpdateAction.php @@ -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); } } - diff --git a/src/Model/BaseModel.php b/src/Model/BaseModel.php index 7062914..9d862f2 100644 --- a/src/Model/BaseModel.php +++ b/src/Model/BaseModel.php @@ -127,30 +127,32 @@ public static function getTotalCount($countField = null) * Gets all active * @author Adegoke Obasa * @author Olawale Lawal + * @author Adeyemi Olaoye * @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 - * @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 * @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] + ); }