BSchoolPrivate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * 学校安全与隐私
  4. * @author jiangfei
  5. * @date 2015-10-29 13:30:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class BSchoolPrivate extends BusinessActiveRecord{
  9. public static function model($className = __CLASS__){
  10. return parent::model($className);
  11. }
  12. public function tableName(){
  13. return "school_private";
  14. }
  15. public function getPrivate($schoolId){
  16. $criteria = new CDbCriteria();
  17. $criteria->select = 'is_private';
  18. $criteria->addCondition("school_id={$schoolId}");
  19. $result = $this->find($criteria);
  20. if ($result){
  21. return $result->is_private;
  22. }else{
  23. return 0;
  24. }
  25. }
  26. public function savePrivate($schoolId, $isPrivate)
  27. {
  28. $criteria = new CDbCriteria();
  29. $criteria->select = 'id';
  30. $criteria->addCondition("school_id={$schoolId}");
  31. $result = $this->find($criteria);
  32. if ($result){
  33. //更新
  34. $bool = $this->updateByPk($result->id,array('is_private'=>$isPrivate));
  35. if($bool!==false){
  36. return true;
  37. }else{
  38. return false;
  39. }
  40. }else{
  41. $sp = new BSchoolPrivate();
  42. $sp->is_private = $isPrivate;
  43. $sp->school_id = $schoolId;
  44. $bool = $sp->save();
  45. if($bool){
  46. return true;
  47. }else{
  48. return false;
  49. }
  50. }
  51. }
  52. }