AdService.php 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2020-01-29 14:42
  7. */
  8. namespace common\services;
  9. use backend\models\form\AdForm;
  10. use backend\models\search\OptionsSearch;
  11. use common\models\Options;
  12. use yii\base\Exception;
  13. class AdService extends Service implements AdServiceInterface
  14. {
  15. public function getSearchModel(array $options = [])
  16. {
  17. return new OptionsSearch(['type'=>Options::TYPE_AD]);
  18. }
  19. public function getModel($id, array $options = [])
  20. {
  21. return AdForm::findOne($id);
  22. }
  23. public function newModel(array $options = [])
  24. {
  25. $model = new AdForm();
  26. $model->loadDefaultValues();
  27. return $model;
  28. }
  29. public function getAdByName($name)
  30. {
  31. $model = AdForm::findOne(["type"=>Options::TYPE_AD, "name"=>$name]);
  32. if( $model === null ) throw new Exception("Not exists advertisement named " . $name);
  33. return $model;
  34. }
  35. }