| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: |
|
| 20: |
|
| 21: |
|
| 22: | |
| 23: | |
| 24: |
|
| 25: | class ProfileVisibility extends XoopsObject
|
| 26: | {
|
| 27: | public $field_id;
|
| 28: | public $user_group;
|
| 29: | public $profile_group;
|
| 30: |
|
| 31: | |
| 32: | |
| 33: |
|
| 34: | public function __construct()
|
| 35: | {
|
| 36: | $this->initVar('field_id', XOBJ_DTYPE_INT);
|
| 37: | $this->initVar('user_group', XOBJ_DTYPE_INT);
|
| 38: | $this->initVar('profile_group', XOBJ_DTYPE_INT);
|
| 39: | }
|
| 40: | }
|
| 41: |
|
| 42: | |
| 43: | |
| 44: |
|
| 45: | class ProfileVisibilityHandler extends XoopsPersistableObjectHandler
|
| 46: | {
|
| 47: | |
| 48: | |
| 49: |
|
| 50: | public function __construct(XoopsDatabase $db)
|
| 51: | {
|
| 52: | parent::__construct($db, 'profile_visibility', 'profilevisibility', 'field_id');
|
| 53: | }
|
| 54: |
|
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: |
|
| 63: | public function getVisibleFields($profile_groups, $user_groups = null)
|
| 64: | {
|
| 65: | $profile_groups[] = $user_groups[] = 0;
|
| 66: | $sql = "SELECT field_id FROM {$this->table} WHERE profile_group IN (" . implode(',', $profile_groups) . ')';
|
| 67: | $sql .= ' AND user_group IN (' . implode(',', $user_groups) . ')';
|
| 68: | $field_ids = array();
|
| 69: | $result = $this->db->query($sql);
|
| 70: | if ($this->db->isResultSet($result)) {
|
| 71: | while (false !== (list($field_id) = $this->db->fetchRow($result))) {
|
| 72: | $field_ids[] = $field_id;
|
| 73: | }
|
| 74: | }
|
| 75: |
|
| 76: | return $field_ids;
|
| 77: | }
|
| 78: |
|
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: |
|
| 86: | public function getAllByFieldId(CriteriaElement $criteria = null)
|
| 87: | {
|
| 88: | $rawRows = parent::getAll($criteria, null, false, false);
|
| 89: |
|
| 90: | usort($rawRows, array($this, 'visibilitySort'));
|
| 91: |
|
| 92: | $rows = array();
|
| 93: | foreach ($rawRows as $rawRow) {
|
| 94: | $rows[$rawRow['field_id']][] = $rawRow;
|
| 95: | }
|
| 96: |
|
| 97: | return $rows;
|
| 98: | }
|
| 99: |
|
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: |
|
| 112: | protected function visibilitySort($a, $b)
|
| 113: | {
|
| 114: | $fieldDiff = $a['field_id'] - $b['field_id'];
|
| 115: | $userDiff = $a['user_group'] - $b['user_group'];
|
| 116: | $profDiff = $a['profile_group'] - $b['profile_group'];
|
| 117: | if (0 != $fieldDiff) {
|
| 118: | return $fieldDiff;
|
| 119: | } elseif (0 !== $userDiff) {
|
| 120: | return $userDiff;
|
| 121: | } else {
|
| 122: | return $profDiff;
|
| 123: | }
|
| 124: | }
|
| 125: | }
|
| 126: | |