SHARE
TWEET

Untitled

a guest Jun 18th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace app\modules\system\daemon\models;
  4.  
  5. use app\modules\system\daemon\models\enums\DaemonType;
  6. use yii\base\Model;
  7. use yii\data\ActiveDataProvider;
  8. use yii\data\ArrayDataProvider;
  9.  
  10. class DaemonNameSearch extends DaemonName
  11. {
  12.  
  13.   public function rules()
  14.   {
  15.     return [
  16.       [[static::$TYPE_CODE_FIELD], 'integer'],
  17.       [[static::$NAME_FIELD, static::$TRANSLATED_NAME_FIELD, static::$LAUNCHER_FIELD, static::$GREP_FIELD], 'string'],
  18.       [[static::$TYPE_ID_FIELD, static::$IS_ACTIVE_FIELD, static::$PID_FIELD, static::$TYPE_NAME_FIELD,], 'safe'],
  19.     ];
  20.   }
  21.  
  22.  
  23.   public function scenarios()
  24.   {
  25.     return Model::scenarios();
  26.   }
  27.  
  28.   public function search($params)
  29.   {
  30.     $models = DaemonNameQuery::find()->all();
  31.     $daemons = [];
  32.     $personalShop = array_filter($models, function ($daemon) {
  33.       return $daemon->{DaemonName::$TYPE_CODE_FIELD} == DaemonType::$PERSONAL_SHOP;
  34.     });
  35.     $shops = Shop::find()->all();
  36.     foreach ($shops as $shop) {
  37.       foreach ($personalShops as $daemon) {
  38.  
  39.         $daemonModel = new DaemonName();
  40.         $daemonModel->{DaemonName::$NAME_FIELD} = $daemon->{DaemonName::$NAME_FIELD};
  41.         $daemonModel->{DaemonName::$TRANSLATED_NAME_FIELD} = $daemon->{DaemonName::$TRANSLATED_NAME_FIELD};
  42.         $daemonModel->{DaemonName::$LAUNCHER_FIELD} = $daemon->{DaemonName::$LAUNCHER_FIELD};
  43.         $daemonModel->{DaemonName::$TYPE_CODE_FIELD} = $daemon->{DaemonName::$TYPE_CODE_FIELD};
  44.         $daemonModel->{DaemonName::$GREP_FIELD} = $daemon->{DaemonName::$GREP_FIELD};
  45.  
  46.         $daemonModel->{DaemonName::$TYPE_ID_FIELD} = $shop->id;
  47.         $daemonModel->{DaemonName::$TYPE_NAME_FIELD} = $shop->name;
  48.  
  49.         $daemons[] = $daemonModel;
  50.       }
  51.     }
  52.     $systemAndSingleDaemons = array_filter($models, function ($daemon) {
  53.       return $daemon->{DaemonName::$TYPE_CODE_FIELD} == DaemonType::$SYSTEM
  54.         || $daemon->{DaemonName::$TYPE_CODE_FIELD} == DaemonType::$SINGLE_APP;
  55.     });
  56.  
  57.     foreach ($systemAndSingleDaemons as $daemon) {
  58.       $daemon->{DaemonName::$TYPE_ID_FIELD} = $daemon->{DaemonName::$NAME_FIELD};
  59.       $daemon->{DaemonName::$TYPE_NAME_FIELD} = 'System';
  60.       $daemons[] = $daemon;
  61.     }
  62.  
  63.     $dataProvider = new ArrayDataProvider([
  64.       'allModels' => $daemons,
  65.       'pagination' => [
  66.         'pageSize' => 20,
  67.       ],
  68.       'sort' => [
  69.         'attributes' => ['id', DaemonName::$NAME_FIELD],
  70.       ],
  71.     ]);
  72.  
  73.     $this->load($params);
  74.  
  75.     return $dataProvider;
  76.   }
  77.  
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top