/** * Get array of contacts data by Email * * @param string $data * @return array of CMS_profile_user * @access public */ static function getByEmail($data) { if (!SensitiveIO::isValidEmail($data)) { CMS_grandFather::raiseError('$data must be a valid email : ' . $data); return array(); } $aUsers = array(); //create the request to look for the data $sql = 'select `id_cd` from `contactDatas` where `email_cd` = "' . sensitiveIO::sanitizeSQLString($data) . '"'; //launching the request $q = new CMS_query($sql); //checking if ok and looping on results if (!$q->hasError()) { while (($oTmpUserId = $q->getValue("id_cd")) !== false) { //creating the user and filling the data $oTmpUser = CMS_profile_usersCatalog::getByID($oTmpUserId); if (!$oTmpUser->hasError()) { $oTmpUser->getContactData(); if (!$oTmpUser->hasError()) { $aUsers[] = $oTmpUser; } } } unset($oTmpUser, $oTmpUserId); } return $aUsers; }
/** * Sets the email address. * * @param string $newEmail the new email address * @return boolean true on success, false on failure to set it * @access public */ function setEmail($newEmail) { if (SensitiveIO::isValidEmail($newEmail)) { $this->_email = $newEmail; return true; } return false; }
/** * Returns all the profile users, sorted by last name + first name. * Static function. * * @param boolean activeOnly : return only active users (default : false) * @param boolean withDeleted : return deleted users also (default false) * @param boolean returnObjects : return CMS_profile_user objects (default) or array of userId * @param array attrs : filter for search : array($attrName => $attrValue) * @return array(CMS_profile_user) * @access public */ static function getAll($activeOnly = false, $withDeleted = false, $returnObjects = true, $attrs = array()) { $attrWhere = ''; $from = ''; if ($attrs and is_array($attrs)) { $availableAttrs = array('id_pru', 'login_pru', 'firstName_pru', 'lastName_pru', 'contactData_pru', 'profile_pru', 'language_pru', 'textEditor_pru', 'email_cd'); foreach ($attrs as $attrName => $attrValue) { // Check $attrName is available if (in_array($attrName, $availableAttrs)) { $and = $attrWhere || !$attrWhere && (!$withDeleted || $activeOnly) ? " and " : ""; // Sanitize value and set operator if (!is_array($attrValue)) { if ($attrName == 'email_cd') { // Special case : parameter is contactData email $attrValue = sensitiveIO::sanitizeSQLString($attrValue); if (SensitiveIO::isValidEmail($attrValue)) { $attrWhere .= $and . " " . $attrName . " = '" . $attrValue . "' and contactData_pru=id_cd"; $from .= ',contactDatas'; } } else { $attrValue = sensitiveIO::sanitizeSQLString($attrValue); $attrWhere .= $and . " " . $attrName . " = '" . $attrValue . "'"; } } elseif (is_array($attrValue)) { $attrValue = array_map(array('sensitiveIO', 'sanitizeSQLString'), $attrValue); foreach ($attrValue as $key => $value) { $attrValue[$key] = "'" . $value . "'"; } $attrWhere .= $and . " " . $attrName . " in (" . implode(',', $attrValue) . ")"; } } else { CMS_grandFather::_raiseError(__CLASS__ . ' : ' . __FUNCTION__ . ' : attrName must be in availableAttrs array'); } } } $sql = "\n\t\t\tselect\n\t\t\t\tid_pru\n\t\t\tfrom\n\t\t\t\tprofilesUsers \n\t\t\t\t" . $from . "\n\t\t\t" . (!$withDeleted || $activeOnly || $attrWhere ? " where " : '') . "\n\t\t\t" . (!$withDeleted ? " deleted_pru='0'" : '') . "\n\t\t\t" . (!$withDeleted && $activeOnly ? " and " : '') . "\n\t\t\t" . ($activeOnly ? " active_pru='1' " : '') . "\n\t\t\t" . $attrWhere . "\n\t\t\torder by\n\t\t\t\tlastName_pru,\n\t\t\t\tfirstName_pru\n\t\t"; $q = new CMS_query($sql); $users = array(); while ($id = $q->getValue("id_pru")) { if ($returnObjects) { $usr = CMS_profile_usersCatalog::getByID($id); if (is_object($usr)) { if ($activeOnly && $usr->isActive() || !$activeOnly) { $users[] = $usr; } } } else { $users[] = $id; } } return $users; }
/** * Set a string of the object * * @param string $stringName The string name to set * @param string $stringValue The string value to set * @return boolean true on success, false on failure * @access public */ function setString($stringName, $stringValue) { if (in_array($this->_tableData[$stringName][0], $this->_classString)) { //here you can verifiy string data switch ($this->_tableData[$stringName][0]) { case "email": //null case if (is_null($stringValue)) { $this->_tableData[$stringName][1] = null; break; } if (!SensitiveIO::isValidEmail($stringValue)) { $this->raiseError("Try to set an uncorrect email format :" . $stringValue); return false; } break; case "string": $stringValue = SensitiveIO::sanitizeHTMLString($stringValue); break; case "html": //$stringValue = $stringValue; break; default: $this->raiseError("Unknown string or not a string dataType :" . $stringName); return false; break; } $this->_tableData[$stringName][1] = $stringValue; return true; } else { $this->raiseError("Unknown string or not a string dataType :" . $stringName); return false; } }