/** * Factory Method: Loads a user from the database and returns an object instance. * * You must adhere the reference that is returned, otherwise the internal caching * and runtime state strategy will fail. * * @param mixed $id A valid identifier for a MidgardPerson: An existing midgard_person class * or subclass thereof, a Person ID or GUID or a midcom_core_user identifier. * @return midcom_core_user A reference to the user object matching the identifier or false on failure. */ function get_user($id) { if (is_double($id)) { // This is some crazy workaround for cases where the ID passed is a double // (coming from midcom_connection::get_user() possibly) and is_object($id), again for // whatever reason, evaluates to true for that object... $id = (int) $id; } $param = $id; if (isset($param->id)) { $id = $param->id; } else { if (!is_string($id) && !is_integer($id)) { debug_print_type('The passed argument was an object of an unsupported type:', $param, MIDCOM_LOG_WARN); debug_print_r('Complete object dump:', $param); return false; } } if (!array_key_exists($id, $this->_user_cache)) { try { if (is_a($param, 'midcom_db_person')) { $param = $param->__object; } $this->_user_cache[$id] = new midcom_core_user($param); } catch (midcom_error $e) { // Keep it silent while missing user object can mess here $this->_user_cache[$id] = false; } } return $this->_user_cache[$id]; }
/** * Helper function, it takes a MidCOM DBA object and converts it into an MgdSchema object. * * If the conversion cannot be done for some reason, the function returns null and logs * an error. * * @param MidCOMDBAObject &$object MidCOM DBA Object * @return MidgardObject MgdSchema Object */ function convert_midcom_to_midgard(&$object) { if (!is_object($object)) { debug_print_type("Cannot cast the object to an MgdSchema type, it is not an object, we got this type:", $object, MIDCOM_LOG_ERROR); debug_print_r("Object dump:", $object); return null; } if (!midcom::get('dbclassloader')->is_midcom_db_object($object)) { if (midcom::get('dbclassloader')->is_mgdschema_object($object)) { // Return it directly, it is already in the format we want return $object; } debug_print_type("Cannot cast the object to an MgdSchema type, it is not a MidCOM DBA object, we got this type:", $object, MIDCOM_LOG_ERROR); debug_print_r("Object dump:", $object); return null; } if (!isset($object->__object) || !is_object($object->__object)) { debug_print_type("Cannot cast the object to an MgdSchema type, as it doesn't contain it, we got this type:", $object, MIDCOM_LOG_ERROR); debug_print_r("Object dump:", $object); return null; } return $object->__object; }