private function fetchJobs(ProfilePage $page) { // Build the jobs tree $jobs = XDB::fetchAllAssoc('SELECT j.id, j.jobid, je.name, j.description, j.email AS w_email, j.email_pub AS w_email_pub, j.url AS w_url, j.pub, j.entry_year AS w_entry_year FROM profile_job AS j LEFT JOIN profile_job_enum AS je ON (j.jobid = je.id) WHERE j.pid = {?} ORDER BY j.id', $page->pid()); if (empty($jobs)) { return array($this->emptyJob()); } $compagnies = array(); $backtrack = array(); foreach ($jobs as $key => $job) { $compagnies[] = $job['jobid']; $backtrack[$job['id']] = $key; } $it = Address::iterate(array($page->pid()), array(Address::LINK_JOB), array(), Visibility::get(Visibility::VIEW_ADMIN)); while ($address = $it->next()) { $jobs[$address->id]['w_address'] = $address->toFormArray(); } $it = Phone::iterate(array($page->pid()), array(Phone::LINK_JOB), array(), Visibility::get(Visibility::VIEW_ADMIN)); while ($phone = $it->next()) { $jobs[$phone->link_id]['w_phone'][$phone->id] = $phone->toFormArray(); } $res = XDB::iterator("SELECT e.jtid, e.full_name, j.jid\n FROM profile_job_term_enum AS e\n INNER JOIN profile_job_term AS j USING(jtid)\n WHERE pid = {?}\n ORDER BY j.jid", $page->pid()); while ($term = $res->next()) { // $jid is the ID of the job among this user's jobs $jid = $term['jid']; if (!isset($backtrack[$jid])) { continue; } $job =& $jobs[$backtrack[$jid]]; if (!isset($job['terms'])) { $job['terms'] = array(); } $job['terms'][] = $term; } $phone = new Phone(); $address = new Address(); foreach ($jobs as $id => &$job) { if (!isset($job['w_phone'])) { $job['w_phone'] = array(0 => $phone->toFormArray()); } if (!isset($job['w_address'])) { $job['w_address'] = $address->toFormArray(); } $job['w_email_new'] = ''; if (!isset($job['w_email_pub'])) { $job['w_email_pub'] = 'private'; } } return $jobs; }
printf("\r%u / %u", $i, $total); } } printf("\r%u / %u", $i, $total); print "\nFormating done.\n\n"; print "Deletes duplicated phones. (4/4)\n"; $pids = XDB::rawFetchColumn("SELECT DISTINCT(pid)\n FROM profile_phones AS p1\n WHERE link_type = 'user' AND EXISTS (SELECT *\n FROM profile_phones AS p2\n WHERE p2.link_type = 'user' AND p2.pid = p1.pid AND p2.tel_id != p1.tel_id)\n ORDER BY pid"); $total = count($pids); $done = 0; $aux = 0; $deleted = 0; $phones = array(); $duplicates = array(); foreach ($pids as $pid) { $count = 0; $it = Phone::iterate(array($pid), array(Phone::LINK_PROFILE), array(0), Visibility::get(Visibility::VIEW_PRIVATE)); while ($item = $it->next()) { $phones[] = $item; ++$count; } for ($i = 0; $i < $count; ++$i) { for ($j = $i + 1; $j < $count; ++$j) { if ($phones[$i]->search == $phones[$j]->search) { $duplicates[$j] = true; if (Visibility::isLessRestrictive($phones[$i]->pub, $phones[$j]->pub)) { $phones[$i]->pub = $phones[$j]->pub; } } } } if (count($duplicates)) {
public function next() { if (is_null($this->dbiter)) { return null; } $data = $this->dbiter->next(); if (is_null($data)) { return null; } // Adds phones to addresses. $it = Phone::iterate(array($data['pid']), array(Phone::LINK_ADDRESS), array($data['id']), $this->visibility); while ($phone = $it->next()) { $data['phones'][$phone->id] = $phone->toFormArray(); } return new Address($data); }
public function value(ProfilePage $page, $field, $value, &$success) { $success = true; $phones = array(); if (is_null($value)) { $it = Phone::iterate(array($page->pid()), array(Phone::LINK_PROFILE), array(0), Visibility::get(Visibility::VIEW_ADMIN)); while ($phone = $it->next()) { $success = $phone->format() && $success; $phones[] = $phone->toFormArray(); } if (count($phones) == 0) { $phone = new Phone(); $phones[] = $phone->toFormArray(); } return $phones; } else { $phones = Phone::formatFormArray($value, $success); if (!$success) { Platal::page()->trigError('Numéro de téléphone invalide'); } return $phones; } }
public static function preload($pids = array()) { if (self::$fullload) { return; } // Load raw data if (count($pids)) { $join = 'LEFT JOIN profile_job ON (profile_job.jobid = pje.id)'; $where = 'WHERE profile_job.pid IN ' . XDB::formatArray($pids); } else { $join = ''; $where = ''; } $it = XDB::iterator('SELECT pje.id, pje.name, pje.acronym, pje.url, pa.flags, pa.text, pa.type, pa.pub FROM profile_job_enum AS pje LEFT JOIN profile_addresses AS pa ON (pje.id = pa.jobid AND pa.type = \'hq\') ' . $join . ' ' . $where); $newcompanies = array(); while ($row = $it->next()) { $cp = new Company($row); $addr = new Address($row); $cp->setAddress($addr); if (!array_key_exists($row['id'], self::$companies)) { $newcompanies[] = $row['id']; } self::$companies[$row['id']] = $cp; } // Add phones to hq if (count($newcompanies)) { $it = Phone::iterate(array(), array(Phone::LINK_COMPANY), $newcompanies, Visibility::defaultForRead()); while ($phone = $it->next()) { self::$companies[$phone->link_id]->setPhone($phone); } } if (count($pids) == 0) { self::$fullload = true; } }