+ public function setVisibilityLevel($visibility)
+ {
+ if ($visibility != self::VISIBILITY_PRIVATE
+ && $visibility != self::VISIBILITY_AX
+ && $visibility != self::VISIBILITY_PUBLIC) {
+ Platal::page()->kill("Visibility invalide: " . $visibility);
+ }
+ $this->visibility = self::$v_values[$visibility];
+ }
+
+
+ /* Addresses
+ */
+ public function getAddresses($flags, $limit = null)
+ {
+ $where = XDB::format('pa.pid = {?}', $this->id());
+ if ($flags & self::ADDRESS_MAIN) {
+ $where .= ' AND FIND_IN_SET(\'current\', pa.flags)';
+ }
+ if ($flags & self::ADDRESS_POSTAL) {
+ $where .= ' AND FIND_IN_SET(\'mail\', pa.flags)';
+ }
+ if ($this->visibility) {
+ $where .= ' AND pa.pub IN ' . XDB::formatArray($this->visibility);
+ }
+ $type = array();
+ if ($flags & self::ADDRESS_PRO) {
+ $type[] = 'job';
+ }
+ if ($flags & self::ADDRESS_PERSO) {
+ $type[] = 'home';
+ }
+ if (count($type) > 0) {
+ $where .= ' AND pa.type IN ' . XDB::formatArray($type);
+ }
+ $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
+ return XDB::iterator('SELECT pa.text, pa.postalCode, pa.type, pa.latitude, pa.longitude,
+ gl.name AS locality, gas.name AS subAdministrativeArea,
+ ga.name AS administrativeArea, gc.countryFR AS country,
+ FIND_IN_SET(\'current\', pa.flags) AS current,
+ FIND_IN_SET(\'temporary\', pa.flags) AS temporary,
+ FIND_IN_SET(\'secondary\', pa.flags) AS secondary,
+ FIND_IN_SET(\'mail\', pa.flags) AS mail, pa.type
+ FROM profile_addresses AS pa
+ LEFT JOIN geoloc_localities AS gl ON (gl.id = pa.localityId)
+ LEFT JOIN geoloc_administrativeareas AS ga ON (ga.id = pa.administrativeAreaId)
+ LEFT JOIN geoloc_administrativeareas AS gas ON (gas.id = pa.subAdministrativeAreaId)
+ LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
+ WHERE ' . $where . '
+ ORDER BY pa.id
+ ' . $limit);
+ }
+
+ public function getMainAddress()
+ {
+ $it = $this->getAddresses(self::ADDRESS_PERSO | self::ADDRESS_MAIN);
+ if ($it->total() == 0) {
+ return null;
+ } else {
+ return $it->next();
+ }
+ }
+
+
+ /* Educations
+ */
+ public function getEducations($flags, $limit = null)
+ {
+ $where = XDB::format('pe.uid = {?}', $this->id());
+ if ($flags & self::EDUCATION_MAIN) {
+ $where .= ' AND FIND_IN_SET(\'primary\', pe.flags)';
+ } else if ($flags & self::EDUCATION_EXTRA) {
+ $where .= ' AND NOT FIND_IN_SET(\'primary\', pe.flags)';
+ } else if ($flags & self::EDUCATION_FINISHED) {
+ $where .= ' AND pe.grad_year <= YEAR(CURDATE())';
+ } else if ($flags & self::EDUCATION_CURRENT) {
+ $where .= ' AND pe.grad_year > YEAR(CURDATE())';
+ }
+ $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
+ return XDB::iterator('SELECT pe.entry_year, pe.grad_year, pe.program,
+ pee.name AS school, pee.abbreviation AS school_short, pee.url AS school_url, gc.countryFR AS country,
+ pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level, pefe.field,
+ FIND_IN_SET(\'primary\', pe.flags) AS prim
+ FROM profile_education AS pe
+ INNER JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
+ LEFT JOIN geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
+ INNER JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
+ LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
+ WHERE ' . $where . '
+ ORDER BY NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id
+ ' . $limit);
+ }
+
+ public function getExtraEducations($limit = null)
+ {
+ return $this->getEducations(self::EDUCATION_EXTRA, $limit);
+ }
+