/** * Converts the given value so that it can be hydrated by the hydrator. * * @param mixed $value * The original value. * @return mixed Returns the value that should be hydrated. */ public function hydrate($value) { if (Helper::is_json($value)) { $value = json_decode($value, true); } return parent::hydrate($value); }
/** * @ORM\PostLoad * * @param Lead $lead * @param LifecycleEventArgs $event */ public function postLoad(Lead $lead, LifecycleEventArgs $event) { // Get the values for the ArrayCollection and sort it using the function $attributes = $lead->getAttributes(); // Filter by active LeadAttribute if ($attributes) { $attributes = array_filter($attributes, function ($leadAttributeValue) { $attribute = $leadAttributeValue->getAttribute(); return $attribute ? $attribute->getActive() : false; }); } // sort as you like usort($attributes, function ($a, $b) { $aOrder = $bOrder = 0; $aAttribute = $a->getAttribute(); if ($aAttribute) { $aOrder = $aAttribute->getAttributeOrder(); } $bAttribute = $b->getAttribute(); if ($bAttribute) { $bOrder = $bAttribute->getAttributeOrder(); } return $aOrder - $bOrder; }); // Clear the current collection values and reintroduce in new order. $lead->setAttributes(new ArrayCollection($attributes)); $default_ip = "0.0.0.0"; $ip = $lead->getIpaddress(); $ip_filtered = Helper::validate_ipv4($ip, false) ? $ip : $default_ip; $lead->setIpv4address($ip_filtered); $referrer = $lead->getReferrer(); $referrer_filtered = $referrer ? Helper::add_protocol(strtolower($referrer)) : null; $lead->setReferrer($referrer_filtered); }
/** * @ORM\PostLoad * * @param AgentCriterionValue $agentCriterionValue * @param LifecycleEventArgs $event */ public function postLoad(AgentCriterionValue $agentCriterionValue, LifecycleEventArgs $event) { $fValue = null; $value = $agentCriterionValue->getValue(); if ($value && Helper::is_serialized($value, $fValue)) { $agentCriterionValue->setValue($fValue); } }
/** * * @param array $location * * @return Elastica\Query $localityQuery */ public static function getLocalityQuery($location) { $query = new Agent\Elastica\Query\BoolQuery(); $method = 'addMust'; if (!isset($location['state']) && !isset($location['zip']) && !isset($location['locality'])) { foreach (['phone', 'ipaddress'] as $field) { if (isset($location[$field]) && empty($location['state'])) { switch ($field) { case 'ipaddress': $geo = self::$geo; $loc = $geo->getRecord($location['ipaddress']); if ($loc instanceof Record) { $state = $loc->getRegion(); if ($state) { $location['state'] = $state; } } break; case 'phone': $phone = Helper::parse_phonenumber($location['phone'], 'array'); if ($phone) { $state = Helper::area_code_to_state($phone[0]); if ($state) { $location['state'] = $state; } } break; } } } } foreach ($location as $field => $value) { switch ($field) { case 'locality': if (!isset($location['zip'])) { $fields = ['latitude', 'longitude']; $values = is_array($value) ? $value : explode(",", $value); $latlon = count($values) == 2 ? array_combine($fields, $values) : false; if ($latlon) { $path = "location"; $nested = new Elastica\Query\Nested(); $nested->setPath($path); $bool = new Elastica\Query\BoolQuery(); foreach ($latlon as $dim => $coord) { $bool->addMust(new Elastica\Query\Match("{$path}.{$dim}", $coord)); } $nested->setQuery($bool); $query->addMust($nested); } } break; case 'city': if (!isset($location['locality'])) { $query->addShould(new Elastica\Query\Match($field, $value)); } break; case 'state': if (!isset($location['locality'])) { $fields = ['state.abbrev', 'state.full']; $values = is_array($value) ? $value : [$value]; foreach ($values as $state) { $querystring = new Elastica\Query\QueryString($state); $querystring->setFields($fields); $nested = new Elastica\Query\Nested(); $nested->setQuery($querystring); $nested->setPath($field); if (count($values) > 1) { $query->addShould($nested); } else { $query->addMust($nested); } } } break; case 'zip': $query->{$method}(new Elastica\Query\Match($field, $value)); break; } } $localityQuery = new Elastica\Query($query); $localityQuery->setSize(1); return $localityQuery; }
?> <?php foreach ($entry as $data_label => $data_value) { ?> <tr> <td><?php echo $data_label; ?> </td> <?php if (is_array($data_value)) { ?> <td><?php echo Helper::recursive_implode($data_value, ", ", false, false); ?> </td> <?php } else { ?> <td><?php echo $data_value; ?> </td> <?php } ?> </tr> <?php }
public function addScripts(ElementInterface $oElement) { $view = $this->getView(); $inlinejs = ''; $allow_add = $oElement->getOption('allow_add'); $allow_remove = $oElement->getOption('allow_remove'); if ($allow_add || $allow_remove) { $id = $oElement->getAttribute('id'); $name = Helper::camelCase($oElement->getName()); $remove = $allow_remove ? 'true' : 'false'; if ($allow_add) { $inlinejs .= sprintf(self::$addScriptFormat, $name, $id, $remove); } if ($allow_remove) { $inlinejs .= sprintf(self::$removeScriptFormat, $name, $id); } $script = $view->inlineScript(); $headScript = $view->headScript(); $script->appendScript($inlinejs, 'text/javascript', array('noescape' => true)); // Disable CDATA comments } }
protected function formatFormMessages($form, $glue = ". <br>\n", $debug = false) { $messages = $form->getMessages(); $output = []; foreach ($messages as $field => $notice) { foreach ($notice as $rule => $message) { if (is_array($message)) { $output[] = "The field \"{$field}\" is invalid. " . ($debug ? $glue . Helper::recursive_implode($message, $glue) : ""); } else { $output[] = "The field \"{$field}\" is invalid. {$message}"; } } } return implode($glue, $output); }
protected function getDateOfBirth(Lead $lead) { $DateOfBirth = null; $match = $lead->findAttribute('birth', true); if ($match) { $date = $match->getValue(); $DateOfBirth = $date instanceof \DateTime ? date_format('m/d/Y', $date) : (Helper::validateDate($date) ? date('m/d/Y', strtotime($date)) : null); } return $DateOfBirth; }
protected function getSources(array $results = [], $list = false) { $sources = []; if (!$results) { $results = $this->getReferrers(); } foreach ($results as $record) { $referrer = Helper::add_protocol(strtolower($record['referrer'])); $domain = $referrer ? parse_url($referrer, PHP_URL_HOST) : false; $count = $record['refcount']; if (!$domain) { $domain = 'unknown'; } if (isset($sources[$domain])) { $sources[$domain]['referrers'][] = $record['referrer']; $sources[$domain]['count'] += $count; } else { $sources[$domain] = ['source' => $domain, 'count' => $count, 'referrers' => [$record['referrer']]]; } } if ($list) { $sources = array_combine(array_keys($sources), array_keys($sources)); } return $sources; }
/** * Handle Confirm (Stage 4) * * @param array $post * @param Form $form * @param boolean $reload * * @return mixed */ protected function handleConfirm($post, $form, $reload = false) { $outcome = false; $valid = false; $request = $this->getRequest(); $invalid = false; $form->setData($post); if ($form->isValid()) { if ($post && isset($post['match'], $post['leadTmpFile'])) { $match = $post['match']; if (Helper::is_json($match)) { $match = json_decode($match, true); } $company = $post['Company']; $tmp_file = $this->getUploadPath() . '/' . $post['leadTmpFile']; $duplicates = isset($post['duplicate']) ? $post['duplicate'] : false; $importFieldset = $form->getImportFieldset(); $form->addConfirmField(); $csv = $this->parseFile($tmp_file); if ($csv['count']) { $data = $this->mapImportedValues($csv['body'], $match, false); $valid = $this->validateImportData($data, $duplicates); if ($valid) { $outcome = true; $headings = $this->getHeadings(); $invalid = array_filter($valid); $form = $this->addImportFields($form, $data, $valid); $form->get('submit')->setValue('Confirm'); $form->addCancelField(); $form->addHiddenField('Company', $company); $this->stage = 4; $this->results['stage'] = $this->stage; $this->results['fields'] = $form->getLeadAttributes(); $this->results['data'] = $data; $this->results['valid'] = $valid; $this->results['form'] = $form; $this->results['headings'] = $headings; $this->setImportCache($this->stage, $post); } } if (!$valid || $valid === $invalid) { $outcome = false; $message = "No valid records could be imported."; $this->flashMessenger()->addErrorMessage($message); } } } else { $message = "You have invalid Form Entries."; $this->flashMessenger()->addErrorMessage($message); $messages = $form->getMessages(); if ($messages) { $this->flashMessenger()->addErrorMessage($this->formatFormMessages($form)); } } return $outcome; }
<th>Field</th> <th>Imported Record</th> <th>Existing Record</th> </tr> </thead> <tbody> <?php foreach ($data as $attribute_id => $entry) { ?> <?php foreach ($entry as $data_label => $data_value) { ?> <?php if (is_array($data_value)) { $data_value = Helper::recursive_implode($data_value); } ?> <tr class="<?php if (isset($fields[$attribute_id])) { echo "duplicate"; } ?> "> <td><?php echo $data_label; ?> </td> <td><?php
public function __toString() { $fValue = $this->getValue(); $criterion = $this->getCriterion(); if ($criterion) { $relationship = $criterion->getRelationship(); if ($relationship) { $type = $relationship->getInput(); if ($type) { $methodName = "get" . ucwords($type); if (method_exists($this, $methodName)) { switch ($type) { case 'boolean': case 'string': case 'daterange': case 'range': $fValue = $this->{$methodName}(); break; case 'location': case 'multiple': $value = $this->{$methodName}(); $fValue = is_array($value) ? Helper::recursive_implode($value, ", ", false) : $value; break; } } } } } return $fValue; }
public function format_value($value, $type = null) { $formatted = null; if (!$type) { $attribute = $this->getAttribute(); if (isset($attribute)) { $type = $attribute->getAttributeType() ?: 'string'; } } switch ($type) { case 'date': $date = str_replace('-', '/', $this->value); if (count(explode('/', $date)) > 1) { $ts = strtotime($date); if (date('Y', $ts) > date('Y')) { $darray = []; $darray[] = date('m', $ts); $darray[] = date('d', $ts); $darray[] = date('Y', $ts) - 100; $date = implode('/', $darray); } if (Helper::validateDate($date)) { $formatted = new \DateTime(date('Y-m-d', strtotime($date))); } } break; case 'number': $limits = ['upper' => pow(2, 31) - 1, 'lower' => -1 * (pow(2, 31) - 1)]; if (preg_match('/([\\d\\.]+)/i', $value, $match)) { $number = isset($match[1]) ? $match[1] : null; if (!$number || !is_numeric($number)) { $formatted = null; } else { $float = floatval($number); $formatted = $float > $limits['upper'] || $float < $limits['lower'] ? null : $float; } } break; default: $formatted = $value; break; } return $formatted; }
/** * Run Jobs Queue * * @return mixed */ protected function runQueue() { $outcome = false; if ($this->queue) { $count = count($this->queue); $i = 0; foreach ($this->queue as $job) { $return = true; $message = false; $type = 'notice'; if (isset($job->callback) && Helper::is_closure($job->callback)) { $return = $job->callback(); } if (isset($job->progress)) { if (is_numeric($job->progress)) { $this->progress += $job->progress; } elseif (Helper::is_closure($job->progress)) { $this->progress += $job->progress($this->progress); } } if ($return && !$return instanceof \Exception) { if (Helper::is_closure($job->message)) { $message = $job->message($return); } elseif ($job->message) { $message = $job->message; } else { $message = ["status" => "running", "message" => "{$this->progress} completed."]; } } elseif ($return instanceof \Exception) { $message = ["status" => "running", "message" => $return->getMessage()]; $type = 'fail'; break; } else { $message = ["status" => "error", "message" => "Oops. Something went wrong."]; $type = 'fail'; break; } if (!$message) { $message = ["status" => "running", "message" => "{$this->progress} completed."]; } $i++; if ($count == $i) { $type = 'success'; } $outcome = $this->onProgress($message, $type); sleep(1); } } return $outcome; }