/** * Increments user spam count, both globally and in current session * * @return bool */ public function incrementSpamCount() { // Save global spam count $current = $this->get('spam_count', 0); $this->set('spam_count', $current + 1); $this->set('user_id', \User::get('id')); $this->save(); // Also increment session spam count $current = Session::get('spam_count', 0); Session::set('spam_count', $current + 1); }
/** * Check to see if user has permission to perform task * * @param object $group \Hubzero\User\Group * @param string $action Group Action to perform * @return boolean */ public static function userHasPermissionForGroupAction($group, $action) { // Get user roles $roles = self::getGroupMemberRoles(\User::get('id'), $group->get('gidNumber')); // Check to see if any of our roles for user has permission for action foreach ($roles as $role) { $permissions = json_decode($role['permissions']); $permissions = is_object($permissions) ? $permissions : new \stdClass(); if (property_exists($permissions, $action) && $permissions->{$action} == 1) { return true; } } return false; }
/** * Gets an attribute by key * * This will not retrieve properties directly attached to the model, * even if they are public - those should be accessed directly! * * Also, make sure to access properties in transformers using the get method. * Otherwise you'll just get stuck in a loop! * * @param string $key The attribute key to get * @param mixed $default The value to provide, should the key be non-existent * @return mixed */ public function get($key, $default = null) { if ($key == 'tags') { return $this->tags(); } if (!$this->hasAttribute($key) && !$this->profileLoaded) { // Collect multi-value fields into arrays $data = Profile::collect($this->profiles); foreach ($data as $k => $v) { $this->set($k, $v); } $this->profileLoaded = true; } return parent::get($key, $default); }
/** * Return a groups logo * * @param string $what What data to return? * @return mixed */ public function getLogo($what = '') { //default logo static $default_logo; if (!$default_logo) { $default_logo = '/core/components/com_groups/site/assets/img/group_default_logo.png'; } //logo link - links to group overview page $link = \Route::url('index.php?option=com_groups&cn=' . $this->get('cn')); //path to group uploaded logo $path = substr(PATH_APP, strlen(PATH_ROOT)) . '/site/groups/' . $this->get('gidNumber') . DS . 'uploads' . DS . $this->get('logo'); //if logo exists and file is uploaded use that logo instead of default $src = $this->get('logo') != '' && is_file(PATH_ROOT . $path) ? $path : $default_logo; //check to make sure were a member to show logo for hidden group $members_and_invitees = array_merge($this->get('members'), $this->get('invitees')); if ($this->get('discoverability') == 1 && !in_array(\User::get('id'), $members_and_invitees)) { $src = $default_logo; } $what = strtolower($what); if ($what == 'size') { return getimagesize(PATH_ROOT . $src); } if ($what == 'path') { return $src; } return \Request::base(true) . $src; }