/** * * @param PCModelWebsite $site * @param PCModelUser $user * @param string $comment * @param string $usability * @param string $contents * @param string $reliability * @param string $language * @param string $error * @return bool */ public static function addReviewForSite($site, $user, $comment, $usability, $contents, $reliability, $language, &$error) { if (!isset($site) || !isset($site)){ die("Internal Inconsistency"); } if(!PCHelperValidator::validateLanguageCode($language)){ $error = "Invalid language code"; return FALSE; } $language = strtoupper($language); $commentLen = strlen($comment); if ($commentLen < 5 || $commentLen > PCModelReview::maxCommentLength) { $error = "Invalid comment length, ".( ($commentLen < 5) ? " minumum length is 6 characters" : "maximum length is 200 characters"); return FALSE; } $usa = floatval($usability); $cont = floatval($contents); $rel = floatval($reliability); if($usa < PCModelReview::minVote ||$usa > PCModelReview::maxVote){ $error = "usability is not valid"; return FALSE; } if($cont < PCModelReview::minVote ||$cont > PCModelReview::maxVote){ $error = "contents is not valid"; return FALSE; } if($rel < PCModelReview::minVote ||$rel > PCModelReview::maxVote){ $error = "reliability is not valid"; return FALSE; } $date_added = new DateTime('now', new DateTimeZone('UTC')); $date_added_mysql = $date_added->format('Y-m-d H:i:s'); $values = array( 'site_identifier' => $site->getIdentifier(), 'user_identifier' => $user->getIdentifier(), 'comment' => $comment, 'usability' => $usa, 'reliability' => $rel, 'contents' => $cont, 'language_code' => $language, 'date_added' => $date_added_mysql ); if($user->getAccountType() !== PCModelUser::$TYPE_DEFAULT && PCConfigManager::sharedManager()->getBoolValue('SOCIAL_POST_ON_REVIEW') ){ $user->postReviewToTimeline($values,$site); } $dupUpdate = array('language_code','date_added','contents','reliability','usability','comment'); if(PCModelManager::insertObject(PCModelReview::getMapper(), $values, $dupUpdate)){ return TRUE; } $error = "Error adding review please try later"; return FALSE; }
/** * 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); }