@@ -40,9 +40,9 @@ namespace common\components ; | |||
class ActiveRecordCommon extends \yii\db\ActiveRecord | |||
{ | |||
const SEARCH_ALL = 'all' ; | |||
const SEARCH_ONE = 'one' ; | |||
const SEARCH_COUNT = 'count' ; | |||
const SEARCH_ALL = 'all' ; | |||
const SEARCH_ONE = 'one' ; | |||
const SEARCH_COUNT = 'count' ; | |||
/** | |||
* Méthode générique de recherche utilisée pour tous les modèles. Elle a | |||
@@ -57,7 +57,14 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord | |||
{ | |||
$class = get_called_class() ; | |||
$default_options = $class::defaultOptionsSearch() ; | |||
if(is_callable([$class, 'defaultOptionsSearch'])) { | |||
$default_options = $class::defaultOptionsSearch() ; | |||
} | |||
else { | |||
throw new \ErrorException('La méthode "defaultOptionsSearch" n\'est ' | |||
. 'pas définie dans la classe "'.$class.'"'); | |||
} | |||
$options = array_merge($default_options, $options) ; | |||
$pk = $class::primaryKey() ; | |||
@@ -71,7 +78,7 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord | |||
$options['type_search'] = self::SEARCH_ALL ; | |||
} | |||
$records = $options['class']::find() ; | |||
$records = $class::find() ; | |||
// With | |||
if(is_array($options['with']) && count($options['with'])) { |
@@ -139,7 +139,6 @@ class CreditHistory extends ActiveRecord | |||
*/ | |||
public static function defaultOptionsSearch() { | |||
return [ | |||
'class' => 'CreditHistory', | |||
'with' => [], | |||
'join_with' => [], | |||
'orderby' => self::tableName().'.date ASc', |
@@ -116,7 +116,6 @@ class Invoice extends \yii\db\ActiveRecord | |||
public static function defaultOptionsSearch() | |||
{ | |||
return [ | |||
'class' => 'Invoice', | |||
'with' => [], | |||
'join_with' => [], | |||
'orderby' => self::tableName().'.date ASc', |
@@ -152,7 +152,6 @@ class Order extends ActiveRecordCommon | |||
*/ | |||
public static function defaultOptionsSearch() { | |||
return [ | |||
'class' => 'Order', | |||
'with' => ['productOrder', 'creditHistory', 'pointSale'], | |||
'join_with' => ['production', 'user', 'user.userProducer'], | |||
'orderby' => 'order.date ASC', |
@@ -141,6 +141,8 @@ class PointSale extends \yii\db\ActiveRecord | |||
); | |||
} | |||
/** | |||
* Initialise les commandes liées au point de vente. | |||
* |
@@ -153,7 +153,6 @@ class Subscription extends ActiveRecordCommon | |||
*/ | |||
public static function defaultOptionsSearch() { | |||
return [ | |||
'class' => 'Subscription', | |||
'with' => ['producer', 'pointSale', 'productSubscription'], | |||
'join_with' => ['user'], | |||
'orderby' => 'user.name ASC', |