initUserProperties(); $this->initOrgProperties(); // Set up user type name credential $this->setUserTypeCredential(); } /** * Called when a user signs out - clears credentials */ public function signOut() { // Clears user credentials $this->getAttributeHolder()->clear(); // Pass call along to parent parent::signOut(); } public function getOrgId() { return $this->getAttribute('org_id'); } public function setOrgId($orgId) { return $this->setAttribute('org_id', $orgId); } /** * Read application level property, affected by user group * * @param string $name Name of application-level property * @param integer $cacheTime Optional cachetime value (omit or use null for default) */ public function getAppProperty($name, $cacheTime = null) { // Get group name, if it is set $group = $this->getAnyProperty('system.app_property_group'); if ($group) { return AppPropertyPeer::lookup($name, $cacheTime, $group); } else { return AppPropertyPeer::lookup($name, $cacheTime); } } public function initOrgProperties() { $c = new Criteria(); $c->add( UserOrgPropertyPeer::ID_USER_ORG, $this->getProfile()->getIdUserOrg() ); $props = UserOrgPropertyPeer::doSelect($c); return $this->initProperties($props, 'org_properties', 'organisational'); } public function getOrgProperty($name) { return $this->getProperty($name, 'org_properties'); } public function removeOrgProperties() { $this->getAttributeHolder()->remove('org_properties'); } public function initUserProperties() { $c = new Criteria(); $c->add( UserMainPropertyPeer::ID_USER_MAIN, $this->getProfile()->getIdUserMain() ); $props = UserMainPropertyPeer::doSelect($c); return $this->initProperties($props, 'user_properties', 'user'); } public function getUserProperty($name) { return $this->getProperty($name, 'user_properties'); } public function removeUserProperties() { $this->getAttributeHolder()->remove('user_properties'); } /** * Gets either a user or an organisational property, preferring the former * * @todo If a user property is deliberately set to null, as opposed to being unset, it will be ignored - fix this? */ public function getAnyProperty($name) { $v = $this->getUserProperty($name); if (is_null($v)) { $v = $this->getOrgProperty($name); } return $v; } /** * Shared private function for setting organisational and user properties * * @param $rs An array of Propel objects that must support getName and getValue (ie there must be `name` and `value` in the underlying table) * @param $strAttrib is the name of the attribute to set * @param $strType the name of the type, usually "organisational" or "user" */ private function initProperties($rs, $strAttrib, $strType) { $text = array(); $props = array(); foreach ($rs as $prop) { $name = $prop->getName(); $value = $prop->getValue(); $props[$name] = $value; $text[] = "${name}=${value}"; } sfContext::getInstance()->getLogger()->info( 'There are ' . count($props) . " $strType properties: " . implode(', ', $text) ); return $this->setAttribute($strAttrib, $props); } private function getProperty($name, $strAttrib) { $props = $this->getAttribute($strAttrib); sfContext::getInstance()->getLogger()->info("Looking for '$name' in property group '$strAttrib' which contains " . print_r($props, true)); // See if key "$name" exists first if (is_array($props) && array_key_exists($name, $props)) { $value = $props[$name]; } else { $value = null; } return $value; } /** * Reads the user type from the organisation table, and sets it as a symfony user credential */ private function setUserTypeCredential() { // Null all the intermediate derefencing values first $org = $cat = $type = null; // Dereference the shortname if it exists (it may not) $profile = $this->getProfile(); if ($profile) $org = $profile->getUserOrg(); if ($org) $cat = $org->getUserCat(); if ($cat) $type = $cat->getShortName(); // If we were successful, set up the credentials if ($type) { $this->addCredential("user_type_$type"); } } }