/**
  * Recursive load all Children
  */
 public function loadChildren()
 {
     $this->children = User_Visibility_Settings::findBySQL("user_id = ? AND parent_id = ? ", array($this->user_id, $this->visibilityid));
     foreach ($this->children as $child) {
         $child->parent = $this;
         $child->loadChildren();
     }
 }
Example #2
0
 /**
  * Configures this model.
  *
  * @param Array $config Configuration array
  */
 protected static function configure($config = array())
 {
     $config['db_table'] = 'datafields';
     $config['has_many']['entries'] = array('class_name' => 'DatafieldEntryModel', 'on_delete' => function ($df) {
         return DatafieldEntryModel::deleteBySQL("datafield_id = ?", array($df->id));
     });
     $config['has_many']['visibility_settings'] = array('class_name' => 'User_Visibility_Settings', 'assoc_foreign_key' => 'identifier', 'on_delete' => function ($df) {
         return User_Visibility_Settings::deleteBySQL("identifier = ?", array($df->id));
     });
     parent::configure($config);
 }
Example #3
0
 /**
  * Returns all the categorys and it's items
  * @return array categorys and it's items
  */
 public function getProfileSettings()
 {
     if (!isset($this->profileSettings)) {
         // if the default categories have not been created, do this now
         if (User_Visibility_Settings::countBySQL('user_id = ? AND category = 0', array($this->userid)) == 0) {
             Visibility::createDefaultCategories($this->userid);
         }
         $this->profileSettings = User_Visibility_Settings::findBySQL("user_id = ? AND parent_id = 0 AND identifier <> 'plugins'", array($this->userid));
         foreach ($this->profileSettings as $i => $vis) {
             $vis->loadChildren();
             // remap child settings to default categories
             if ($vis->category == 1) {
                 $idmap[$vis->identifier] = $vis;
                 unset($this->profileSettings[$i]);
             }
         }
         $about = new about($GLOBALS['user']->username, '');
         $elements = $about->get_homepage_elements();
         foreach ($elements as $key => $element) {
             foreach ($this->profileSettings as $vis) {
                 if ($vis->name === $element['category']) {
                     foreach ($vis->children as $child) {
                         if ($child->identifier === $key) {
                             $child->name = $element['name'];
                             break 2;
                         }
                     }
                     $child = $idmap[$key] ?: new User_Visibility_Settings();
                     $child->setData(array('user_id' => $this->userid, 'parent_id' => $vis->id, 'category' => 1, 'name' => $element['name'], 'state' => $element['visibility'], 'identifier' => $key));
                     $child->store();
                     $child->parent = $vis;
                     $child->setDisplayed();
                     $vis->children[] = $child;
                     break;
                 }
             }
         }
     }
     return $this->profileSettings;
 }
Example #4
0
/**
 * Gets a user's visibility settings for special context. Valid contexts are
 * at the moment:
 * <ul>
 * <li><b>online</b>: Visibility in "Who is online" list</li>
 * <li><b>search</b>: Can the user be found via person search?</li>
 * <li><b>email</b>: Is user's email address shown?</li>
 * <li><b>homepage</b>: Visibility of all user homepage elements, stored as
 * JSON-serialized array</li>
 * </ul>
 *
 * @param string $user_id user ID to check
 * @param string $context local visibility in which context?
 * @param boolean $return_user_perm return not only visibility, but also
 * the user's global permission level
 * @return mixed Visibility flag or array with visibility and user permission
 * level.
 */
function get_local_visibility_by_id($user_id, $context, $return_user_perm=false) {
    global $NOT_HIDEABLE_FIELDS;

    $query = "SELECT a.perms, u.`{$context}`
              FROM auth_user_md5 AS a
              LEFT JOIN user_visibility AS u USING (user_id)
              WHERE user_id = ?";
    $statement = DBManager::get()->prepare($query);
    $statement->execute(array($user_id));
    $data = $statement->fetch(PDO::FETCH_ASSOC);

    if ($context === 'homepage') {
        $settings = User_Visibility_Settings::findByUser_id($user_id);
        foreach ($settings as $setting) {
            if ($setting['category'] == 1) {
                $homepage_settings[$setting['identifier']] = $setting['state'];
            }
        }

        if ($homepage_settings) {
            $data[$context] = json_encode($homepage_settings);
        }
    }

    if ($data[$context] === null) {
        $user_perm = $data['perm'];
        $data['perms'] = $user_perm;

        $data[$context] = get_config(strtoupper($context) . '_VISIBILITY_DEFAULT');
    }
    // Valid context given.
    if ($data[$context]) {
        // Context may not be hidden per global config setting.
        if ($NOT_HIDEABLE_FIELDS[$data['perms']][$context]) {
            $result = true;
        } else {
            // Give also user's permission level.
            if ($return_user_perm) {
                $result = array(
                    'perms' => $data['perms'],
                    $context => $data[$context]
                );
            } else {
                $result = $data[$context];
            }
        }
    } else {
        $result = false;
    }
    return $result;
}
Example #5
0
 /**
  * Renames a PrivacySetting
  *
  * @param int|string $id VisibilityID or Identifier to be renamed
  *
  * @param string $new_name the new name
  *
  * @param string $user Userid. Default: Current logged on user
  */
 public static function renamePrivacySetting($id, $new_name, $user = null)
 {
     $setting = User_Visibility_Settings::find($id, $user);
     $setting->name = $new_name;
     $setting->store();
 }