+ 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];
+ if ($this->mobile && !in_array($this->mobile_pub, $this->visibility)) {
+ unset($this->data['mobile']);
+ }
+ }
+
+
+ /* Photo
+ */
+ public function getPhoto($fallback = true)
+ {
+ /* TODO: migrate photo table to profile_photo, change uid to pid
+ */
+ $cond = '';
+ if ($this->visibility) {
+ $cond = ' AND pub IN ' . XDB::formatArray($this->visibility);
+ }
+ $res = XDB::query('SELECT *
+ FROM profile_photos
+ WHERE attachmime IN (\'jpeg\', \'png\')
+ ' . $cond . ' AND pid = {?}',
+ $this->id());
+ if ($res->numRows() > 0) {
+ $photo = $res->fetchOneAssoc();
+ return PlImage::fromData($photo['attach'], 'image/' . $photo['attachmime'],
+ $photo['x'], $photo['y']);
+ } else if ($fallback) {
+ return PlImage::fromFile(dirname(__FILE__).'/../htdocs/images/none.png',
+ 'image/png');
+ }
+ return null;
+ }
+
+ /* 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,
+ ppfix.display_tel AS fixed_tel, ppfax.display_tel AS fax_tel,
+ 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)
+ LEFT JOIN profile_phones AS ppfix ON (ppfix.link_type = \'address\' AND ppfix.pid = pa.pid AND ppfix.link_id = pa.id AND ppfix.tel_type = \'fixed\')
+ LEFT JOIN profile_phones AS ppfax ON (ppfax.link_type = \'address\' AND ppfax.pid = pa.pid AND ppfax.link_id = pa.id AND ppfax.tel_type = \'fax\')
+ 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.pid = {?}', $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);
+ }
+
+
+ /** Networking
+ */
+
+ public function getNetworking($flags, $limit = null)
+ {
+ $where = XDB::format('pn.pid = {?}', $this->id());
+ if ($flags & self::NETWORKING_WEB) {
+ $where .= ' AND pn.network_type = 0'; // XXX hardcoded reference to web site index
+ }
+ if ($this->visibility) {
+ $where .= ' AND pn.pub IN ' . XDB::formatArray($this->visibility);
+ }
+ $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
+ return XDB::iterator('SELECT pne.name, pne.icon,
+ IF (LENGTH(pne.link) > 0, REPLACE(pne.link, \'%s\', pn.address),
+ pn.address) AS address
+ FROM profile_networking AS pn
+ INNER JOIN profile_networking_enum AS pne ON (pn.network_type = pne.network_type)
+ WHERE ' . $where . '
+ ORDER BY pn.network_type, pn.nwid
+ ' . $limit);
+ }
+
+ public function getWebSite()
+ {
+ $site = $this->getNetworking(self::NETWORKING_WEB, 1);
+ if ($site->total() != 1) {
+ return null;
+ }
+ $site = $site->next();
+ return $site['address'];
+ }
+
+
+ /** Jobs
+ */
+
+ public function getJobs($flags, $limit = null)
+ {
+ $where = XDB::format('pj.pid = {?}', $this->id());
+ $cond = 'TRUE';
+ if ($this->visibility) {
+ $where .= ' AND pj.pub IN ' . XDB::formatArray($this->visibility);
+ $cond = 'pj.email_pub IN ' . XDB::formatArray($this->visibility);
+ }
+ $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
+ return XDB::iterator('SELECT pje.name, pje.acronym, pje.url, pje.email, pje.NAF_code,
+ pj.description, pj.url AS user_site,
+ IF (' . $cond . ', pj.email, NULL) AS user_email,
+ pjse.name AS sector, pjsse.name AS subsector,
+ pjssse.name AS subsubsector
+ FROM profile_job AS pj
+ INNER JOIN profile_job_enum AS pje ON (pje.id = pj.jobid)
+ LEFT JOIN profile_job_sector_enum AS pjse ON (pjse.id = pj.sectorid)
+ LEFT JOIN profile_job_subsector_enum AS pjsse ON (pjsse.id = pj.subsectorid)
+ LEFT JOIN profile_job_subsubsector_enum AS pjssse ON (pjssse.id = pj.subsubsectorid)
+ WHERE ' . $where . '
+ ORDER BY pj.id
+ ' . $limit);
+ }
+
+ public function getMailJob()
+ {
+ $job = $this->getJobs(self::JOBS_MAIN, 1);
+ if ($job->total() != 1) {
+ return null;
+ }
+ return $job->next();
+ }
+
+ /* Binets
+ */
+ public function getBinets()
+ {
+ return XDB::fetchColumn('SELECT binet_id
+ FROM profile_binets
+ WHERE pid = {?}', $this->id());
+ }
+