StaticSource.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * 静态资源模型
  4. */
  5. class StaticSource extends MongoAr {
  6. public $_id;
  7. public $key;
  8. public $title;
  9. public $content;
  10. public $remark;
  11. public function __construct($scenario='insert') {
  12. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_data'));
  13. parent::__construct($scenario);
  14. }
  15. public static function model($className=__CLASS__) {
  16. return parent::model($className);
  17. }
  18. public function getCollectionName() {
  19. return 'static_sources';
  20. }
  21. public static function get($_id) {
  22. if (CommonFn::isMongoId($_id)) {
  23. $criteria = new EMongoCriteria();
  24. $criteria->_id('==', $_id);
  25. $model = self::model()->find($criteria);
  26. return $model;
  27. } else {
  28. return false;
  29. }
  30. }
  31. public static function getByKey($key) {
  32. $criteria = new EMongoCriteria();
  33. $criteria->key('==', $key);
  34. $model = self::model()->find($criteria);
  35. return $model;
  36. }
  37. public function parseRow($row, $output = []) {
  38. $newRow = [];
  39. $newRow['id'] = (string)$row['_id'];
  40. $newRow['key'] = CommonFn::get_val_if_isset($row, 'key', '');
  41. $newRow['title'] = CommonFn::get_val_if_isset($row, 'title', '');
  42. $newRow['content'] = CommonFn::get_val_if_isset($row, 'content', '');
  43. $newRow['content_short'] = '#内容#';
  44. $newRow['remark'] = CommonFn::get_val_if_isset($row, 'remark', '');
  45. return $this->output($newRow, $output);
  46. }
  47. }