Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Addon::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['GridView.pagination.pageSize']]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['status' => $this->status, 'installed' => $this->installed]);
     $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'class', $this->class])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'version', $this->version])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * Add / Remove Add-Ons automatically.
  *
  * @throws InvalidConfigException
  */
 protected function refreshAddOnsList()
 {
     // Absolute path to addOns directory
     $addOnsDirectory = Yii::getAlias('@addons');
     // Name of each sub-directory
     $subDirectories = array_diff(scandir($addOnsDirectory), array('..', '.'));
     // Each sub-directory name is an addOn ID
     $addOns = [];
     foreach ($subDirectories as $addOnID) {
         // Must be a directory
         if (is_dir($addOnsDirectory . DIRECTORY_SEPARATOR . $addOnID)) {
             array_push($addOns, $addOnID);
         }
     }
     $installedAddOns = ArrayHelper::map(Addon::find()->select(['id', 'id'])->asArray()->all(), 'id', 'id');
     $newAddOns = array_diff($addOns, $installedAddOns);
     $removedAddOns = array_diff($installedAddOns, $addOns);
     // Install new addOns
     foreach ($newAddOns as $newAddOn) {
         // Verify if Module.php file of the new addOn exist
         $file = $addOnsDirectory . DIRECTORY_SEPARATOR . $newAddOn . DIRECTORY_SEPARATOR . 'Module.php';
         if (!is_file($file)) {
             throw new InvalidConfigException(Yii::t('addon', 'An invalid Add-on detected. Please verify your Add-ons directory.'));
         } else {
             $configFile = Yii::getAlias('@addons') . DIRECTORY_SEPARATOR . $newAddOn . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'install.php';
             if (is_file($configFile)) {
                 $config = (require $configFile);
                 if (!is_array($config) || !isset($config['id']) || !isset($config['name']) || !isset($config['class'])) {
                     throw new InvalidConfigException(Yii::t('addon', 'An invalid Add-on detected. Please verify your Add-On configuration.'));
                 }
                 // Add AddOn to List
                 $addOnModel = new Addon();
                 $addOnModel->id = $config['id'];
                 $addOnModel->name = $config['name'];
                 $addOnModel->class = $config['class'];
                 $addOnModel->description = isset($config['description']) && isset($config['description'][Yii::$app->language]) ? $config['description'][Yii::$app->language] : null;
                 $addOnModel->version = isset($config['version']) ? $config['version'] : null;
                 $addOnModel->status = isset($config['status']) ? $config['status'] : null;
                 $addOnModel->save();
             }
         }
     }
     // Uninstall removed addOns
     foreach ($removedAddOns as $removedAddOn) {
         $addOnModel = Addon::find()->where(['id' => $removedAddOn])->one();
         $addOnModel->delete();
     }
 }
Пример #3
0
 protected function getActiveAddOns()
 {
     $activeAddOns = ArrayHelper::map(Addon::find()->active()->all(), 'id', 'class');
     $addOns = [];
     foreach ($activeAddOns as $id => $class) {
         $addOns[$id]['class'] = $class;
     }
     return $addOns;
 }