public function afterDelete()
 {
     parent::afterDelete();
     if ($model = $this->getErrorQuery()) {
         $model->delete();
     }
 }
 public function getMenu()
 {
     $moduleName = AbstractModel::moduleName(static::className());
     $model = $this->findModel();
     $uniqueKey = 0;
     $items = $model::find()->orderBy(['lft' => SORT_ASC])->asArray()->all();
     foreach ($items as &$item) {
         $uniqueKey++;
         $nodeId = $uniqueKey . '-id-' . $item['id'];
         $item['nodeAttributes'] = ['id' => $nodeId, 'text' => $item['name'], 'type' => 'folder', 'active' => \Yii::$app->request->get('id') == $item['id'], 'a_attr' => ['data-id' => $nodeId, 'href' => ["/{$moduleName}/category/update", 'id' => $item['id']]]];
     }
     $treeWidget = new ARTreeMenuWidget(['items' => $items, 'view' => 'nested']);
     return $treeWidget->run();
 }
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (!parent::beforeSave($insert)) {
         return false;
     }
     if ($insert && !$this->api_key) {
         $this->generateApiKey();
     }
     if ($insert && !$this->auth_key) {
         $this->generateAuthKey();
     }
     if ($insert || $this->isAttributeChanged('password')) {
         $this->password = $this->generatePassword($this['password']);
     }
     return true;
 }
 /**
  * Relative path for saving model files.
  * @return string path.
  */
 public function getStoragePath()
 {
     $moduleName = AbstractModel::moduleName(static::className());
     $owner_id = $this->getAttribute('owner_id') ?: Yii::$app->user->id;
     return "@app/web/files/{$owner_id}/{$moduleName}/" . $this->formName() . '/' . $this->id;
 }
 /**
  * @inheritdoc
  */
 public function beforeDelete()
 {
     if (!$this->pid) {
         throw new Exception("Can not delete the root page");
     }
     return parent::beforeDelete();
 }
 /**
  * Relative path for saving model files.
  * @return string path.
  */
 public function getStoragePath()
 {
     $moduleName = AbstractModel::moduleName(static::className());
     return "@app/web/files/{$moduleName}/" . $this->formName() . '/' . $this->id;
 }