本文整理汇总了PHP中Utils::fetchCol方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::fetchCol方法的具体用法?PHP Utils::fetchCol怎么用?PHP Utils::fetchCol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils
的用法示例。
在下文中一共展示了Utils::fetchCol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: run
/**
* (non-PHPdoc)
* @see Bgtask_Abstract::run()
*/
public function run()
{
$object = $this->_config['object'];
$container = $this->_config['session_container'];
/*
* Save task ID into session for UI
*/
$session = Store_Session::getInstance();
$session->set($container, $this->_pid);
$this->goBackground();
$objectConfig = Db_Object_Config::getInstance($object);
$ivField = $objectConfig->getIvField();
$primaryKey = $objectConfig->getPrimaryKey();
if (!$objectConfig->hasEncrypted()) {
$this->finish();
}
$filter = array($ivField => new Db_Select_Filter($ivField, false, Db_Select_Filter::NOT_NULL));
$model = Model::factory($object);
$count = Model::factory($object)->getCount($filter);
$this->setTotalCount($count);
if (!$count) {
$this->finish();
}
$data = $model->getList(array('limit' => $this->buckedSize), $filter, array($primaryKey));
$encryptedFields = $objectConfig->getEncryptedFields();
while (!empty($data)) {
$ids = Utils::fetchCol($primaryKey, $data);
$objectList = Db_Object::factory($object, $ids);
$count = 0;
foreach ($objectList as $dataObject) {
$data = array();
foreach ($encryptedFields as $name) {
$data[$name] = $dataObject->get($name);
$model->logError($dataObject->getId() . ' ' . $name . ': ' . $data[$name]);
}
$data[$ivField] = null;
try {
$model->getDbConnection()->update($model->table(), $data, $primaryKey . ' = ' . $dataObject->getId());
$count++;
} catch (Exception $e) {
$errorText = 'Cannot decrypt ' . $dataObject->getName() . ' ' . $dataObject->getId() . ' ' . $e->getMessage();
$model->logError($errorText);
$this->error($errorText);
}
}
/*
* Update task status and check for signals
*/
$this->incrementCompleted($count);
$this->updateState();
$this->processSignals();
$data = $model->getList(array('limit' => $this->buckedSize), $filter, array($primaryKey));
}
$this->finish();
}
示例3: run
/**
* (non-PHPdoc)
* @see Bgtask_Abstract::run()
*/
public function run()
{
$object = $this->_config['object'];
$container = $this->_config['session_container'];
/*
* Save task ID into session for UI
*/
$session = Store_Session::getInstance();
$session->set($container, $this->_pid);
$this->goBackground();
$objectConfig = Db_Object_Config::getInstance($object);
$ivField = $objectConfig->getIvField();
$primaryKey = $objectConfig->getPrimaryKey();
$model = Model::factory($object);
$count = Model::factory($object)->getCount(array($ivField => null));
$this->setTotalCount($count);
if (!$count) {
$this->finish();
}
$ignore = array();
$data = $model->getList(array('limit' => $this->buckedSize), array($ivField => null), array($primaryKey));
while (!empty($data)) {
$ids = Utils::fetchCol($primaryKey, $data);
$objectList = Db_Object::factory($object, $ids);
$count = 0;
foreach ($objectList as $dataObject) {
if (!$dataObject->save()) {
$ignore[] = $dataObject->getId();
$this->log('Cannot encrypt ' . $dataObject->getName() . ' ' . $dataObject->getId());
} else {
$count++;
}
}
/*
* Update task status and check for signals
*/
$this->incrementCompleted($count);
$this->updateState();
$this->processSignals();
if (!empty($ignore)) {
$filters = array($ivField => null, $primaryKey => new Db_Select_Filter($primaryKey, $ignore, Db_Select_Filter::NOT_IN));
} else {
$filters = array($ivField => null);
}
$data = $model->getList(array('limit' => $this->buckedSize), $filters, array($primaryKey));
}
$this->finish();
}
示例4: listAction
/**
* (non-PHPdoc)
* @see Backend_Controller_Crud::listAction()
*/
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);
$vc = Model::factory('vc');
$data = $dataModel->getListVc($pager, $filter, $query, $this->_listFields, 'user', 'updater');
if (empty($data)) {
Response::jsonSuccess(array(), array('count' => 0));
}
$ids = Utils::fetchCol('id', $data);
$maxRevisions = $vc->getLastVersion($this->_objectName, $ids);
foreach ($data as $k => &$v) {
if (isset($maxRevisions[$v['id']])) {
$v['last_version'] = $maxRevisions[$v['id']];
} else {
$v['last_version'] = 0;
}
}
Response::jsonSuccess($data, array('count' => $dataModel->getCount($filter, $query)));
}
示例5: defaultblockssaveAction
/**
* Save default blockmap
*/
public function defaultblockssaveAction()
{
$this->_checkCanEdit();
$data = Request::post('blocks', 'raw', '');
if (strlen($data)) {
$data = json_decode($data, true);
} else {
$data = array();
}
$blockMapping = Model::factory('Blockmapping');
$blockMapping->clearMap(0);
if (!empty($data)) {
foreach ($data as $place => $items) {
$blockMapping->addBlocks(0, $place, Utils::fetchCol('id', $items));
}
}
$blockManager = new Blockmanager();
$blockManager->invalidateDefaultMap();
Response::jsonSuccess();
}
示例6: 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;
}
示例7: getPagesWithDefaultMap
/**
* Get id's of page with default blocks map
* @return array:
*/
public function getPagesWithDefaultMap()
{
$ids = $this->getList(false, array('default_blocks' => 1), array('id'));
if (!empty($ids)) {
return Utils::fetchCol('id', $ids);
} else {
return array();
}
}
示例8: objectExists
/**
* Check if the listed objects exist
* @param string $name
* @param mixed integer/array $ids
* @return boolean
*/
public static function objectExists($name, $ids)
{
if (!Db_Object_Config::configExists($name)) {
return false;
}
try {
$cfg = Db_Object_Config::getInstance($name);
} catch (Exception $e) {
return false;
}
if (!is_array($ids)) {
$ids = array($ids);
}
$model = Model::factory($name);
$data = $model->getItems($ids);
if (empty($data)) {
return false;
}
$data = Utils::fetchCol($cfg->getPrimaryKey(), $data);
foreach ($ids as $v) {
if (!in_array(intval($v), $data, true)) {
return false;
}
}
return true;
}
示例9: 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);
}
示例10: linkedlistAction
/**
* Get list of objects which can be linked
*/
public function linkedlistAction()
{
$object = Request::post('object', 'string', false);
$pager = Request::post('pager', 'array', array());
$query = Request::post('search', 'string', false);
if ($object === false || !Db_Object_Config::configExists($object)) {
Response::jsonError($this->_lang->WRONG_REQUEST);
}
if (!in_array(strtolower($object), $this->_canViewObjects, true)) {
Response::jsonError($this->_lang->CANT_VIEW);
}
$objectCfg = Db_Object_Config::getInstance($object);
$primaryKey = $objectCfg->getPrimaryKey();
$objectConfig = Db_Object_Config::getInstance($object);
// Check ACL permissions
$acl = $objectConfig->getAcl();
if ($acl) {
if (!$acl->can(Db_Object_Acl::ACCESS_VIEW, $object)) {
Response::jsonError($this->_lang->get('ACL_ACCESS_DENIED'));
}
}
/**
* @var Model
*/
$model = Model::factory($object);
$rc = $objectCfg->isRevControl();
if ($objectCfg->isRevControl()) {
$fields = array('id' => $primaryKey, 'published');
} else {
$fields = array('id' => $primaryKey);
}
$count = $model->getCount(false, $query, false);
$data = array();
if ($count) {
$data = $model->getList($pager, false, $fields, false, $query);
if (!empty($data)) {
$objectIds = Utils::fetchCol($primaryKey, $data);
try {
$objects = Db_Object::factory($object, $objectIds);
} catch (Exception $e) {
Model::factory($object)->logError('linkedlistAction ->' . $e->getMessage());
Response::jsonError($this->_lang->get('CANT_EXEC'));
}
foreach ($data as &$item) {
if (!$rc) {
$item['published'] = true;
}
$item['deleted'] = false;
if (isset($objects[$item[$primaryKey]])) {
$o = $objects[$item[$primaryKey]];
$item['title'] = $o->getTitle();
} else {
$item['title'] = $item['id'];
}
}
unset($item);
}
}
Response::jsonSuccess($data, array('count' => $count));
}
示例11: migrateRecords
/**
* Copy previous class localization
* @param integer $version
* @param string $lang
* @throws Exception
*/
public function migrateRecords($objectClass, $version, $lang, $fields)
{
$model = Model::factory($objectClass);
$list = $model->getList(false, array('vers' => $version), array('id'));
$locModel = Model::factory('sysdocs_localization');
$locModel->getDbConnection()->delete($locModel->table(), ' lang="' . $lang . '" AND vers="' . $version . '" AND object_class="' . $objectClass . '"');
$list = Utils::fetchCol('id', $list);
$chunks = array_chunk($list, 300);
foreach ($chunks as $items) {
$newItems = array();
$list = $model->getList(false, array('vers' => $version, 'id' => $items));
foreach ($list as $item) {
foreach ($fields as $fieldName) {
$loc = $this->findLocale($objectClass, $fieldName, $lang, $item['hid']);
if ($loc === false) {
continue;
}
$loc = trim($loc);
if (!strlen($loc)) {
continue;
}
$item = array('field' => $fieldName, 'hid' => $item['hid'], 'lang' => $lang, 'object_class' => $objectClass, 'object_id' => $item['id'], 'value' => $loc, 'vers' => $this->vers);
/*
* Multi Insert can cause PHP segfault if mysql max_allowed_packet is to small
*/
// uncomment this to use multi insert
//$newItems[] = $item;
// comment this to use multi insert
if (!Model::factory('sysdocs_localization')->getDbConnection()->insert(Model::factory('sysdocs_localization')->table(), $item)) {
throw new Exception('Cannot save sysdocs_localization ' . $lang);
}
}
if (count($newItems) > 100) {
if (!Model::factory('sysdocs_localization')->multiInsert($newItems, 50)) {
throw new Exception('Cannot save sysdocs_localization ' . $lang);
}
$newItems = array();
}
}
if (count($newItems) && !Model::factory('sysdocs_localization')->multiInsert($newItems, 50)) {
throw new Exception('Cannot save sysdocs_localization ' . $lang);
}
}
}
示例12: 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();
}
示例13: _invalidateBlockList
/**
* @param array $blockItems
*/
protected function _invalidateBlockList(array $blockItems)
{
if (!$this->_cache) {
return;
}
if (empty($blockItems)) {
return;
}
$blockIds = Utils::fetchCol('id', $blockItems);
$blockMapping = Model::factory('Blockmapping');
$pageBlocks = $blockMapping->getList(false, array('block_id' => $blockIds), array('page_id', 'block_id'));
if (empty($pageBlocks)) {
return;
}
/*
* Reset block config for pages
*/
$pages = array_unique(Utils::fetchCol('page_id', $pageBlocks));
foreach ($pages as $id) {
if ($id == 0 || empty($id)) {
$this->invalidateDefaultMap();
}
$this->_cache->remove($this->hashPage($id));
$this->_cache->remove($this->_hashMap($id));
}
unset($pages);
$sortedPageBlocks = Utils::groupByKey('block_id', $pageBlocks);
$pagesModel = Model::factory('Page');
$defaultMapped = $pagesModel->getPagesWithDefaultMap();
/*
* Reset cache for all blocks with current menu on all pages
*/
foreach ($blockItems as $v) {
if (!strlen($v['sys_name'])) {
$this->_cache->remove($this->getCacheKey(self::DEFAULT_BLOCK, $v));
continue;
}
if (!isset($sortedPageBlocks[$v['id']]) || empty($sortedPageBlocks[$v['id']])) {
continue;
}
foreach ($sortedPageBlocks[$v['id']] as $pageToBlock) {
if ($v['sys_name']::dependsOnPage) {
$v['page_id'] = $pageToBlock['page_id'];
if ($v['page_id'] == 0) {
foreach ($defaultMapped as $pId) {
$cfg = $v;
$cfg['page_id'] = $pId;
$this->_cache->remove($this->getCacheKey($v['sys_name'], $cfg));
}
}
}
$this->_cache->remove($this->getCacheKey($v['sys_name'], $v));
}
}
}
示例14: _getSingleLinks
/**
* Get "single link" associations
* when object has link as own property
* @param integer $objectId
* @param string $relatedObject - related object name
* @param array $links - links config like
* array(
* 'field1'=>'object',
* 'field2'=>'multy'
* ...
* 'fieldN'=>'object',
* )
* @return array
*/
protected static function _getSingleLinks($objectId, $relatedObject, $links)
{
$relatedConfig = Db_Object_Config::getInstance($relatedObject);
$relatedObjectModel = Model::factory($relatedObject);
$fields = array();
$singleRelated = array();
foreach ($links as $field => $type) {
if ($type !== 'object') {
continue;
}
$fields[] = $field;
}
if (empty($fields)) {
return array();
}
$db = $relatedObjectModel->getDbConnection();
$sql = $db->select()->from($relatedObjectModel->table(), array($relatedConfig->getPrimaryKey()));
$first = true;
foreach ($fields as $field) {
if ($first) {
$sql->where($db->quoteIdentifier($field) . ' =?', $objectId);
} else {
$sql->orWhere($db->quoteIdentifier($field) . ' =?', $objectId);
$first = false;
}
}
$data = $db->fetchAll($sql);
if (empty($data)) {
return array();
}
return Utils::fetchCol($relatedConfig->getPrimaryKey(), $data);
}
示例15: listAction
public function listAction()
{
$object = Request::post('object', 'string', false);
$query = Request::post('search', 'string', false);
$params = Request::post('pager', 'array', array());
if (!$object || !Db_Object_Config::configExists($object)) {
Response::jsonError($this->_lang->WRONG_REQUEST);
}
$cfg = Db_Object_Config::getInstance($object);
$fieldsCfg = $cfg->getFieldsConfig(true);
$fields = array();
$dictionaries = array();
$objectLinks = $cfg->getLinks(array(Db_Object_Config::LINK_OBJECT));
$multylinks = $cfg->getLinks(array(Db_Object_Config::LINK_OBJECT_LIST));
foreach ($fieldsCfg as $name => $fCfg) {
if ($cfg->isDictionaryLink($name)) {
$dictionaries[$name] = $cfg->getLinkedDictionary($name);
}
if ($cfg->isText($name) && !$cfg->isLink($name)) {
$fields[$name] = '"[ text ]"';
} else {
$fields[] = $name;
}
}
$model = Model::factory($object);
$count = $model->getCount(false, $query, false);
$data = array();
if ($count) {
$data = $model->getList($params, false, $fields, false, $query);
if (!empty($objectLinks)) {
$objectIds = array();
foreach ($data as $row) {
foreach ($objectLinks as $obj => $fields) {
if (!isset($objectIds[$obj])) {
$objectIds[$obj] = array();
}
foreach ($fields as $fName => $lType) {
$objectIds[$obj][] = $row[$fName];
}
}
}
foreach ($objectIds as $oName => &$idsList) {
if (empty($idsList)) {
continue;
}
array_unique($idsList);
$oCfg = Db_Object_Config::getInstance($oName);
$linkedObjects = Db_Object::factory($oName, $idsList);
$titleList = array();
if (!empty($linkedObjects)) {
foreach ($linkedObjects as $id => $item) {
$titleList[$id] = array('id' => $id, 'title' => $item->getTitle());
}
}
$idsList = $titleList;
}
}
if (!empty($dictionaries) || !empty($objectLinks) || !empty($multylinks)) {
foreach ($data as &$row) {
if (!empty($dictionaries)) {
foreach ($dictionaries as $col => $dictName) {
$dictionary = Dictionary::getInstance($dictName);
if ($dictionary->isValidKey($row[$col])) {
$row[$col] = '[' . $row[$col] . '] ' . $dictionary->getValue($row[$col]);
} else {
$row[$col] = '[' . $row[$col] . ']';
}
}
}
if (!empty($objectLinks)) {
foreach ($objectLinks as $object => $fields) {
foreach ($fields as $name => $type) {
if (isset($objectIds[$object][$row[$name]])) {
$row[$name] = '[' . $objectIds[$object][$row[$name]]['id'] . '] ' . $objectIds[$object][$row[$name]]['title'];
}
}
}
}
if (!empty($multylinks)) {
foreach ($multylinks as $obj => $fCfg) {
foreach ($fCfg as $name => $type) {
$list = array();
$rec = $row[$name];
if (strlen($rec)) {
$rec = @unserialize($rec);
if (!empty($rec)) {
$ids = Utils::fetchCol('id', $rec);
if (!empty($ids)) {
$objectsList = Db_Object::factory($cfg->getLinkedObject($name), $ids);
}
foreach ($rec as $item) {
if (isset($objectsList[$item['id']])) {
$list[] = '[' . $item['id'] . '] ' . $objectsList[$item['id']]->getTitle();
} else {
$list[] = '[' . $item['id'] . '] ' . $item['title'] . ' (deleted)';
}
}
}
}
$row[$name] = implode(', ', $list);
//.........这里部分代码省略.........