public function testIfItReturnMostRepeatedValueInStringArray() { $array = ['Apple', 'Orange', 'Plum', 'Apple', 'Grape', 'Apple']; $utils = new ArrayUtils(); $mostRepeatedValue = $utils->mostRepeatedValue($array); $this->assertEquals('Apple', $mostRepeatedValue); }
public function buildDashboard() { $this->setDashboardTitle("Stock Dashboard"); $this->setActionPath("/static/transfer/build/tour/motherboard_stock_action.php"); $kpi = new KPIGroupComponent('kpi'); $kpi->setDimensions(12, 2); $kpi->setCaption('Units stock by Category'); $Units = $this->get_units(true); foreach ($Units as $key => $value) { $kpi->addKPI($value['id'], array('caption' => $value['CategoryName'], 'value' => $value['Quantity'], 'numberSuffix' => ' units', 'numberHumanize' => true)); } $this->addComponent($kpi); $table = new TableComponent('table'); $table->setCaption("List of Item in Stock"); $table->setDimensions(6, 5); $stock = $this->get_stock(); $table->addColumn('id', 'Product Id'); $table->addColumn('name', 'Product Name'); $table->addColumn('category', 'Category'); $table->addColumn('price', 'Price', array("numberPrefix" => "\$", "dataType" => "number")); $table->addColumn('stock', 'Stock'); $table->addMultipleRows($this->PolulateData($stock)); $this->addComponent($table); $c12 = new FormComponent('filter'); $c12->setDimensions(6, 5); $c12->setCaption('Filter items in stock'); $category = $this->get_category(); $c12->addSelectField('category', 'Select Category', array_merge(['no selection'], ArrayUtils::pluck($category, 'CategoryName'))); $c12->addTextField('contains', 'Product Name Contains'); $c12->addNumericRangeField('stock', 'Units In Stock', array(0, 100)); $this->addComponent($c12); $c12->onApplyClick(array($table), 'handleApply', $this); }
function getCMSFields() { $fields = new FieldList($rootTab = new TabSet("Root")); $fields->addFieldsToTab('Root.Main', array(new LiteralField('Break', ColumnFormatter::$left_column_start), new CustomCheckboxSetField('Toolkits', 'What toolkits do you use or plan to use to interact with the OpenStack API?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$toolkits_options, null, array('Other' => 'Other Toolkits (please specify)'))), $t1 = new TextareaField('OtherToolkits', ''), new LiteralField('Break', ColumnFormatter::$right_column_start), new CustomCheckboxSetField('ProgrammingLanguages', 'If you wrote your own code for interacting with the OpenStack API, what programming language did you write it in?', ArrayUtils::AlphaSort(AppDevSurveyOptions::$languages_options, null, array('Other' => 'Other (please specify)'))), $t2 = new TextareaField('OtherProgrammingLanguages', ''), new LiteralField('Break', ColumnFormatter::$end_columns), new LiteralField('Break', ColumnFormatter::$left_column_start), new CustomCheckboxSetField('APIFormats', 'If you wrote your own code for interacting with the OpenStack API, what wire format are you using?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$api_format_options, null, array('Other' => 'Other Wire Format (please specify)'))), $t3 = new TextareaField('OtherAPIFormats', ''), new CustomCheckboxSetField('OperatingSystems', 'What operating systems are you using or plan on using to develop your applications?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$opsys_options, null, array('Other' => 'Other Development OS (please specify)'))), $t4 = new TextareaField('OtherOperatingSystems', ''), new CustomCheckboxSetField('GuestOperatingSystems', 'What guest operating systems are you using or plan on using to deploy your applications to customers?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$opsys_options, null, array('Other' => 'Other Development OS (please specify)'))), $t5 = new TextareaField('OtherGuestOperatingSystems', ''), new LiteralField('Break', '<hr/>'), new LiteralField('Break', '<p>Please share your thoughts with us on the state of applications on OpenStack</p>'), new TextAreaField('StruggleDevelopmentDeploying', 'What do you struggle with when developing or deploying applications on OpenStack?'), $docs = new DropdownField('DocsPriority', 'What is your top priority in evaluating API and SDK docs?', AppDevSurveyOptions::$docs_priority_options), $t6 = new TextareaField('OtherDocsPriority', ''))); $docs->setEmptyString('-- Select One --'); return $fields; }
function __construct($controller, $name) { // Define fields ////////////////////////////////////// $fields = new FieldList(new LiteralField('paragraph', '<p> The questions on this page are optional, but will help us better understand the details of how you are using and interacting with OpenStack. Any information you provide on this step will be treated as private and confidential and only used in aggregate reporting. </p> <p> <strong>If you do not wish to answer these questions, you make <a href="' . $controller->Link('SkipAppDevSurvey') . '">skip to the next section</a>.</strong> </p><hr>'), new CustomCheckboxSetField('Toolkits', 'What toolkits do you use or plan to use to interact with the OpenStack API?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$toolkits_options, null, array('Other' => 'Other Toolkits (please specify)'))), $t1 = new TextareaField('OtherToolkits', ''), new LiteralField('Container', '<div id="wrote_your_own_container" class="hidden">'), $programming_lang = new CustomCheckboxSetField('ProgrammingLanguages', 'If you wrote your own code for interacting with the OpenStack API, what programming language did you write it in?', ArrayUtils::AlphaSort(AppDevSurveyOptions::$languages_options, null, array('Other' => 'Other (please specify)'))), $other_programming_lang = new TextareaField('OtherProgrammingLanguages', ''), new CustomCheckboxSetField('APIFormats', 'If you wrote your own code for interacting with the OpenStack API, what wire format are you using?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$api_format_options, null, array('Other' => 'Other Wire Format (please specify)'))), $t3 = new TextareaField('OtherAPIFormats', ''), new LiteralField('Container', '</div>'), new CustomCheckboxSetField('OperatingSystems', 'What operating systems are you using or plan on using to develop your applications?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$opsys_options, null, array('Other' => 'Other Development OS (please specify)'))), $t4 = new TextareaField('OtherOperatingSystems', ''), new CustomCheckboxSetField('GuestOperatingSystems', 'What guest operating systems are you using or plan on using to deploy your applications to customers?<BR>Select All That Apply', ArrayUtils::AlphaSort(AppDevSurveyOptions::$opsys_options, null, array('Other' => 'Other Development OS (please specify)'))), $t5 = new TextareaField('OtherGuestOperatingSystems', ''), new LiteralField('Break', '<hr/>'), new LiteralField('Break', '<p>Please share your thoughts with us on the state of applications on OpenStack</p>'), new TextAreaField('StruggleDevelopmentDeploying', 'What do you struggle with when developing or deploying applications on OpenStack?'), $docs = new DropdownField('DocsPriority', 'What is your top priority in evaluating API and SDK docs?', AppDevSurveyOptions::$docs_priority_options), $t6 = new TextareaField('OtherDocsPriority', '')); $t1->addExtraClass('hidden'); $t3->addExtraClass('hidden'); $t4->addExtraClass('hidden'); $t5->addExtraClass('hidden'); $t6->addExtraClass('hidden'); $other_programming_lang->addExtraClass('hidden'); $docs->setEmptyString('-- Select One --'); // $prevButton = new CancelFormAction($controller->Link().'Login', 'Previous Step'); $nextButton = new FormAction('SaveAppDevSurvey', ' Next Step '); $actions = new FieldList($nextButton); // Create Validators $validator = new RequiredFields(); Requirements::javascript('surveys/js/deployment_survey_appdevsurvey_form.js'); parent::__construct($controller, $name, $fields, $actions, $validator); if ($AppDevSurvey = $this->controller->LoadAppDevSurvey()) { $this->loadDataFrom($AppDevSurvey->data()); } }
function serializeArray($result, $instance, $isSimpleResult, $serverKey) { $json = ""; if (is_array($result)) { if (ArrayUtils::isAssociative($result)) { $json .= "{"; foreach ($result as $key => $value) { $json .= '"' . $key . '":'; if (is_object($value)) { $json .= serializeObject($value, $instance, false, $serverKey); } else { if (is_array($value)) { $json .= serializeArray($value, $instance, $isSimpleResult, $serverKey); } else { $json .= serializeObject($value, $instance, !is_object($value), $serverKey); } } $json .= ","; } } else { $json .= "["; for ($i = 0; $i < count($result); $i++) { $json .= serializeObject($result[$i], $instance, $isSimpleResult, $serverKey) . ","; } } $json = JsonUtils::removeLastChar($result, $json); if (ArrayUtils::isAssociative($result)) { $json .= "}"; } else { $json .= "]"; } } return $json; }
function __construct($controller, $name) { $org_field = null; $current_user = Member::currentUser(); $current_affiliations = $current_user->getCurrentAffiliations(); if (!$current_affiliations) { $org_field = new TextField('Organization', 'Your Organization Name'); } else { if (count($current_affiliations) > 1) { $source = array(); foreach ($current_affiliations as $a) { $org = $a->Organization(); $source[$org->ID] = $org->Name; } $source['0'] = "-- New One --"; $ddl = new DropdownField('OrgID', 'Your Organization', $source); $ddl->setEmptyString('-- Select Your Organization --'); $org_field = new FieldGroup(); $org_field->push($ddl); $org_field->push($txt = new TextField('Organization', '')); $txt->addExtraClass('new-org-name'); } else { $org_field = new TextField('Organization', 'Your Organization Name', $current_user->getOrgName()); } } $fields = new FieldList($org_field, new DropdownField('Industry', 'Your Organization’s Primary Industry', ArrayUtils::AlphaSort(DeploymentSurveyOptions::$industry_options, array('' => '-- Please Select One --'), array('Other' => 'Other Industry (please specify)'))), new TextareaField('OtherIndustry', 'Other Industry'), $org_it_activity = new TextareaField('ITActivity', 'Your Organization’s Primary IT Activity'), new LiteralField('Break', '<hr/>'), new LiteralField('Break', '<p>Your Organization’s Primary Location or Headquarters</p>'), $country = new DropdownField('PrimaryCountry', 'Country', CountryCodes::$iso_3166_countryCodes), new TextField('PrimaryState', 'State / Province / Region'), new TextField('PrimaryCity', 'City'), new DropdownField('OrgSize', 'Your Organization Size (All Branches, Locations, Sites)', DeploymentSurveyOptions::$organization_size_options), new CustomCheckboxSetField('OpenStackInvolvement', 'What best describes your Organization’s involvement with OpenStack?<BR>Select All That Apply', ArrayUtils::AlphaSort(DeploymentSurveyOptions::$openstack_involvement_options))); $org_it_activity->addExtraClass('hidden'); $country->setEmptyString('-- Select One --'); $nextButton = new FormAction('NextStep', ' Next Step '); $actions = new FieldList($nextButton); $validator = new RequiredFields(); Requirements::javascript('surveys/js/deployment_survey_yourorganization_form.js'); parent::__construct($controller, $name, $fields, $actions, $validator); }
protected function __construct() { $this->array = ArrayUtils::instance(); $this->file = FileUtils::instance(); $this->object = ObjectUtils::instance(); $this->string = StringUtils::instance(); }
/** * Defined by Zend\Validator\ValidatorInterface * * Returns true if all values validate true * * @param mixed $value * @param mixed $context Additional context * @return bool * @throws RuntimeException */ public function isValid($value, $context = null) { $this->setValue($value); if ($value instanceof Traversable) { $value = ArrayUtils::iteratorToArray($value); } if (is_array($value)) { $values = $value; } elseif (is_string($value)) { $delimiter = $this->getValueDelimiter(); // Skip explode if delimiter is null, // used when value is expected to be either an // array when multiple values and a string for // single values (ie. MultiCheckbox form behavior) $values = null !== $delimiter ? explode($this->valueDelimiter, $value) : array($value); } else { $values = array($value); } $validator = $this->getValidator(); if (!$validator) { throw new RuntimeException(sprintf('%s expects a validator to be set; none given', __METHOD__)); } foreach ($values as $value) { // provide context to validators isValid method if (!$validator->isValid($value, $context)) { $this->abstractOptions['messages'][] = $validator->getMessages(); if ($this->isBreakOnFirstFailure()) { return false; } } } return count($this->abstractOptions['messages']) == 0; }
function getCMSFields() { $CountryCodes = CountryCodes::$iso_3166_countryCodes; $CountryCodes['Worldwide'] = 'Worldwide'; $CountryCodes['Prefer not to say'] = 'Prefer not to say'; $CountryCodes['Too many to list'] = 'Too many to list'; $fields = new FieldList($rootTab = new TabSet("Root")); $fields->addFieldsToTab('Root.Main', array(new LiteralField('Break', '<p>Each deployment profile can be marked public if you wish for the basic information on this page to appear on openstack.org. If you select private we will treat all of the profile information as confidential information.</p>'), new OptionSetField('IsPublic', 'Would you like to keep this information confidential or allow the Foundation to share information about this deployment publicly?', array('1' => '<strong>Willing to share:</strong> The information on this page may be shared for this deployment', '0' => '<strong>Confidential:</strong> All details provided should be kept confidential to the OpenStack Foundation'), 0), new LiteralField('Break', '<hr/>'), new TextField('Label', 'Deployment Name<BR><p class="clean_text">Please create a friendly label, like “Production OpenStack Deployment”. This name is for your deployment in our survey tool. If several people at your organization work on one deployment, we would <b>really appreciate</b> you all referring to the same deployment by the same name!</p>'), $ddl_stage = new DropdownField('DeploymentStage', 'In what stage is your OpenStack deployment? (make a new deployment profile for each type of deployment)', DeploymentOptions::$stage_options), new MultiDropdownField('CountriesPhysicalLocation', 'In which country / countries is this OpenStack deployment physically located?', $CountryCodes), new MultiDropdownField('CountriesUsersLocation', 'In which country / countries are the users / customers for this deployment physically located?', $CountryCodes), $ddl_type = new DropdownField('DeploymentType', 'Deployment Type', DeploymentOptions::$deployment_type_options), new CustomCheckboxSetField('ProjectsUsed', 'Projects Used', DeploymentOptions::$projects_used_options), new CustomCheckboxSetField('CurrentReleases', 'What releases are you currently using?', DeploymentOptions::$current_release_options), new LiteralField('Break', 'Describe the workloads and frameworks running in this OpenStack environment.<BR>Select All That Apply'), new LiteralField('Break', '<hr/>'), new CustomCheckboxSetField('ServicesDeploymentsWorkloads', '<b>Services Deployments - workloads designed to be accessible for external users / customers</b>', DeploymentOptions::$services_deployment_workloads_options), $other_service_workload = new TextAreaField('OtherServicesDeploymentsWorkloads', ''), new CustomCheckboxSetField('EnterpriseDeploymentsWorkloads', '<b>Enterprise Deployments - workloads designed to be run internally to support business</b>', DeploymentOptions::$enterprise_deployment_workloads_options), $other_enterprise_workload = new TextAreaField('OtherEnterpriseDeploymentsWorkloads', ''), new CustomCheckboxSetField('HorizontalWorkloadFrameworks', '<b>Horizontal Workload Frameworks</b>', DeploymentOptions::$horizontal_workload_framework_options), $other_horizontal_workload = new TextAreaField('OtherHorizontalWorkloadFrameworks', ''))); $ddl_type->setEmptyString('-- Select One --'); $ddl_stage->setEmptyString('-- Select One --'); $details = array(new LiteralField('Break', '<p>The information below will help us better understand the most common configuration and component choices OpenStack deployments are using.</p>'), new LiteralField('Break', '<h3>Telemetry</h3>'), new LiteralField('Break', '<hr/>'), new LiteralField('Break', '<p>Please provide the following information about the size and scale of this OpenStack deployment. This information is optional, but will be kept confidential and <b>never</b> published in connection with you or your organization.</p>'), new DropdownField('OperatingSystems', 'What is the main operating system running this OpenStack cloud deployment?', ArrayUtils::AlphaSort(DeploymentOptions::$operating_systems_options, array('' => '-- Select One --'), array('Other' => 'Other (please specify)'))), $other_os = new TextareaField('OtherOperatingSystems', ''), new CustomCheckboxSetField('UsedPackages', 'What packages does this deployment use…?<BR>Select All That Apply', DeploymentOptions::$used_packages_options), new CustomCheckboxSetField('CustomPackagesReason', 'If you have modified packages or have built your own packages, why?<BR>Select All That Apply', DeploymentOptions::$custom_package_reason_options), $other_custom_reason = new TextareaField('OtherCustomPackagesReason', ''), new CustomCheckboxSetField('DeploymentTools', 'What tools are you using to deploy / configure this cluster?<BR>Select All That Apply', DeploymentOptions::$deployment_tools_options), $other_deployment_tools = new TextareaField('OtherDeploymentTools', ''), new CustomCheckboxSetField('PaasTools', 'What Platform-as-a-Service (PaaS) tools are you using to manage applications on this OpenStack deployment?', ArrayUtils::AlphaSort(DeploymentOptions::$paas_tools_options, array('' => '-- Select One --'), array('Other' => 'Other Tool (please specify)'))), $other_paas = new TextareaField('OtherPaasTools', ''), new CustomCheckboxSetField('Hypervisors', 'If this deployment uses <b>OpenStack Compute (Nova)</b>, which hypervisors are you using?<BR>Select All That Apply', DeploymentOptions::$hypervisors_options), new TextareaField('OtherHypervisor', ''), new CustomCheckboxSetField('SupportedFeatures', 'Which compatibility APIs does this deployment support?<BR> Select All That Apply', DeploymentOptions::$deployment_features_options), new TextareaField('OtherSupportedFeatures', ''), new CustomCheckboxSetField('UsedDBForOpenStackComponents', 'What database do you use for the components of this OpenStack cloud?<BR>Select All That Apply', DeploymentOptions::$used_db_for_openstack_components_options), new TextareaField('OtherUsedDBForOpenStackComponents', ''), new CustomCheckboxSetField('NetworkDrivers', ' If this deployment uses <b>OpenStack Network (Neutron)</b>, which drivers are you using?<BR>Select All That Apply', DeploymentOptions::$network_driver_options), new TextareaField('OtherNetworkDriver', ''), new CustomCheckboxSetField('IdentityDrivers', 'If you are using <b>OpenStack Identity Service (Keystone)</b> which OpenStack identity drivers are you using?<BR>Select All That Apply', DeploymentOptions::$identity_driver_options), new TextareaField('OtherIndentityDriver', ''), new CustomCheckboxSetField('BlockStorageDrivers', 'If this deployment uses <b>OpenStack Block Storage (Cinder)</b>, which drivers are <BR>Select All That Apply', DeploymentOptions::$block_storage_divers_options), new TextareaField('OtherBlockStorageDriver', ''), new CustomCheckboxSetField('InteractingClouds', 'With what other clouds does this OpenStack deployment interact?<BR>Select All That Apply', DeploymentOptions::$interacting_clouds_options), new TextareaField('OtherInteractingClouds', ''), $ddl_users = new DropdownField('NumCloudUsers', 'Number of users', DeploymentOptions::$cloud_users_options), $ddl_nodes = new DropdownField('ComputeNodes', 'Physical compute nodes', DeploymentOptions::$compute_nodes_options), $ddl_cores = new DropdownField('ComputeCores', 'Processor cores', DeploymentOptions::$compute_cores_options), $ddl_instances = new DropdownField('ComputeInstances', 'Number of instances', DeploymentOptions::$compute_instances_options), $ddl_ips = new DropdownField('NetworkNumIPs', 'Number of fixed / floating IPs', DeploymentOptions::$network_ip_options), $ddl_block_size = new DropdownField('BlockStorageTotalSize', 'If this deployment uses <b>OpenStack Block Storage (Cinder)</b>, what is the size of its block storage?', DeploymentOptions::$storage_size_options), $ddl_block_size = new DropdownField('ObjectStorageSize', 'If this deployment uses <b>OpenStack Object Storage (Swift)</b>, what is the size of its block storage?', DeploymentOptions::$storage_size_options), $ddl_objects_size = new DropdownField('ObjectStorageNumObjects', 'If this deployment uses <b>OpenStack Object Storage (Swift)</b>, how many total objects are stored?', DeploymentOptions::$storage_objects_options), new LiteralField('Break', '<h3>Spotlight</h3>'), new LiteralField('Break', '<hr/>'), new CustomCheckboxSetField('WhyNovaNetwork', 'If this deployment uses nova-network and not OpenStack Network (Neutron), what would allow you to migrate to Neutron?', DeploymentOptions::$why_nova_network_options), $other_why_nova = new TextareaField('OtherWhyNovaNetwork', ''), $ddl_swift_dist_feat = new DropdownField('SwiftGlobalDistributionFeatures', 'Are you using Swift\'s global distribution features?', DeploymentOptions::$swift_global_distribution_features_options), $ddl_uses_cases = new DropdownField('SwiftGlobalDistributionFeaturesUsesCases', 'If yes, what is your use case?', DeploymentOptions::$swift_global_distribution_features_uses_cases_options), $other_uses_cases = new TextareaField('OtherSwiftGlobalDistributionFeaturesUsesCases', ''), $ddl_policies = new DropdownField('Plans2UseSwiftStoragePolicies', 'Do you have plans to use Swift\'s storage policies or erasure codes in the next year?', DeploymentOptions::$plans_2_use_swift_storage_policies_options), new TextareaField('OtherPlans2UseSwiftStoragePolicies', ''), $ddl_other_tools = new DropdownField('ToolsUsedForYourUsers', 'What tools are you using charging or show-back for your users?', DeploymentOptions::$tools_used_for_your_users_options), $other_tools = new TextareaField('OtherToolsUsedForYourUsers', ''), new TextareaField('Reason2Move2Ceilometer', 'If you are not using Ceilometer, what would allow you to move to it (optional free text)?')); $ddl_users->setEmptyString('-- Select One --'); $ddl_nodes->setEmptyString('-- Select One --'); $ddl_cores->setEmptyString('-- Select One --'); $ddl_instances->setEmptyString('-- Select One --'); $ddl_ips->setEmptyString('-- Select One --'); $ddl_block_size->setEmptyString('-- Select One --'); $ddl_block_size->setEmptyString('-- Select One --'); $ddl_objects_size->setEmptyString('-- Select One --'); $ddl_swift_dist_feat->setEmptyString('-- Select One --'); $ddl_uses_cases->setEmptyString('-- Select One --'); $ddl_policies->setEmptyString('-- Select One --'); $ddl_other_tools->setEmptyString('-- Select One --'); $fields->addFieldsToTab('Root.Details', $details); return $fields; }
/** * Create service * * @param ServiceLocatorInterface $serviceLocator * * @return mixed */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config'); if ($config instanceof Traversable) { $config = ArrayUtils::iteratorToArray($config); } return new TwitterInfoService($config['twitter']['cache_path']); }
function testIsAssociative() { $this->assertFalse(ArrayUtils::isAssociative(null)); $this->assertFalse(ArrayUtils::isAssociative(array())); $this->assertFalse(ArrayUtils::isAssociative(array(1, 2, 3))); $this->assertFalse(ArrayUtils::isAssociative(array("value", 2, false))); $this->assertTrue(ArrayUtils::isAssociative(array("key1" => "value1", "key2" => "value2"))); }
/** * Expands flat array to multi-dimensional associative array * using keys names as paths. * * @param array $flatten * * @return array */ public static function expand(array $flatten) { $nested = array(); foreach ($flatten as $path => $value) { ArrayUtils::set($nested, $path, $value); } return $nested; }
/** * Test for Schwaen\Stdlib\ArrayUtils::flatten */ public function testFlatten() { $arr1 = ['name' => 'Sven', 'Name' => 'Max']; $arr2 = ['a', [['b']], ['c'], [[[['d']]]]]; $this->assertEquals($arr1, ArrayUtils::flatten($arr1, true)); $this->assertEquals(['Sven', 'Max'], ArrayUtils::flatten($arr1, false)); $this->assertEquals(['a', 'b', 'c', 'd'], ArrayUtils::flatten($arr2)); }
static function currency_to_symbol($currency) { if (ArrayUtils::contains_key($currency, self::$currency_symbols)) { return self::$currency_symbols[$currency]; } else { throw new InvalidParameterException("Valuta non supportata!!"); } }
public static function set($key, $value) { if (!self::exists($key)) { $set = ArrayUtils::stringToNestedArray($key, $value); self::$config = ArrayUtils::merge(self::$config, $set); } return false; }
public static function require_css($css_path, $media = CSS::MEDIA_ALL) { self::init_css(); if (!ArrayUtils::has_value(self::$css_elements, $css_path)) { self::$css_elements[] = $css_path; PageData::instance()->add("/page/headers/required_css_files/css_file_list", array("path" => $css_path, "media" => $media)); } }
public static function getLists($stateIds) { $cityLists = ''; foreach ($stateIds as $stateid) { $cityLists = ArrayUtils::mergeArray($cityLists, self::getList($stateid)); } return $cityLists; }
/** * 获取版块信息 * * @param string $fids 版块信息列表 空或者0则为全部版块 * @return array */ public static function getForumInfos($fids = '') { if ($fids == '' || $fids == '0') { $fids = ForumUtils::getForumShowFids(); } else { $fids = ArrayUtils::explode($fids); } return DzForumForum::getForumInfos($fids); }
public function get_cities($source, $target, $params) { $cityDataQuery = $this->pdo->prepare("SELECT SUM(amount) as total_amount, city FROM Payments NATURAL JOIN Customers where Customers.state = :paymentState GROUP BY city;"); $cityDataQuery->execute(array('paymentState' => $params['label'])); $cityData = $cityDataQuery->fetchAll(PDO::FETCH_ASSOC); $source->clearChart(); $source->setLabels(ArrayUtils::pluck($cityData, 'city')); $source->addSeries("sales", "Sales", ArrayUtils::pluck($cityData, "total_amount"), array('numberPrefix' => "\$")); }
function launch() { // not checked below refer to testing returning results through utf8 encoding. plb 2-6-2015 $valid_json_methods = array('GetSuggestions', 'GetListTitles', 'getOverDriveSummary', 'GetPreferredBranches', 'requestPinReset', 'getCreateListForm', 'getBulkAddToListForm', 'AddList', 'getEmailMyListForm', 'sendMyListEmail', 'setListEntryPositions', 'removeTag', 'saveSearch', 'deleteSavedSearch', 'cancelHold', 'cancelHolds', 'freezeHold', 'thawHold', 'getChangeHoldLocationForm', 'changeHoldLocation', 'getReactivationDateForm', 'renewItem', 'renewAll', 'renewSelectedItems', 'getPinResetForm'); $method = $_GET['method']; if (in_array($method, $valid_json_methods)) { header('Content-type: application/json'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past $result = $this->{$method}(); try { require_once ROOT_DIR . '/sys/Utils/ArrayUtils.php'; $utf8EncodedValue = ArrayUtils::utf8EncodeArray($result); $output = json_encode($utf8EncodedValue); $error = json_last_error(); if ($error != JSON_ERROR_NONE || $output === FALSE) { if (function_exists('json_last_error_msg')) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error_msg())); } else { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error())); } global $configArray; if ($configArray['System']['debug']) { print_r($utf8EncodedValue); } } } catch (Exception $e) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => $e)); global $logger; $logger->log("Error encoding json data {$e}", PEAR_LOG_ERR); } echo $output; } elseif (in_array($method, array('LoginForm', 'getBulkAddToListForm', 'getPinUpdateForm', 'getCitationFormatsForm'))) { header('Content-type: text/html'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past echo $this->{$method}(); } else { header('Content-type: text/xml'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past $xml = '<?xml version="1.0" encoding="UTF-8"?' . ">\n" . "<AJAXResponse>\n"; if (is_callable(array($this, $_GET['method']))) { $xml .= $this->{$_GET}['method'](); } else { $xml .= '<Error>Invalid Method</Error>'; } $xml .= '</AJAXResponse>'; echo $xml; } }
public static function raw($key, $script) { self::init_javascript(); if (!ArrayUtils::has_value(self::$scripts, $key)) { self::$scripts[$key] = $script; $p = array(Block::MARKER_KEY => "head/raw_javascript", "raw_script" => $script); PageData::instance()->add("/page/headers/required_javascripts/list", $p); } }
public function multiGet($noderefs, NodePartials $nodePartials, $forceReadWrite = false, $checkJumpPermissions = false, $allowDeleted = false) { // foreach((array)$noderefs as $nodeRef) // $this->NodeEvents->fireNodeEvents('get', '', &$nodeRef); if (empty($noderefs)) { return array(); } $results = array(); $idField = 'ID'; $connectionCouplets = $this->getResolvedConnectionCouplets(is_array($noderefs) ? $noderefs : array($noderefs), $forceReadWrite); foreach ($connectionCouplets as $connectionCouplet) { $db = $connectionCouplet->getConnection(); $tableToSlugs = $connectionCouplet->getAttribute('tablesToSlugs'); foreach ($tableToSlugs as $table => $tableInfo) { extract($tableInfo); if ($checkJumpPermissions && !$this->NodePermissions->check('get', $tableNodeRef, $nodePartials, true)) { continue; } foreach (array_chunk($slugs, 1000) as $slugs) { $rows = $this->multiGetFromDB($db, $tableid, $table, $tableNodeRef, $slugs, false, $forceReadWrite, $allowDeleted); if (!empty($rows)) { $ids = ArrayUtils::arrayMultiColumn($rows, $idField); $outTags = $this->NodeTagsDAO->findOutTags($db, $tableNodeRef, $ids, $nodePartials->getOutPartials(), $forceReadWrite, $checkJumpPermissions, $nodePartials->getRestrictedOutPartials(), $nodePartials->isResolveLinks()); $inTags = $this->NodeTagsDAO->findInTags($db, $tableNodeRef, $ids, $nodePartials->getInPartials(), $forceReadWrite, $checkJumpPermissions, $nodePartials->getRestrictedInPartials(), $nodePartials->isResolveLinks()); $meta = $this->NodeMetaDAO->findMeta($db, $tableNodeRef, $ids, $nodePartials->getMetaPartials(), $forceReadWrite, $nodePartials->getRestrictedMetaPartials()); foreach ($rows as $nodeRefString => $row) { $row->setNodePartials($nodePartials); if (isset($meta[$row[$idField]])) { $row->setMetas($meta[$row[$idField]]); } if (isset($outTags[$row[$idField]])) { $row->setOutTags($outTags[$row[$idField]]); } if (isset($inTags[$row[$idField]])) { $row->setInTags($inTags[$row[$idField]]); } //$this->NodeMapper->populateNodeCheaters($row); $results[$nodeRefString] = $row; } unset($ids); unset($outTags); unset($inTags); unset($meta); } unset($rows); } unset($slugs); } unset($tableToSlugs); } unset($connectionCouplets); if (!empty($results) && !is_array($noderefs)) { return current($results); } return $results; }
public function handleArtistChartClick($source, $target, $params) { $artistName = $params['label']; $topAlbumsChart = $this->getComponentByID("c2"); $top_albums = $this->getTopAlbums($artistName); $topAlbumsChart->setCaption("Top 5 albums by " . $artistName); $topAlbumsChart->clearChart(); $topAlbumsChart->setLabels(ArrayUtils::pluck($top_albums, "Title")); $topAlbumsChart->addSeries('top_albums', "Top Albums", ArrayUtils::pluck($top_albums, "total_sales")); }
public function __construct($options = null) { // The abstract constructor allows no scalar values if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (is_array($options)) { $this->setOptions($options); } }
public function __construct($options = null) { $this->_config = new Config\Oauth2Config(); if ($options !== null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } $this->_config->setOptions($options); } }
/** * @param UncacherBaseDaoWorker $uncacher * @return UncacherBaseDaoWorker */ private function mergeSelf(UncacherBaseDaoWorker $uncacher) { foreach ($uncacher->getClassNameMap() as $className => $idKeys) { if (isset($this->classNameMap[$className])) { $this->classNameMap[$className] = ArrayUtils::mergeUnique($this->classNameMap[$className], $idKeys); } else { $this->classNameMap[$className] = $idKeys; } } return $this; }
function encode_item(&$item, &$key) { if (is_array($item)) { ArrayUtils::encode_item($item, $key); } else { if (is_string($item)) { $key = utf8_encode($key); $item = utf8_encode($item); } } }
public function RenderGrid(Grid $Grid) { $Grid->GetDataset()->Open(); $totals = array(); if ($Grid->HasTotals()) { $totalValues = $Grid->GetTotalValues(); foreach ($Grid->GetPrintColumns() as $column) { $totals[] = $column->GetTotalPresentationData(ArrayUtils::GetArrayValueDef($totalValues, $column->GetName(), null)); } } $this->doRenderGrid($Grid, PageMode::PrintAll, 'print/grid.tpl', array('Totals' => $totals)); }
function testDeleteKeys() { $data = array("ciao" => "mondo", "hello" => "world", "abla" => "espanol"); $keys = array("ciao" => "prova", "abla" => "altro"); $result = ArrayUtils::delete_keys($data, $keys); $this->assertFalse(isset($result["ciao"]), "La chiave non e' stata rimossa con successo!!"); $this->assertFalse(isset($result["abla"]), "La chiave non e' stata rimossa con successo!!"); $this->assertTrue(isset($result["hello"]), "La chiave che non doveva esser rimossa e' stata rimossa!!"); $this->assertEqual($result["hello"], "world", "Il valore rimasto non e' corretto!!"); $this->assertEqual($data["ciao"], "mondo", "L'array originale e' stato modificato!!"); $this->assertEqual($data["hello"], "world", "L'array originale e' stato modificato!!"); $this->assertEqual($data["abla"], "espanol", "L'array originale e' stato modificato!!"); }
/** * @covers MarketMeSuite\Phranken\Util\ArrayUtils::structureExists */ public function testStructureExists() { $actual = ArrayUtils::structureExists(array('user' => array('access' => '1337')), array('user' => array('access' => ''))); $this->assertSame(true, $actual); $actual = ArrayUtils::structureExists(array('user' => array('access' => '1337', 'token' => '80081322')), array('user' => array('access' => ''))); $this->assertSame(true, $actual, 'does not care about extra strucure'); $actual = ArrayUtils::structureExists(array('user' => array('access' => '1337')), array('user' => array('access' => '', 'token' => ''))); $this->assertSame(false, $actual, 'missing structure is failure'); $actual = ArrayUtils::structureExists(array(), array()); $this->assertSame(true, $actual, 'empty arrays are the same schema'); $actual = ArrayUtils::structureExists(array('user' => array('access' => array('nope' => 'nope'))), array('user' => array('access' => ''))); $this->assertSame(true, $actual, 'does not care about deeper strucures'); }