Article.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /*
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\services\cms;
  10. use fecshop\services\cms\article\ArticleMongodb;
  11. use fecshop\services\cms\article\ArticleMysqldb;
  12. use fecshop\services\Service;
  13. use Yii;
  14. /**
  15. * Cms Article services. 文字条款类的page单页。
  16. * @author Terry Zhao <2358269014@qq.com>
  17. * @since 1.0
  18. */
  19. class Article extends Service
  20. {
  21. /**
  22. * $storagePrex , $storage , $storagePath 为找到当前的storage而设置的配置参数
  23. * 可以在配置中更改,更改后,就会通过容器注入的方式修改相应的配置值
  24. */
  25. public $storage = 'ArticleMongodb'; // 当前的storage,如果在config中配置,那么在初始化的时候会被注入修改
  26. /**
  27. * 设置storage的path路径,
  28. * 如果不设置,则系统使用默认路径
  29. * 如果设置了路径,则使用自定义的路径
  30. */
  31. public $storagePath = '';
  32. protected $_article;
  33. public function init()
  34. {
  35. parent::init();
  36. $currentService = $this->getStorageService($this);
  37. $this->_article = new $currentService();
  38. /*
  39. if ($this->storage == 'mongodb') {
  40. $this->_article = new ArticleMongodb();
  41. } elseif ($this->storage == 'mysqldb') {
  42. $this->_article = new ArticleMysqldb();
  43. }
  44. */
  45. }
  46. /**
  47. * Get Url by article's url key.
  48. */
  49. //public function getUrlByPath($urlPath){
  50. //return Yii::$service->url->getHttpBaseUrl().'/'.$urlKey;
  51. //return Yii::$service->url->getUrlByPath($urlPath);
  52. //}
  53. /**
  54. * get artile's primary key.
  55. */
  56. protected function actionGetPrimaryKey()
  57. {
  58. return $this->_article->getPrimaryKey();
  59. }
  60. /**
  61. * get artile model by primary key.
  62. */
  63. protected function actionGetByPrimaryKey($primaryKey)
  64. {
  65. return $this->_article->getByPrimaryKey($primaryKey);
  66. }
  67. /**
  68. * @param $urlKey | String , 对应表的url_key字段
  69. * 根据url_key 查询得到article model
  70. */
  71. protected function actionGetByUrlKey($urlKey)
  72. {
  73. return $this->_article->getByUrlKey($urlKey);
  74. }
  75. /**
  76. * 得到category model的全名.
  77. */
  78. protected function actionGetModelName()
  79. {
  80. return get_class($this->_article);
  81. }
  82. /**
  83. * @param $filter|array
  84. * get artile collection by $filter
  85. * example filter:
  86. * [
  87. * 'numPerPage' => 20,
  88. * 'pageNum' => 1,
  89. * 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
  90. * 'where' => [
  91. * ['>','price',1],
  92. * ['<=','price',10]
  93. * ['sku' => 'uk10001'],
  94. * ],
  95. * 'asArray' => true,
  96. * ]
  97. */
  98. protected function actionColl($filter = '')
  99. {
  100. return $this->_article->coll($filter);
  101. }
  102. /**
  103. * @param $one|array , save one data .
  104. * @param $originUrlKey|string , article origin url key.
  105. * save $data to cms model,then,add url rewrite info to system service urlrewrite.
  106. */
  107. protected function actionSave($one, $originUrlKey)
  108. {
  109. return $this->_article->save($one, $originUrlKey);
  110. }
  111. protected function actionRemove($ids)
  112. {
  113. return $this->_article->remove($ids);
  114. }
  115. }