Created
January 7, 2013 23:24
-
-
Save Fi1osof/4479563 to your computer and use it in GitHub Desktop.
CustomUser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SocietyUser extends modUser { | |
static function load(xPDO &$xpdo, $className, $criteria, $cacheFlag = true) { | |
$instance= null; | |
$fromCache= false; | |
if ($className= $xpdo->loadClass($className)) { | |
if (!is_object($criteria)) { | |
$criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag); | |
} | |
if (is_object($criteria)) { | |
$row= null; | |
if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) { | |
$row= $xpdo->fromCache($criteria, $className); | |
} | |
if ($row === null || !is_array($row)) { | |
if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) { | |
$row= $rows->fetch(PDO::FETCH_ASSOC); | |
$rows->closeCursor(); | |
} | |
} else { | |
$fromCache= true; | |
} | |
if (!is_array($row)) { | |
if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true)); | |
} else { | |
$row['SocietyUser_class_key'] = 'SocietyTestUser'; | |
$instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row); | |
if (is_object($instance)) { | |
if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) { | |
$xpdo->toCache($criteria, $instance, $cacheFlag); | |
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) { | |
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag); | |
$xpdo->toCache($pkCriteria, $instance, $cacheFlag); | |
} | |
} | |
if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true)); | |
} | |
} | |
} else { | |
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.'); | |
} | |
} else { | |
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className); | |
} | |
return $instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment