class ActiveRecordCommon extends \yii\db\ActiveRecord | 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 | * Méthode générique de recherche utilisée pour tous les modèles. Elle a | ||||
{ | { | ||||
$class = get_called_class() ; | $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) ; | $options = array_merge($default_options, $options) ; | ||||
$pk = $class::primaryKey() ; | $pk = $class::primaryKey() ; | ||||
$options['type_search'] = self::SEARCH_ALL ; | $options['type_search'] = self::SEARCH_ALL ; | ||||
} | } | ||||
$records = $options['class']::find() ; | |||||
$records = $class::find() ; | |||||
// With | // With | ||||
if(is_array($options['with']) && count($options['with'])) { | if(is_array($options['with']) && count($options['with'])) { |
*/ | */ | ||||
public static function defaultOptionsSearch() { | public static function defaultOptionsSearch() { | ||||
return [ | return [ | ||||
'class' => 'CreditHistory', | |||||
'with' => [], | 'with' => [], | ||||
'join_with' => [], | 'join_with' => [], | ||||
'orderby' => self::tableName().'.date ASc', | 'orderby' => self::tableName().'.date ASc', |
public static function defaultOptionsSearch() | public static function defaultOptionsSearch() | ||||
{ | { | ||||
return [ | return [ | ||||
'class' => 'Invoice', | |||||
'with' => [], | 'with' => [], | ||||
'join_with' => [], | 'join_with' => [], | ||||
'orderby' => self::tableName().'.date ASc', | 'orderby' => self::tableName().'.date ASc', |
*/ | */ | ||||
public static function defaultOptionsSearch() { | public static function defaultOptionsSearch() { | ||||
return [ | return [ | ||||
'class' => 'Order', | |||||
'with' => ['productOrder', 'creditHistory', 'pointSale'], | 'with' => ['productOrder', 'creditHistory', 'pointSale'], | ||||
'join_with' => ['production', 'user', 'user.userProducer'], | 'join_with' => ['production', 'user', 'user.userProducer'], | ||||
'orderby' => 'order.date ASC', | 'orderby' => 'order.date ASC', |
); | ); | ||||
} | } | ||||
/** | /** | ||||
* Initialise les commandes liées au point de vente. | * Initialise les commandes liées au point de vente. | ||||
* | * |
*/ | */ | ||||
public static function defaultOptionsSearch() { | public static function defaultOptionsSearch() { | ||||
return [ | return [ | ||||
'class' => 'Subscription', | |||||
'with' => ['producer', 'pointSale', 'productSubscription'], | 'with' => ['producer', 'pointSale', 'productSubscription'], | ||||
'join_with' => ['user'], | 'join_with' => ['user'], | ||||
'orderby' => 'user.name ASC', | 'orderby' => 'user.name ASC', |