Browse Source

Suppression attribut 'class' inutile dans la méthode "defaultOptionsSearch"

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
a88d04f14b
6 changed files with 14 additions and 9 deletions
  1. +12
    -5
      common/components/ActiveRecordCommon.php
  2. +0
    -1
      common/models/CreditHistory.php
  3. +0
    -1
      common/models/Invoice.php
  4. +0
    -1
      common/models/Order.php
  5. +2
    -0
      common/models/PointSale.php
  6. +0
    -1
      common/models/Subscription.php

+ 12
- 5
common/components/ActiveRecordCommon.php View File



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'])) {

+ 0
- 1
common/models/CreditHistory.php View File

*/ */
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',

+ 0
- 1
common/models/Invoice.php View File

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',

+ 0
- 1
common/models/Order.php View File

*/ */
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',

+ 2
- 0
common/models/PointSale.php View File

); );
} }


/** /**
* Initialise les commandes liées au point de vente. * Initialise les commandes liées au point de vente.
* *

+ 0
- 1
common/models/Subscription.php View File

*/ */
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',

Loading…
Cancel
Save