public function value(ProfilePage $page, $field, $value, &$success) { $entreprise = ProfileValidate::get_typed_requests($page->pid(), 'entreprise'); $entr_val = 0; $init = false; if (is_null($value)) { $value = $this->fetchJobs($page); $init = true; } $success = true; foreach ($value as $key => $job) { $job['name'] = trim($job['name']); if ($job['name'] == '' && $entreprise[$entr_val]->id == $key) { $job['tmp_name'] = $entreprise[$entr_val]->name; ++$entr_val; } else { if ($job['name'] == '') { if ($job['description'] == '' && $job['w_url'] == '' && $job['w_address']['text'] == '' && $job['w_email'] == '' && count($job['w_phone']) >= 1 && $job['w_phone'][0]['display'] == '') { unset($value[$key]); continue; } if (!$init) { $job['name_error'] = true; $success = false; } } } if (isset($job['removed']) && $job['removed']) { if (!S::user()->checkPerms('directory_private') && (Phone::hasPrivate($job['w_phone']) || Address::hasPrivate($job['w_address']) || $job['w_email_pub'] == 'private')) { Platal::page()->trigWarning("L'entreprise ne peut être supprimée car elle contient des informations pour lesquelles vous n'avez pas le droit d'édition."); } else { if ($job['name'] == '' && $entreprise && isset($entreprise[$entr_val - 1])) { $entreprise[$entr_val - 1]->clean(); } unset($value[$key]); continue; } } if (!isset($job['pub']) || !$job['pub']) { $job['pub'] = 'private'; } $value[$key] = $job; } foreach ($value as $key => &$job) { $address = new Address($job['w_address']); $s = $address->format(); // Force the address publicity to be at least as restricted as // the job publicity. $job_level = $job['pub']; if (Visibility::isLessRestrictive($job_level, $address->pub)) { $address->pub = $job_level; } $job['w_address'] = $address->toFormArray(); $this->cleanJob($page, $key, $job, $s, $job_level); if (!$init) { $success = $success && $s; } } usort($value, 'Visibility::comparePublicity'); return $value; }
$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)) { foreach ($duplicates as $key => $bool) { unset($phones[$key]); } } if (count($phones) != $count) { $deleted += $count - count($phones); Phone::deletePhones($pid, 'user'); $id = 0; foreach ($phones as $phone) {
private static function formArrayWalk(array $data, $function, &$success = true, $requiresEmptyPhone = false, $maxPublicity = null) { $phones = array(); if (!is_null($data)) { foreach ($data as $item) { $phone = new Phone($item); $success = !$phone->error && ($phone->format() || $phone->isEmpty()) && $success; if (!$phone->isEmpty()) { // Restrict phone visibility to $maxPublicity if (!is_null($maxPublicity) && Visibility::isLessRestrictive($maxPublicity, $phone->pub)) { $phone->pub = $maxPublicity; } $phones[] = call_user_func(array($phone, $function)); } } } if (count($phones) == 0 && $requiresEmptyPhone) { $phone = new Phone(); if (!is_null($maxPublicity) && Visibility::isLessRestrictive($maxPublicity, $phone->pub)) { // Restrict phone visibility to $maxPublicity $phone->pub = $maxPublicity; } $phones[] = call_user_func(array($phone, $function)); } return $phones; }