/** * Get translation for particular string. * * @static * @access public * @param string $string * @param array $options * @return string * @since 1.0.0-dev * @version 1.2.0-dev */ public static function get($string, $options = []) { $output = $string; $cachedData = static::getCachedData(); $context = Helper\Arrays::get($options, 'context', 'no_context'); if (isset($cachedData[$string]) && isset($cachedData[$string][$context])) { $output = $cachedData[$string][$context]; } return $output; }
/** * Apply style to particular image. * * @static * @access public * @param string $sStyleName * @since 1.0.0, 2014-07-13 * @version 1.1.0, 2014-07-15 */ public function apply($sStyleName) { if (static::$aImageStyles === NULL) { static::$aImageStyles = \Plethora\Config::get('image_styles'); } $aStyles = \Plethora\Helper\Arrays::get(static::$aImageStyles, $sStyleName); if ($aStyles === NULL) { throw new \Plethora\Exception\Fatal('Image style "' . $sStyleName . '" do not exists.'); } $oImage = $this->getImage(); $oImageFile = $oImage->getImageFileObject(); $sStyledImagePath = 'uploads/image_styles/' . $sStyleName . '/' . $oImageFile->getName() . '.' . $oImageFile->getExt(); if (!file_exists($sStyledImagePath)) { foreach ($aStyles as $aStyle) { $oImage = call_user_func_array(array($oImage, $aStyle[0]), $aStyle[1]); } $oImage->save($sStyledImagePath); } return $sStyledImagePath; }
/** * Method is called by Form object when this particular form is used (sent). * * @access protected * @throws Exception\Fatal * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function whenFormSubmitted() { // get sent data $sentFileData = $this->getSentFileArray(); // loop trough all sent data foreach ($sentFileData as $sLang => $allDefaultValuesForLang) { foreach ($allDefaultValuesForLang as $i => $dataBatch) { // create file broker (if not exists) $broker = Arrays::path($this->aFileBrokers, $sLang . '.' . $i, FALSE); if ($broker === FALSE) { $parent = $this->isMultilanguage() ? $this->getFormObject()->getModel()->getLocales() : $this->getFormObject()->getModel(); $broker = new $this->sBrokerModel(); /* @var $broker ModelCore\FileBroker */ if (!$broker instanceof ModelCore\FileBroker) { throw new Exception\Fatal('Given bad class name (`' . get_class($broker) . '`). ' . 'Not a `ModelCore\\FileBroker` class.'); } $broker->setParent($parent); } // if file was uploaded earlier and is in "temporary file" field $formValues = $this->getFormObject()->getMethodValue(); $tempValue = Arrays::get($formValues, 'temp_file_' . $this->getName() . '_' . $sLang . '_' . $i); if (!empty($tempValue)) { $oFile = DB::find('\\Model\\File', $tempValue); /* @var $oFile \Model\File */ Arrays::createMultiKeys($this->aFileTemp, $sLang . '.' . $i, $oFile); } // if file has been sent by $_FILE method if (isset($dataBatch['tmp_name']) && $dataBatch['tmp_name'] !== '' && $dataBatch['size'] >= 0) { $broker->setTempData($dataBatch); } // set file to filebroker $oFileForBroker = Arrays::path($this->aFileTemp, $sLang . '.' . $i, FALSE); if ($oFileForBroker !== FALSE) { $broker->setFile($oFileForBroker); } // set broker as fields value Arrays::createMultiKeys($this->aFileBrokers, $sLang . '.' . $i, $broker); $this->setValue($broker, $i, $sLang); } } }
/** * @access public * @param string $sName * @return mixed * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getConfigValue($sName) { return Helper\Arrays::get($this->aConfig, $sName, NULL); }
/** * Reset form values. * * @access protected * @return $this * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function resetValue() { $aDefaultValue = $this->getFormObject()->getDefaultVal($this->getName()); $this->aFormMethodValues = $this->getFormObject()->getMethodValue(); foreach ($this->getLangs() as $sLang) { if (isset($aDefaultValue[$sLang])) { $aDefaultValue[$sLang] = [$aDefaultValue[$sLang]]; } } if ($this->getFormObject()->isFieldsNameWithPrefix()) { $mSentData = Helper\Arrays::path($this->aFormMethodValues, $this->getFormObject()->getName() . '.' . $this->getName(), FALSE); } else { $mSentData = Helper\Arrays::get($this->aFormMethodValues, $this->getName(), FALSE); } if ($mSentData === FALSE && $this->getFormObject()->isSubmitted()) { $mSentData = []; foreach ($this->getLangs() as $sLang) { $mSentData[$sLang][] = []; } } $this->setValue($mSentData !== FALSE ? $mSentData : $aDefaultValue); return $this; }
/** * Get particular field formatter. * * @access public * @param string $sField * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getFieldFormatters($sField) { return Helper\Arrays::get($this->aFieldsFormatters, $sField, []); }
echo $amount; ?> </p> <?php } ?> </td> </tr> <tr> <td><?php echo __('Translations per application part'); ?> :</td> <td> <?php $amountPerPart = Helper\Arrays::get($info, 'amount_per_part', []); ?> <?php //dd($amountPerPart) ?> <?php foreach ($amountPerPart as $part => $data) { ?> <?php $type = NULL; switch ($part) { case 'fw': $type = 'Plethora'; break; case 'app': $type = __('Application');
/** * Get all loaded local actions. * * @static * @access public * @param string $sForRoute * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function getLocalActions($sForRoute) { return Helper\Arrays::get(static::$aLocalActions, $sForRoute, []); }
/** * Find active route in particular menu. * * @access private * @param array $routes * @param integer $parentKey * @param array $parent * @since 1.0.0-dev * @version 1.3.0-dev */ private function findActiveRoute(array &$routes, $parentKey = NULL, array $parent = []) { foreach ($routes as $i => &$route) { /* @var $route array */ /* @var $routeName string */ /* @var $routeParams array */ /* @var $activeRoutes array */ if (!isset($route['classes'])) { $route['classes'] = []; } $routeName = Helper\Arrays::get($route, 'route_name', NULL); $url = Helper\Arrays::get($route, 'url', NULL); $routeParams = Helper\Arrays::get($route, 'route_parameters', []); $activeRoutes = Helper\Arrays::get($route, 'active_routes', []); // $path = $url === NULL ? Route::factory($routeName)->path($routeParams) : $url; if ($routeName !== NULL) { $path = Route::factory($routeName)->path($routeParams); } else { $path = $url; } $path = str_replace(Router::getBase(), '', $path); $currentPath = Router::getCurrentUrl(); if (in_array(Router::getCurrentRouteName(), $activeRoutes)) { $route['classes'][] = ['current ' . $this->activeTrailClass]; } if ($parentKey !== NULL) { $route['parent_key'] = $parentKey; $route['parent'] = $parent; } if ($path === $currentPath) { $this->goBackAndSetActive($route); } if (isset($route['children']) && !empty($route['children'])) { $this->findActiveRoute($route['children'], $i, $routes); /* @var $oChildren View */ } } }
/** * Render field and return its rendered value. * * @access public * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function render() { $content = ''; $values = $this->getValue(); $langVersions = $this->isMultilanguage() ? Router::getLangs() : ['und']; $fieldDefaultId = $this->getAttributes()->getAttribute('id'); $fieldDefaultName = $this->getAttributes()->getAttribute('name'); // create all cases of this field's value foreach ($langVersions as $sLang) { $fieldValueContent = []; $langValues = Helper\Arrays::get($values, $sLang, []); $amountOfFieldValues = count($langValues); // check quantity of this field's value for particular lang if ($this->getQuantity() !== 0 && $this->getQuantity() < $amountOfFieldValues) { $amountOfFieldValues = $this->getQuantity(); } // if current amount of fields is below minimal quantity if ($amountOfFieldValues < $this->getQuantityMin()) { $amountOfFieldValues = $this->getQuantityMin(); } // if current amount of fields is higher than maximal quantity if ($this->getQuantityMax() > 0 && $amountOfFieldValues > $this->getQuantityMax()) { $amountOfFieldValues = $this->getQuantityMax(); } // container for one lang values $fieldSingleValue = View::factory('base/form/field_single_lang')->set('sLang', $sLang)->bind('oField', $this); // for each value number for ($i = 0; $i < $amountOfFieldValues; $i++) { $this->getAttributes()->setAttribute('id', $fieldDefaultId . '_' . $sLang . '_' . $i)->setAttribute('name', $fieldDefaultName . '[' . $sLang . '][' . $i . ']'); $this->renderSingleValue($fieldValueContent, $sLang, $i); } // prepend to field whole content $content .= $fieldSingleValue->bind('aLangValues', $fieldValueContent)->render(); } // field pattern if ($this->getQuantity() !== 1) { $this->getAttributes()->setAttribute('id', $fieldDefaultId . '_LANGUAGE_NUMBER')->setAttribute('name', $fieldDefaultName . '[LANGUAGE][NUMBER]'); $sPatternContent = $this->renderSingleValuePattern(); $sPattern = View::factory('base/form/field_single_value')->set('sLang', 'LANGUAGE')->set('sOneValueNumber', 'NUMBER')->bind('sOneValueContent', $sPatternContent)->bind('oField', $this)->render(); $this->getFormObject()->addFieldPattern($this->getName(), $sPattern); } // reset ID and NAME attributes $this->resetIdAttribute(); $this->resetNameAttribute(); // rendering base of field return View::factory($this->getViewBase())->render(['sContent' => $content, 'oField' => $this]); }
/** * Parse all attributes and return them as a string. * * @access public * @param array $aAddContent * @param boolean $bSaveOldValue * @param boolean $bWithSpace * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function renderAttributes($aAddContent = [], $bSaveOldValue = FALSE, $bWithSpace = TRUE) { $sReturn = ''; // render main attributes foreach ($this->aAttributes as $sName => $sValue) { if (!isset($aAddContent[$sName])) { $sReturn .= ' ' . $sName . '="' . trim($sValue) . '"'; } } // render the rest of the attributes with additional content foreach ($aAddContent as $sName => $sValue) { $sOldValue = $bSaveOldValue ? Arrays::get($this->aAttributes, $sName, '') : ''; $sReturn .= ' ' . $sName . '="' . trim($sOldValue . ($bWithSpace ? ' ' : '') . $sValue) . '"'; } // return rendered attributes return ltrim($sReturn); }
/** * Create next level of menu. * * @access private * @param array $aRoutes * @return View * @since 1.2.0-dev * @version 1.2.0-dev */ private function createNextLevel(array $aRoutes) { $aEntries = []; $this->iLevel++; foreach ($aRoutes as $aRoute) { /* @var $aRoute array */ $oItem = $aRoute['object']; /* @var $oItem \Model\Menu\Item */ $oItemLocales = $oItem->getLocales(); /* @var $oItemLocales \Model\Menu\Item\Locales */ $sRouteTitle = $oItemLocales->getName(); /* @var $sRouteTitle string */ $sRouteName = $oItem->getRoute(); /* @var $sRouteName string */ $aRouteParams = $oItem->getRouteParams() !== NULL ? $oItem->getRouteParams() : []; /* @var $aRouteParams array */ $aAttributes = Arrays::get($aRoute, 'parameters', []); /* @var $aSiblings array */ $aSiblings = Arrays::get($aRoute, 'siblings', []); /* @var $aSiblings array */ $sClasses = $oItem->getClasses(); /* @var $sClasses string */ $oSiblings = NULL; $oRoute = Route::factory($sRouteName); $aParamsTypes = array_keys($oRoute->getParameterTypes()); $aParams = array_combine($aParamsTypes, $aRouteParams); $sPath = $oRoute->path($aParams); if (!isset($aAttributes['class'])) { $aAttributes['class'] = ''; } $aAttributes['class'] = trim($sClasses . ' ' . $aAttributes['class'] . ' ' . Arrays::get($aRoute, 'classes', '')); $oSingleLevel = View::factory('menu/model/single_level')->set('sRouteTitle', $sRouteTitle)->set('sRouteName', $sRouteName)->set('sPath', $sPath)->set('aRouteParams', $aRouteParams)->set('aParameters', $aAttributes); if ($aSiblings !== []) { $oSiblings = $this->createNextLevel($aSiblings); /* @var $oSiblings View */ } $oSingleLevel->set('oSiblings', $oSiblings); $aEntries[] = $oSingleLevel; } return View::factory('menu/menu')->set('iLevel', $this->iLevel)->set('aEntries', $aEntries); }
/** * Add validation rules on the basis of ORM annotation mappings. * * @access private * @param Form\Field $oField * @param array $aMappings * @return bool * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function addValidationByMapping(Form\Field &$oField, array $aMappings) { $iLength = Arrays::get($aMappings, 'length'); $sType = Arrays::get($aMappings, 'type'); // if there are no field mappings if (empty($aMappings) || $oField instanceof Form\Field\Hidden) { return FALSE; } // 'required' validation rule if (Arrays::get($aMappings, 'nullable', FALSE) === FALSE) { $oField->setRequired(); } // validation rules by type switch ($sType) { case 'string': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\String::factory()->max(':value', $iLength)); } break; case 'integer': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\Number::factory()->max(':value', $iLength)); } break; } return TRUE; }
/** * Constructor. * * @access public * @param string $name Form name * @param array $defaultValues * @param string $method * @throws Exception\Fatal * @throws Exception * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function __construct($name, array $defaultValues = [], $method = Form::METHOD_POST) { if (preg_match('/[^a-z0-9_]/', $name) !== 0) { throw new Exception\Fatal('Name of the form can contain only small letters, numbers and an underscore characters.'); } $this->formName = $name; $this->defaultValues = $defaultValues; $this->validator = new Validator(); $this->setMethod($method); $this->setSubmitValue(__('send')); $this->setSubmitName($this->getName() . '_submit'); if (Helper\Arrays::get($this->getMethodValue(), $this->getSubmitName(), FALSE) || isset($_FILES[$this->getName()])) { $this->isFormSubmitted = TRUE; } // add javascripts $controller = Router::getInstance()->getController(); $controller->addJs('/themes/_common/js/form/form.js'); // loggin form creation Log::insert('Form "' . $name . '" has been created.'); }
/** * Method is called by Form object when this particular form is used (sent). * * @access protected * @return void * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function whenFormSubmitted() { $this->aFormMethodValues = $this->getFormObject()->getMethodValue(); if ($this->getFormObject()->isFieldsNameWithPrefix()) { $mSentData = Helper\Arrays::path($this->aFormMethodValues, $this->getFormObject()->getName() . '.' . $this->getName(), FALSE); } else { $mSentData = Helper\Arrays::get($this->aFormMethodValues, $this->getName(), FALSE); } if ($mSentData === FALSE) { foreach ($this->getLangs() as $lang) { $this->setValue([], 0, $lang); } } }
/** * @access private * @param string $sField * @return SearchEngine\RelFieldInfo|FALSE * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function getRelFieldInfo($sField = NULL) { return $sField === NULL ? $this->aRelatedFieldsList : Arrays::get($this->aRelatedFieldsList, $sField, FALSE); }
<?php /* @var $route array */ /* @var $routeTitle string */ /* @var $routeName string */ /* @var $path string */ /* @var $routeParams array */ /* @var $children View */ /* @var $classes View */ ?> <?php $prefix = \Plethora\Helper\Arrays::get($route, 'prefix', ''); $suffix = \Plethora\Helper\Arrays::get($route, 'suffix', ''); $innerPrefix = \Plethora\Helper\Arrays::get($route, 'inner_prefix', ''); $innerSuffix = \Plethora\Helper\Arrays::get($route, 'inner_suffix', ''); ?> <?php echo $prefix; ?> <li class="<?php echo implode(' ', $classes); ?> "> <?php if ($path !== NULL) { ?> <?php echo Html::a($path, $innerPrefix . '<span>' . $routeTitle . '</span>' . $innerSuffix); ?>
/** * Method generating search engine object. * * @access public * @param array $fields * @return Helper\SearchEngine * @throws Exception\Fatal * @throws Doctrine\ORM\Mapping\MappingException * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function generateSearchEngine(array $fields = []) { $searchEngine = new Helper\SearchEngine($this); $baseConfig = static::getConfig(); # search engine config foreach ($this->getConfigSearchEngine()->getRelsFields() as $varName => $relFields) { if (property_exists($this, $varName)) { $fieldMapping = static::getMetadata()->getAssociationMapping($varName); $relClass = Helper\Arrays::get($fieldMapping, 'targetEntity'); $objConfig = call_user_func($relClass . '::getConfig'); /* @var $objConfig ModelCore\MConfig */ foreach ($relFields as $fieldName) { try { $fieldName = $baseConfig->hasField($fieldName) ? $varName . '_' . $fieldName : $fieldName; $field = $objConfig->getField($fieldName); $baseConfig->addField($field); $searchEngine->addRelFieldInfo($fieldName, $fieldName, $varName, $relClass); } catch (Exception $e) { } } } else { throw new Exception\Fatal('Zmienna "' . $varName . '" nie istnieje w klase "' . static::getClass() . '".'); } } # basic config foreach ($baseConfig->getFields() as $fieldName => $field) { /* @var $field Form\Field */ if ((empty($fields) || in_array($fieldName, $fields)) && !in_array($field->getType(), Helper\SearchEngine::getBannedFieldTypes())) { if (!in_array($field->getType(), static::$notInSearchEngine)) { if (isset(static::$aChangeThoseTypes[$field->getType()])) { $field = $field->cloneToOtherType(static::$aChangeThoseTypes[$field->getType()]); } if ($field->getQuantity() !== 1) { $field->setQuantity(1); $field->setQuantityMin(1); $field->setQuantityMax(1); } $field->getAttributes()->removeAttribute('disabled'); if ($field->isRequired()) { $field->setRequiredNot(); } $searchEngine->getForm()->addSingleton($field); } } } return $searchEngine; }