本文整理汇总了PHP中Utils::rekey方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::rekey方法的具体用法?PHP Utils::rekey怎么用?PHP Utils::rekey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils
的用法示例。
在下文中一共展示了Utils::rekey方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listAction
/**
* Get list of items. Returns JSON reply with
* ORM object field data;
* Filtering, pagination and search are available
* Sends JSON reply in the result
* and closes the application.
*/
public function listAction()
{
$pager = Request::post('pager', 'array', array());
$filter = Request::post('filter', 'array', array());
$query = Request::post('search', 'string', false);
$filter = array_merge($filter, Request::extFilters());
$dataModel = Model::factory($this->_objectName);
if (isset($filter['date']) && !empty($filter['date'])) {
$date = date('Y-m-d', strtotime($filter['date']));
$filter['date'] = new Db_Select_Filter('date', array($date . ' 00:00:00', $date . ' 23:59:59'), Db_Select_Filter::BETWEEN);
}
$data = $dataModel->getListVc($pager, $filter, $query, $this->_listFields);
if (empty($data)) {
Response::jsonSuccess(array(), array('count' => 0));
}
$userIds = Utils::fetchCol('user_id', $data);
$userData = array();
if (!empty($userIds)) {
$userData = Model::factory('User')->getList(false, array('id' => $userIds), array('id', 'name'));
if (!empty($userData)) {
$userData = Utils::rekey('id', $userData);
}
foreach ($data as $k => &$v) {
if (isset($userData[$v['user_id']])) {
$v['user_name'] = $userData[$v['user_id']]['name'];
} else {
$v['user_name'] = '';
}
}
}
unset($v);
Response::jsonSuccess($data, array('count' => $dataModel->getCount($filter, $query)));
}
示例2: _addUrls
protected function _addUrls(&$menuItems)
{
$codes = Model::factory('Page')->getCachedCodes();
$resourceIds = array();
$resourcesData = array();
foreach ($menuItems as $k => &$v) {
if (isset($codes[$v['page_id']])) {
$v['page_code'] = $codes[$v['page_id']];
} else {
$v['page_code'] = '';
}
if ($v['link_type'] === 'resource') {
$resourceIds[] = $v['resource_id'];
}
}
unset($v);
if (!empty($resourceIds)) {
$resourceIds = array_unique($resourceIds);
$data = Model::factory('Medialib')->getItems($resourceIds, array('id', 'path'));
if (!empty($data)) {
$resourcesData = Utils::rekey('id', $data);
}
}
foreach ($menuItems as $k => &$v) {
$v['link_url'] = '';
switch ($v['link_type']) {
case 'page':
$v['link_url'] = Request::url(array($v['page_code']));
break;
case 'url':
$v['link_url'] = $v['url'];
break;
case 'resource':
if (isset($resourcesData[$v['resource_id']])) {
$v['link_url'] = Model_Medialib::addWebRoot($resourcesData[$v['resource_id']]['path']);
}
break;
}
}
unset($v);
}
示例3: permissionsAction
/**
* List permissions action
*/
public function permissionsAction()
{
$user = Request::post('user_id', 'int', 0);
$group = Request::post('group_id', 'int', 0);
if ($user && $group) {
Response::jsonError($this->_lang->WRONG_REQUEST);
}
if ($group) {
$data = Model::factory('acl_simple')->getGroupPermissions($group);
}
if (!empty($data)) {
$data = Utils::rekey('object', $data);
}
$manager = new Db_Object_Manager();
$objects = $manager->getRegisteredObjects();
foreach ($objects as $name) {
if (!isset($data[$name])) {
$data[$name] = array('object' => $name, 'create' => false, 'view' => false, 'edit' => false, 'delete' => false, 'user_id' => null, 'publish' => false, 'group_id' => $group);
}
}
foreach ($data as $k => &$v) {
if (!Db_Object_Config::configExists($k)) {
unset($data[$k]);
continue;
}
$cfg = Db_Object_Config::getInstance($k);
if ($cfg->isRevControl()) {
$v['rc'] = true;
} else {
$v['rc'] = false;
}
$v['title'] = $cfg->getTitle();
}
unset($v);
Response::jsonSuccess(array_values($data));
}
示例4: updateGroupPermissions
/**
* Update group permissions
* @param integer $groupId
* @param array $data - permissions like array(
* array(
* 'object'=>'object',
* 'view'=>true,
* 'create'=>false,
* 'edit'=>false,
* 'delete'=>false,
* 'publish'=>false
* ),
* ...
* )
* @return boolean
*/
public function updateGroupPermissions($groupId, array $data)
{
$groupPermissions = $this->getList(false, array('group_id' => $groupId, 'user_id' => null));
$sorted = Utils::rekey('object', $groupPermissions);
$modulesToRemove = array();
if (!empty($sorted)) {
$modulesToRemove = array_diff(array_keys($sorted), Utils::fetchCol('object', $data));
}
if (!empty($modulesToRemove)) {
$this->_db->delete($this->table(), '`object` IN (\'' . implode("','", $modulesToRemove) . '\') AND `group_id`=' . intval($groupId));
}
$errors = false;
foreach ($data as $values) {
if (empty($values)) {
return false;
}
/**
* Check if all needed fields are present
*/
$diff = array_diff(self::$_fields, array_keys($values));
if (!empty($diff)) {
continue;
}
try {
if (isset($sorted[$values['object']])) {
$obj = new Db_Object($this->_name, $sorted[$values['object']][$this->_objectConfig->getPrimaryKey()]);
$obj->setValues(array('view' => (bool) $values['view'], 'create' => (bool) $values['create'], 'edit' => (bool) $values['edit'], 'delete' => (bool) $values['delete'], 'publish' => (bool) $values['publish']));
} else {
$obj = new Db_Object($this->_name);
$obj->setValues(array('view' => (bool) $values['view'], 'create' => (bool) $values['create'], 'edit' => (bool) $values['edit'], 'delete' => (bool) $values['delete'], 'publish' => (bool) $values['publish'], 'object' => $values['object'], 'group_id' => $groupId, 'user_id' => null));
}
if (!$obj->save()) {
$errors = true;
}
} catch (Exception $e) {
$this->logError($e->getMessage());
$errors = true;
}
}
if ($errors) {
return false;
} else {
return true;
}
}
示例5: _collectBlockLinksData
/**
* Prepear data for linked field component
* @param array $data
* @return array
*/
protected function _collectBlockLinksData(array $data)
{
$ids = Utils::fetchCol('id', $data);
$data = Utils::rekey('id', $data);
$obj = new Db_Object('Blocks');
$model = Model::factory('Blocks');
$fields = array('id', 'title' => $obj->getConfig()->getLinkTitle(), 'is_system');
$usedRC = $obj->getConfig()->isRevControl();
if ($usedRC) {
$fields[] = 'published';
}
$odata = $model->getItems($ids, $fields);
if (!empty($data)) {
$odata = Utils::rekey('id', $odata);
}
/*
* Find out deleted records
*/
$deleted = array_diff($ids, array_keys($odata));
$result = array();
foreach ($ids as $id) {
if (in_array($id, $deleted)) {
$title = '';
if (isset($data[$id]['title'])) {
$title = $data[$id]['title'];
}
$item = array('id' => $id, 'deleted' => 1, 'title' => $title, 'published' => 1, 'is_system' => 0);
if ($usedRC) {
$item['published'] = 0;
}
} else {
$item = array('id' => $id, 'deleted' => 0, 'title' => $odata[$id]['title'], 'published' => 1, 'is_system' => $odata[$id]['is_system']);
if ($usedRC) {
$item['published'] = $odata[$id]['published'];
}
}
$result[] = $item;
}
return $result;
}
示例6: prepareKeysUpdate
public function prepareKeysUpdate($dropOnly = false)
{
$updates = array();
$curTable = $this->_model->table();
/*
* Get foreign keys form ORM
*/
$configForeignKeys = $this->getOrmForeignKeys();
/*
* Get foreign keys form database table
*/
$realKeys = $this->getForeignKeys($this->_model->table());
$realKeysNames = array();
if (!empty($realKeys)) {
$realKeys = Utils::rekey('CONSTRAINT_NAME', $realKeys);
}
if (!empty($configForeignKeys)) {
foreach ($configForeignKeys as $keyName => $item) {
$realKeysNames[] = $keyName;
if (!isset($realKeys[$keyName]) && !$dropOnly) {
$updates[] = array('name' => $keyName, 'action' => 'add', 'config' => $item);
}
}
}
if (!empty($realKeys)) {
foreach ($realKeys as $name => $config) {
if (!in_array($name, $realKeysNames, true)) {
$updates[] = array('name' => $name, 'action' => 'drop');
}
}
}
return $updates;
}
示例7: _collectLinksData
/**
* Get ready the data for fields of the ‘link to object list’ type;
* Takes an array of identifiers as a parameter. expands the data adding object name,
* status (deleted or not deleted), publication status for objects under
* version control (used in child classes)
* The provided data is necessary for the RelatedGridPanel component,
* which is used for visual representation of relationship management.
* @param array $data
* @param string $objectName
* @return array
*/
protected function _collectLinksData(array $data, $objectName)
{
$ids = Utils::fetchCol('id', $data);
$data = Utils::rekey('id', $data);
$objectConfig = Db_Object_Config::getInstance($objectName);
$model = Model::factory(ucfirst($objectName));
try {
$objectsList = Db_Object::factory(ucfirst($objectName), $ids);
} catch (Exception $e) {
$objectsList = array();
}
/*
* Find out deleted records
*/
if (empty($objectsList)) {
$deleted = $ids;
} else {
$deleted = array_diff($ids, array_keys($objectsList));
}
$useVc = $objectConfig->isRevControl();
$result = array();
foreach ($ids as $id) {
if (in_array($id, $deleted)) {
$item = array('id' => $id, 'deleted' => 1, 'title' => $data[$id]['title'], 'published' => 1);
if ($useVc) {
$item['published'] = 0;
}
} else {
$object = $objectsList[$id];
$item = array('id' => $id, 'deleted' => 0, 'title' => $object->getTitle(), 'published' => 1);
if ($useVc) {
$item['published'] = $object->get('published');
}
}
$result[] = $item;
}
return $result;
}
示例8: _getListVcRemote
protected function _getListVcRemote($params = false, $filters = false, $query = false, $fields = '*', $author = false, $lastEditor = false, $joins = false)
{
if ($fields !== '*') {
if ($author) {
if (!in_array('author_id', $fields, true)) {
$fields[] = 'author_id';
}
}
if ($lastEditor) {
if (!in_array('editor_id', $fields, true)) {
$fields[] = 'editor_id';
}
}
}
$sql = $this->_dbSlave->select()->from($this->table(), $fields);
if ($filters) {
$this->queryAddFilters($sql, $filters);
}
if ($query && strlen($query)) {
$this->_queryAddQuery($sql, $query);
}
if ($params) {
static::queryAddPagerParams($sql, $params);
}
if (is_array($joins) && !empty($joins)) {
$this->_queryAddJoins($sql, $joins);
}
$data = $this->_dbSlave->fetchAll($sql);
if (!$author && !$lastEditor) {
return $data;
}
$ids = array();
foreach ($data as $row) {
if ($author) {
$ids[] = $row['author_id'];
}
if ($lastEditor) {
$ids[] = $row['editor_id'];
}
}
if (!empty($ids)) {
array_unique($ids);
$usersData = Model::factory('User')->getList(false, array('id' => $ids), array('id', 'name'));
if (!empty($usersData)) {
$usersData = Utils::rekey('id', $usersData);
}
}
foreach ($data as $key => &$row) {
if ($author) {
if (isset($usersData[$row['author_id']])) {
$row[$author] = $usersData[$row['author_id']]['name'];
} else {
$row[$author] = '';
}
}
if ($lastEditor) {
if (isset($usersData[$row['editor_id']])) {
$row[$lastEditor] = $usersData[$row['editor_id']]['name'];
} else {
$row[$lastEditor] = '';
}
}
}
return $data;
}
示例9: exportcsvAction
/**
* Load CSV file
*/
public function exportcsvAction()
{
$this->_checkLoaded();
$query = $this->_session->get('query');
/**
* @var Db_Select
*/
$sql = $query->getSql();
$data = $this->_db->fetchAll($sql);
$fieldsCfg = $query->getSelectedColumns();
$titles = Utils::fetchCol('title', Utils::rekey('name', $fieldsCfg));
$data = array_merge(array($titles), $data);
$csv = Export::factory(Export::CSV, 'Export_Layout_Table_Csv', $data);
$csv->setFileName('Report');
$csv->stream();
}
示例10: find
/**
* @param $query
* @param $version
* @return array
*/
public function find($query, $version)
{
$classModel = Model::factory('sysdocs_class');
$methodModel = Model::factory('sysdocs_class_method');
$fileModel = Model::factory('sysdocs_file');
$result = $classModel->getList(array('start' => 0, 'limit' => $this->searchLimit, 'sort' => 'name', 'dir' => 'ASC'), array(new Db_Select_Filter('name', $query . '%', Db_Select_Filter::LIKE), 'vers' => $version), array('id', 'name', 'fileId'));
if (!empty($result)) {
foreach ($result as &$v) {
$v['itemType'] = 'class';
$v['classId'] = $v['id'];
$v['id'] = 'c' . $v['id'];
$v['title'] = $v['name'];
$v['methodId'] = 0;
}
unset($v);
}
if (count($result) < $this->searchLimit) {
$methodData = $methodModel->getList(array('start' => 0, 'limit' => $this->searchLimit - count($result), 'sort' => 'name', 'dir' => 'ASC'), array(new Db_Select_Filter('name', $query . '%', Db_Select_Filter::LIKE), 'vers' => $version), array('id', 'name', 'classId'));
if (!empty($methodData)) {
$classes = Utils::fetchCol('classId', $methodData);
$classes = $classModel->getList(false, array('id' => $classes), array('id', 'name', 'fileId'));
if (!empty($classes)) {
$classes = Utils::rekey('id', $classes);
}
foreach ($methodData as $k => &$v) {
if (!isset($classes[$v['classId']])) {
unset($methodData[$k]);
continue;
}
$v['methodId'] = $v['id'];
$v['id'] = 'm' . $v['id'];
$v['title'] = $classes[$v['classId']]['name'] . '::' . $v['name'];
$v['itemType'] = 'method';
$v['fileId'] = $classes[$v['classId']]['fileId'];
}
unset($v);
if (!empty($methodData)) {
$result = array_merge($result, $methodData);
}
}
}
if (empty($result)) {
return array();
}
$fileIds = Utils::fetchCol('fileId', $result);
$files = $fileModel->getList(false, array('id' => $fileIds), array('path', 'name', 'id', 'hid'));
if (!empty($files)) {
$files = Utils::rekey('id', $files);
foreach ($result as $k => &$v) {
if (!isset($files[$v['fileId']])) {
unset($result[$k]);
continue;
}
$v['id'] = $k;
$v['fname'] = $files[$v['fileId']]['name'];
$v['path'] = $files[$v['fileId']]['path'];
$v['hid'] = $files[$v['fileId']]['hid'];
unset($v['file_id']);
}
unset($v);
}
return $result;
}
示例11: testRekey
public function testRekey()
{
$data = array(array('id' => 11, 'text' => 1), array('id' => 12, 'text' => 2), array('id' => 13, 'text' => 3));
$result = Utils::rekey('id', $data);
$this->assertEquals(array(11 => array('id' => 11, 'text' => 1), 12 => array('id' => 12, 'text' => 2), 13 => array('id' => 13, 'text' => 3)), $result);
}
示例12: getClassMethods
/**
* Get class methods info by class id
* @param integer $classId
* @param string $lanuage
* @return array
*/
public function getClassMethods($classId, $language)
{
$propModel = Model::factory('sysdocs_class_method');
$list = $propModel->getList(array('sort' => 'name', 'dir' => 'ASC'), array('classId' => $classId), array('id', 'name', 'deprecated', 'description', 'inherited', 'throws', 'static', 'abstract', 'visibility', 'returnType', 'returnsReference', 'hid', 'final'));
if (empty($list)) {
$list = array();
}
$list = Utils::rekey('id', $list);
foreach ($list as $k => &$v) {
/**
* @todo Optimize slow operation
* recursive queries!
*/
$desc = $this->findLocale('sysdocs_class_method', 'description', $language, $list[$k]['hid']);
if (empty($desc)) {
$desc = nl2br($list[$k]['description']);
}
$list[$k]['description'] = $desc;
$list[$k]['object_id'] = $list[$k]['id'];
}
unset($v);
$params = Model::factory('sysdocs_class_method_param')->getList(array('sort' => 'index', 'order' => 'DESC'), array('methodId' => array_keys($list)), array('methodId', 'name', 'default', 'isRef', 'description', 'optional', 'id'));
$params = Utils::groupByKey('methodId', $params);
foreach ($list as $id => &$data) {
if (isset($params[$data['id']])) {
$data['params'] = $params[$data['id']];
$pList = Utils::fetchCol('name', $params[$data['id']]);
foreach ($pList as &$prop) {
$prop = '$' . $prop;
}
unset($prop);
$data['paramsList'] = implode(', ', $pList);
} else {
$data['params'] = array();
$data['paramsList'] = '';
}
}
unset($data);
return array_values($list);
}
示例13: extractBlocks
/**
* Get blocks map from object vesrion
*
* @param integer $pageId
* @param integer $version
* @return array
*/
public function extractBlocks($pageId, $version)
{
$vcModel = Model::factory('Vc');
$data = $vcModel->getData('page', $pageId, $version);
if (!isset($data['blocks']) || empty($data['blocks'])) {
return array();
}
$data = unserialize($data['blocks']);
if (empty($data)) {
return array();
}
$ids = array();
$info = array();
foreach ($data as $place => $items) {
if (!empty($items)) {
foreach ($items as $index => $config) {
$ids[] = $config['id'];
}
$sql = $this->_dbSlave->select()->from($this->table())->where('`id` IN(' . Model::listIntegers($ids) . ')');
$info = $this->_dbSlave->fetchAll($sql);
}
}
if (!empty($info)) {
$info = Utils::rekey('id', $info);
}
foreach ($data as $place => $items) {
if (!empty($items)) {
foreach ($items as $index => $config) {
if (isset($info[$config['id']])) {
$data[$place][$index] = $info[$config['id']];
$data[$place][$index]['place'] = $place;
}
}
}
}
return $data;
}