/** * Canghes the password only if the * @param PCModelUser $user * @param string $newPwdHash * @return bool */ public static function changePasswordForUser($user, $newPwdHash, $oldPwsHash) { $mapper = PCModelUser::getMapper(); $keys = array('password' => $newPwdHash); $conditions = "identifier = :id AND password = :pwd"; $pwd = $oldPwsHash == NULL ? $user->getPassword() : $oldPwsHash; $bindings = array(":id" => $user->getIdentifier(), ":pwd" => $pwd ); return PCModelManager::updateObject($mapper, $keys, $conditions, $bindings); }
/** * * @param PCHelperSocialAdapter $service_adapter * @return PCModelUserOauth */ public static function getOauthUserWithIdentifier($service_adapter) { $keys = array( "oauth_provider" => $service_adapter->getServiceType(), "oauth_uid" => $service_adapter->getServiceUserIdentifier() ); $instances = PCModelManager::fetchModelObjectInstances(PCModelUserOauth::getMapper(), $keys); if (count($instances) == 0) return NULL; $result = $instances[0]; if(isset($result['oauth_uid']) && $result['user_identifier'] == '0') return FALSE; $user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $result['user_identifier'], NULL, TRUE); if (isset($user)) { $bindings = array( "oauth_token" => $service_adapter->getTokenValue(), "oauth_secret" => $service_adapter->getSecretValue(), ); if( PCModelManager::updateObject(PCModelUserOauth::getMapper(), $bindings, "identifier = :iddd",array(":iddd"=>$result['identifier'])) === FALSE) return NULL; $service_adapter->addOauthInfoToUser($user); } return $user; }
/** * @XXX remove direct database interaction * @param PCModelWebsite $site */ public static function recacheSiteReview($site) { //error_log('RECACHING SITE INFO: '.$site->getIdentifier()); $select = "SELECT avg(usability) as usability, avg(reliability) as reliability,"; $select .= " avg(contents) as contents, count(identifier) as count "; $mapper = PCModelReview::getMapper(); $select .= " FROM " . $mapper->getTableName() . " WHERE site_identifier = :id"; $pdo = PCDatabase::getSharedDatabaseConnection(); $prepared = $pdo->prepare($select); $result = $prepared->execute(array(":id" => $site->getIdentifier())); if ($result === FALSE) { return NULL; } $item = $prepared->fetch(PDO::FETCH_ASSOC); if (!isset($item)) { return NULL; } $usability = (double) $item['usability']; $reliability = (double) $item['reliability']; $contents = (double) $item['contents']; $count = (double) $item['count']; $cache_time = new DateTime('now', new DateTimeZone('UTC')); $keys = array('usability' => $usability, 'reliability' => $reliability, 'contents' => $contents, 'number_of_votes' => $count, 'cached' => $cache_time->format('Y-m-d H:i:s')); $condition = "identifier = :id"; $bindings = array(':id' => $site->getIdentifier()); $websiteMapper = PCModelWebsite::getMapper(); if (PCModelManager::updateObject($websiteMapper, $keys, $condition, $bindings)) { $site->cached_date = $cache_time; $site->contents = $contents; $site->number_of_votes = $count; $site->reliability = $reliability; $site->usability = $usability; PCCache::cacheProvider()->setItem($site, $websiteMapper->getTableName() . $site->getIdentifier()); return $site; } return NULL; }