+abstract class UFC_Address implements UserFilterCondition
+{
+ /** Valid address type ('hq' is reserved for company addresses)
+ */
+ const TYPE_HOME = 1;
+ const TYPE_PRO = 2;
+ const TYPE_ANY = 3;
+
+ /** Text for these types
+ */
+ protected static $typetexts = array(
+ self::TYPE_HOME => 'home',
+ self::TYPE_PRO => 'pro',
+ );
+
+ protected $type;
+
+ /** Flags for addresses
+ */
+ const FLAG_CURRENT = 0x0001;
+ const FLAG_TEMP = 0x0002;
+ const FLAG_SECOND = 0x0004;
+ const FLAG_MAIL = 0x0008;
+ const FLAG_CEDEX = 0x0010;
+
+ // Binary OR of those flags
+ const FLAG_ANY = 0x001F;
+
+ /** Text of these flags
+ */
+ protected static $flagtexts = array(
+ self::FLAG_CURRENT => 'current',
+ self::FLAG_TEMP => 'temporary',
+ self::FLAG_SECOND => 'secondary',
+ self::FLAG_MAIL => 'mail',
+ self::FLAG_CEDEX => 'cedex',
+ );
+
+ protected $flags;
+
+ public function __construct($type = null, $flags = null)
+ {
+ $this->type = $type;
+ $this->flags = $flags;
+ }
+
+ protected function initConds($sub)
+ {
+ $conds = array();
+ $types = array();
+ foreach (self::$typetexts as $flag => $type) {
+ if ($flag & $this->type) {
+ $types[] = $type;
+ }
+ }
+ if (count($types)) {
+ $conds[] = XDB::format($sub . '.type IN {?}', $types);
+ }
+
+ if ($this->flags != self::FLAG_ANY) {
+ foreach(self::$flagtexts as $flag => $text) {
+ if ($flag & $this->flags) {
+ $conds[] = 'FIND_IN_SET(' . XDB::format('{?}', $text) . ', ' . $sub . '.flags)';
+ }
+ }
+ }
+ return $conds;
+ }
+
+}
+// }}}
+
+// {{{ class UFC_AddressText
+/** Select users based on their address, using full text search
+ * @param $text Text for filter in fulltext search
+ * @param $textSearchMode Mode for search (one of XDB::WILDCARD_*)
+ * @param $type Filter on address type
+ * @param $flags Filter on address flags
+ * @param $country Filter on address country
+ * @param $locality Filter on address locality