/** * Execute certain hook handler * * @return void */ public function executeHookHandler() { // It's the metadata collected by Doctrine foreach ($this->getMetadata() as $main) { $node = static::getClassesTree()->find($main->name); // Process only certain classes if (!$node->isTopLevelNode() && !$node->isDecorator()) { foreach ($main->fieldMappings as $field => $info) { if ('money' == $info['type']) { $fieldName = \Includes\Utils\Converter::convertToCamelCase($field); $purposes = array('net' => ''); $behaviors = array(); if (isset($info['options']) && is_array($info['options'])) { foreach ($info['options'] as $option) { if ($option instanceof \XLite\Core\Doctrine\Annotation\Behavior) { $behaviors = array_merge($behaviors, $option->list); } elseif ($option instanceof \XLite\Core\Doctrine\Annotation\Purpose) { $purposes[$option->name] = $option->source; } } } foreach ($purposes as $purpose => $source) { $camelField = ucfirst(\Doctrine\Common\Util\Inflector::camelize($field)); $source = $source ? ucfirst($source) . $camelField : $camelField; $this->addReplacement($main, 'get', array('<getter>' => 'get' . $source, '<fieldName>' => $fieldName, '<methodName>' => ucfirst($purpose) . $camelField, '<behaviors>' => $behaviors ? '\'' . implode('\',\'', $behaviors) . '\'' : '', '<purpose>' => $purpose)); } } } } } // Populate changes $this->writeData(); }
/** * Sanitize option new value * * @param \XLite\Model\Config $option Config option * @param string $value New value * * @return string */ protected function sanitizeOptionValue($option, $value) { $category = $option->getCategory(); $name = $option->getName(); $validationMethod = 'sanitize' . \Includes\Utils\Converter::convertToCamelCase($category) . \Includes\Utils\Converter::convertToCamelCase($name); if (method_exists($this, $validationMethod)) { $value = $this->{$validationMethod}($value); } $type = $option->getType(); if ('checkbox' === $type) { $result = empty($value) ? 'N' : 'Y'; } elseif ('serialized' === $type && null !== $value && is_array($value)) { $result = serialize($value); } elseif ('text' === $type) { $result = null !== $value ? trim($value) : ''; } elseif ('XLite\\View\\FormField\\Input\\PasswordWithValue' === $type) { $result = null !== $value ? $value : null; } else { $result = null !== $value ? $value : ''; } return $result; }
/** * Return specific data for address entry. Helper. * * @param \XLite\Model\Address $address Address * @param boolean $showEmpty Show empty fields OPTIONAL * * @return array */ protected function getAddressSectionData(\XLite\Model\Address $address, $showEmpty = false) { $result = array(); $hasStates = $address->getCountry() ? $address->getCountry()->hasStates() : false; foreach (\XLite\Core\Database::getRepo('XLite\\Model\\AddressField')->findAllEnabled() as $field) { $method = 'get' . \Includes\Utils\Converter::convertToCamelCase($field->getViewGetterName() ?: $field->getServiceName()); $addressFieldValue = $address->{$method}(); $cssFieldName = $field->getCSSFieldName(); switch ($field->getServiceName()) { case 'state_id': $addressFieldValue = $hasStates ? $addressFieldValue : null; if (null === $addressFieldValue && $hasStates) { $addressFieldValue = $address->getCustomState(); } break; case 'custom_state': $addressFieldValue = $hasStates ? null : $address->getCustomState(); $cssFieldName = $hasStates ? $cssFieldName : 'address-state'; break; default: } if ($addressFieldValue || $showEmpty) { $result[$field->getServiceName()] = array('css_class' => $cssFieldName, 'title' => $field->getName(), 'value' => $addressFieldValue); } } return $result; }
/** * Execute common helper method * * @param string $type Helper type * * @return void */ public function runCommonHelpers($type) { $method = 'runCommonHelper' . \Includes\Utils\Converter::convertToCamelCase($type); if (method_exists($this, $method)) { // Run common helper method $this->{$method}(); } }
/** * Populate model object properties by the passed data * * @param array $data Data to set * * @return void */ protected function setModelProperties(array $data) { $optionsToUpdate = array(); // Find changed options and store them in $optionsToUpdate foreach ($this->getEditableOptions() as $key => $option) { $name = $option->name; $type = $option->type; $value = $option->value; $category = $option->category; $validationMethod = 'sanitize' . \Includes\Utils\Converter::convertToCamelCase($category) . \Includes\Utils\Converter::convertToCamelCase($name); if (method_exists($this, $validationMethod)) { $data[$name] = $this->{$validationMethod}($data[$name]); } if ('checkbox' === $type) { $newValue = empty($data[$name]) ? 'N' : 'Y'; } elseif ('serialized' === $type && isset($data[$name]) && is_array($data[$name])) { $newValue = serialize($data[$name]); } elseif ('text' === $type) { $newValue = array_key_exists($name, $data) ? null !== $data[$name] ? trim($data[$name]) : null : ''; } else { $newValue = array_key_exists($name, $data) ? $data[$name] : ''; } if (null !== $newValue && $value != $newValue) { $option->value = $newValue; $optionsToUpdate[] = $option; } } // Save changed options to the database if (!empty($optionsToUpdate)) { foreach ($optionsToUpdate as $option) { if ($this->preprocessOption($option)) { \XLite\Core\Database::getRepo('\\XLite\\Model\\Config')->createOption(array('category' => $option->category, 'name' => $option->name, 'value' => $option->value)); } } } }
} $targetSkinDir = $target = strtolower(preg_replace('/([a-z0-9])([A-Z])([a-z0-9])/Ss', '$1_$2$3', $target)); $targetShort = ucfirst(\Includes\Utils\Converter::convertToCamelCase($target)); $targetClass = macro_assemble_class_name('Controller\\Admin\\' . $targetShort, $moduleAuthor, $moduleName); $targetControllerPath = macro_convert_class_name_to_path($targetClass); $list = array_merge((array) @glob(LC_DIR_CLASSES . 'XLite/Controller/Admin/' . $targetShort . '.php'), (array) @glob(LC_DIR_CLASSES . 'XLite/Module/*/*/Controller/Admin/' . $targetShort . '.php')); $list = array_map('trim', $list); $list = array_filter($list, function ($var) use($targetControllerPath) { return !empty($var) && realpath($var) != $targetControllerPath; }); if ($list) { macro_error('Controller class \'' . $targetShort . '\' already exists (' . implode('; ', $list) . ')'); } $targetOne = isset($targetOne) ? $targetOne : substr($target, 0, -1); $targetOneSkinDir = $targetOne = strtolower(preg_replace('/([a-z0-9])([A-Z])([a-z0-9])/Ss', '$1_$2$3', $targetOne)); $targetOneShort = ucfirst(\Includes\Utils\Converter::convertToCamelCase($targetOne)); $targetOneClass = macro_assemble_class_name('Controller\\Admin\\' . $targetOneShort, $moduleAuthor, $moduleName); $targetOneControllerPath = macro_convert_class_name_to_path($targetOneClass); $list = array_merge((array) @glob(LC_DIR_CLASSES . 'XLite/Controller/Admin/' . $targetOneShort . '.php'), (array) @glob(LC_DIR_CLASSES . 'XLite/Module/*/*/Controller/Admin/' . $targetOneShort . '.php')); $list = array_map('trim', $list); $list = array_filter($list, function ($var) use($targetOneControllerPath) { return !empty($var) && realpath($var) != $targetOneControllerPath; }); if ($list) { macro_error('Controller class \'' . $targetOneShort . '\' already exists (' . implode('; ', $list) . ')'); } // --search $searchFields = $searchFields ? array_map('trim', explode(',', $searchFields)) : array(); foreach ($searchFields as $field) { if (!in_array($field, $keys)) { macro_error('Field \'' . $field . '\' marked as searchable and it not ofund');
/** * Return the array of substitutes for the getters/setters templates * * @param \Doctrine\ORM\Mapping\ClassMetadata $main Current multilang model class metadata * @param string $entry Entry to substitute * @param string $method "get" or "set" * @param string $field Name of field to get or set * * @return array */ protected function getMethodSubstitutes(\Doctrine\ORM\Mapping\ClassMetadata $main, $entry, $method, $field) { $result = array(); if (!$main->reflClass->hasMethod($method .= \Includes\Utils\Converter::convertToCamelCase($field))) { $result[$entry] = $method; } return $result; }
/** * Get field value from entity * * @param array $field Field * * @return mixed */ protected function getFieldEntityValue(array $field) { $method = 'get' . \Includes\Utils\Converter::convertToCamelCase($field[static::FIELD_NAME]); $addressMethod = 'get' . ucfirst($this->getParam(static::PARAM_FIELD_NAME)); // $method assembled from 'get' + field short name return $this->getEntity()->{$addressMethod}() ? $this->getEntity()->{$addressMethod}()->{$method}() : null; }