本文整理汇总了PHP中FArrayHelper::array_fill方法的典型用法代码示例。如果您正苦于以下问题:PHP FArrayHelper::array_fill方法的具体用法?PHP FArrayHelper::array_fill怎么用?PHP FArrayHelper::array_fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FArrayHelper
的用法示例。
在下文中一共展示了FArrayHelper::array_fill方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addCalculations
/**
* Add calculations
*
* @param array $a of field elements $a
* @param string &$str to out put as csv file $str
*
* @return null
*/
protected function addCalculations($a, &$str)
{
$input = $this->app->input;
if ($input->get('inccalcs') == 1) {
$incRaw = $input->get('incraw', true);
$calKeys = array('sums', 'avgs', 'medians', 'count');
foreach ($calKeys as $calKey) {
$calculations[$calKey] = FArrayHelper::array_fill(0, count($a) + 1, ' ');
$calculations[$calKey][0] = $calKey;
$calcs = $this->model->getCalculations();
foreach ($calcs[$calKey] as $key => $cal) {
$x = 0;
$found = false;
// $$$rob if grouped data and calc split then get the formatted string as $cal['calc] wont exist below
foreach ($a as $aKey => $aVal) {
if (trim($aKey) == trim($key) && $x != 0) {
$json = $calcs[$calKey][$aKey . '_obj'];
unset($json['']);
if (count($json) == 1) {
$default = $json['Total']->value;
} else {
$default = json_encode($json);
}
}
$x++;
}
$x = 0;
foreach ($a as $aKey => $aVal) {
if ($aKey == JString::substr($key, 0, JString::strlen($key) - 4) && $x != 0) {
$found = true;
break;
}
$x++;
}
if ($found) {
if (array_key_exists('calc', $cal)) {
$calculations[$calKey][$x] = $cal['calc']->value;
if ($incRaw) {
$calculations[$calKey][$x + 1] = $cal['calc']->value;
}
} else {
$calculations[$calKey][$x] = $default;
if ($incRaw) {
$calculations[$calKey][$x + 1] = $default;
}
}
}
}
$str .= implode($this->delimiter, array_map(array($this, 'quote'), $calculations[$calKey]));
$str .= "\n";
}
}
}
示例2: elementJavascript
/**
* Returns javascript which creates an instance of the class defined in formJavascriptClass()
*
* @param int $repeatCounter Repeat group counter
*
* @return array
*/
public function elementJavascript($repeatCounter)
{
$params = $this->getParams();
$id = $this->getHTMLId($repeatCounter);
FabrikHelperHTML::mcl();
$j3 = FabrikWorker::j3();
$element = $this->getElement();
$paramsKey = $this->getFullName(true, false);
$paramsKey = Fabrikstring::rtrimword($paramsKey, $this->getElement()->name);
$paramsKey .= 'params';
$formData = $this->getFormModel()->data;
$imgParams = FArrayHelper::getValue($formData, $paramsKey);
// Above paramsKey stuff looks really wonky - lets test if null and use something which seems to build the correct key
if (is_null($imgParams)) {
$paramsKey = $this->getFullName(true, false) . '___params';
$imgParams = FArrayHelper::getValue($formData, $paramsKey);
}
$value = $this->getValue(array(), $repeatCounter);
$value = is_array($value) ? $value : FabrikWorker::JSONtoData($value, true);
$value = $this->checkForSingleCropValue($value);
// Repeat_image_repeat_image___params
$rawValues = count($value) == 0 ? array() : FArrayHelper::array_fill(0, count($value), 0);
$fileData = $this->getFormModel()->data;
$rawKey = $this->getFullName(true, false) . '_raw';
$rawValues = FArrayHelper::getValue($fileData, $rawKey, $rawValues);
if (!is_array($rawValues)) {
$rawValues = explode(GROUPSPLITTER, $rawValues);
} else {
/*
* $$$ hugh - nasty hack for now, if repeat group with simple
* uploads, all raw values are in an array in $rawValues[0]
*/
if (array_key_exists(0, $rawValues) && is_array(FArrayHelper::getValue($rawValues, 0))) {
$rawValues = $rawValues[0];
}
}
if (!is_array($imgParams)) {
$imgParams = explode(GROUPSPLITTER, $imgParams);
}
$oFiles = new stdClass();
$iCounter = 0;
// Failed validation for ajax upload elements
if (is_array($value) && array_key_exists('id', $value)) {
$imgParams = array_values($value['crop']);
$value = array_keys($value['id']);
/**
* Another nasty hack for failed validations, need to massage $rawValues back into expected shape,
* as they will be keyed by filename instead of parent ID after validation fail.
*/
$newRawValues = array();
foreach ($value as $k => $v) {
$newRawValues[$k] = $rawValues['id'][$v];
}
$rawValues = $newRawValues;
}
for ($x = 0; $x < count($value); $x++) {
if (is_array($value)) {
if (array_key_exists($x, $value) && $value[$x] !== '') {
if (is_array($value[$x])) {
// From failed validation
foreach ($value[$x]['id'] as $tKey => $parts) {
$o = new stdClass();
$o->id = 'alreadyuploaded_' . $element->id . '_' . $iCounter;
$o->name = array_pop(explode(DIRECTORY_SEPARATOR, $tKey));
$o->path = $tKey;
if ($fileInfo = $this->getStorage()->getFileInfo($o->path)) {
$o->size = $fileInfo['filesize'];
} else {
$o->size = 'unknown';
}
$o->type = strstr($fileInfo['mime_type'], 'image/') ? 'image' : 'file';
$o->url = $this->getStorage()->pathToURL($tKey);
$o->recordid = $rawValues[$x];
$o->params = json_decode($value[$x]['crop'][$tKey]);
$oFiles->{$iCounter} = $o;
$iCounter++;
}
} else {
if (is_object($value[$x])) {
// Single crop image (not sure about the 0 settings in here)
$parts = explode(DIRECTORY_SEPARATOR, $value[$x]->file);
$o = new stdClass();
$o->id = 'alreadyuploaded_' . $element->id . '_0';
$o->name = array_pop($parts);
$o->path = $value[$x]->file;
if ($fileInfo = $this->getStorage()->getFileInfo($o->path)) {
$o->size = $fileInfo['filesize'];
} else {
$o->size = 'unknown';
}
$o->type = strstr($fileInfo['mime_type'], 'image/') ? 'image' : 'file';
$o->url = $this->getStorage()->pathToURL($value[$x]->file);
$o->recordid = 0;
//.........这里部分代码省略.........
示例3: prefilterSetting
/**
* Get the prefilter settings from list/module/menu options
* Use in listModel::getPrefilterArray() and formModel::getElementIds()
*
* @return multitype:array
*/
public function prefilterSetting()
{
$params = $this->getParams();
$properties = $this->menuModulePrefilters();
// List pre-filter properties
$listFields = (array) $params->get('filter-fields');
$listConditions = (array) $params->get('filter-conditions');
$listValue = (array) $params->get('filter-value');
$listAccess = (array) $params->get('filter-access');
$listEval = (array) $params->get('filter-eval');
$listJoins = (array) $params->get('filter-join');
$listGrouped = (array) $params->get('filter-grouped');
$listSearchType = FArrayHelper::array_fill(0, count($listJoins), 'prefilter');
/* If we are rendering as a module don't pick up the menu item options (params already set in list module)
* so first statement when rendering a module, 2nd when posting to the component from a module.
*/
if ($properties !== '') {
$prefilters = ArrayHelper::fromObject(json_decode($properties));
$conditions = (array) $prefilters['filter-conditions'];
if (!empty($conditions)) {
$fields = FArrayHelper::getValue($prefilters, 'filter-fields', array());
$conditions = FArrayHelper::getValue($prefilters, 'filter-conditions', array());
$values = FArrayHelper::getValue($prefilters, 'filter-value', array());
$access = FArrayHelper::getValue($prefilters, 'filter-access', array());
$eval = FArrayHelper::getValue($prefilters, 'filter-eval', array());
$joins = FArrayHelper::getValue($prefilters, 'filter-join', array());
$searchType = FArrayHelper::array_fill(0, count($joins), 'menuPrefilter');
$overrideListPrefilters = $params->get('menu_module_prefilters_override', true);
if ($overrideListPrefilters) {
// Original behavior
$listFields = $fields;
$listConditions = $conditions;
$listValue = $values;
$listAccess = $access;
$listEval = $eval;
$listJoins = $joins;
$listSearchType = $searchType;
} else {
// Preferred behavior but for backwards compat we need to ask users to
// set this option in the menu/module settings
$joins[0] = 'AND';
$listFields = array_merge($listFields, $fields);
$listConditions = array_merge($listConditions, $conditions);
$listValue = array_merge($listValue, $values);
$listAccess = array_merge($listAccess, $access);
$listEval = array_merge($listEval, $eval);
$listSearchType = array_merge($listSearchType, $searchType);
//$listGrouped[count($listGrouped) -1] = '1';
$listJoins = array_merge($listJoins, $joins);
$listGrouped = array_merge($listGrouped, FArrayHelper::array_fill(0, count($joins), 0));
}
}
}
return array($listFields, $listConditions, $listValue, $listAccess, $listEval, $listJoins, $listGrouped, $listSearchType);
}
示例4: onFinalStoreRow
/**
* Called at end of form record save. Used for many-many join elements to save their data
*
* @param array &$data Form data
*
* @since 3.1rc1
*
* @return void
*/
public function onFinalStoreRow(&$data)
{
if (!$this->isJoin()) {
return;
}
$groupModel = $this->getGroupModel();
$listModel = $this->getListModel();
$db = $listModel->getDb();
$query = $db->getQuery(true);
$formData =& $this->getFormModel()->formDataWithTableName;
// I set this to raw for cdd.
$name = $this->getFullName(true, false);
$ajaxSubmit = $this->app->input->get('fabrik_ajax');
$rawName = $name . '_raw';
$shortName = $this->getElement()->name;
$join = $this->getJoin();
// The submitted element's values
$d = FArrayHelper::getValue($formData, $rawName, FArrayHelper::getValue($formData, $name));
// set $emptyish to false so if no selection, we don't save a bogus empty row
$allJoinValues = FabrikWorker::JSONtoData($d, true, false);
if ($groupModel->isJoin()) {
$groupJoinModel = $groupModel->getJoinModel();
$k = str_replace('`', '', str_replace('.', '___', $groupJoinModel->getJoin()->params->get('pk')));
$parentIds = (array) $formData[$k];
} else {
$k = 'rowid';
$parentIds = empty($allJoinValues) ? array() : FArrayHelper::array_fill(0, count($allJoinValues), $formData[$k]);
}
$paramsKey = $this->getJoinParamsKey();
$allParams = (array) FArrayHelper::getValue($formData, $paramsKey, array());
$allParams = array_values($allParams);
$i = 0;
$idsToKeep = array();
foreach ($parentIds as $parentId) {
if (!array_key_exists($parentId, $idsToKeep)) {
$idsToKeep[$parentId] = array();
}
if ($groupModel->canRepeat()) {
$joinValues = FArrayHelper::getValue($allJoinValues, $i, array());
} else {
$joinValues = $allJoinValues;
}
$joinValues = (array) $joinValues;
// Get existing records
if ($parentId == '') {
$ids = array();
} else {
$query->clear();
$query->select('id, ' . $shortName)->from($join->table_join)->where('parent_id = ' . $parentId);
$db->setQuery($query);
$ids = (array) $db->loadObjectList($shortName);
}
// If doing an ajax form submit and the element is an ajax file upload then its data is different.
if (get_class($this) === 'PlgFabrik_ElementFileupload' && $ajaxSubmit) {
$allParams = array_key_exists('crop', $joinValues) ? array_values($joinValues['crop']) : array();
$joinValues = array_key_exists('id', $joinValues) ? array_keys($joinValues['id']) : $joinValues;
}
foreach ($joinValues as $jIndex => $jid) {
$record = new stdClass();
$record->parent_id = $parentId;
$fkVal = FArrayHelper::getValue($joinValues, $jIndex);
$record->{$shortName} = $fkVal;
$record->params = FArrayHelper::getValue($allParams, $jIndex);
// Stop notice with file-upload where fkVal is an array
if (array_key_exists($fkVal, $ids)) {
$record->id = $ids[$fkVal]->id;
$idsToKeep[$parentId][] = $record->id;
} else {
$record->id = 0;
}
if ($record->id == 0) {
$ok = $listModel->insertObject($join->table_join, $record);
$lastInsertId = $listModel->getDb()->insertid();
if (!$this->allowDuplicates) {
$newId = new stdClass();
$newId->id = $lastInsertId;
$newId->{$shortName} = $record->{$shortName};
$ids[$record->{$shortName}] = $newId;
}
$idsToKeep[$parentId][] = $lastInsertId;
} else {
$ok = $listModel->updateObject($join->table_join, $record, 'id');
}
if (!$ok) {
throw new RuntimeException('Didn\'t save dbjoined repeat element');
}
}
$i++;
}
// Delete any records that were unselected.
$this->deleteDeselectedItems($idsToKeep, $k);
//.........这里部分代码省略.........