本文整理汇总了PHP中Espo\Core\Utils\Util::toUnderScore方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::toUnderScore方法的具体用法?PHP Util::toUnderScore怎么用?PHP Util::toUnderScore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Espo\Core\Utils\Util
的用法示例。
在下文中一共展示了Util::toUnderScore方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
protected function load($fieldName, $entityName)
{
$foreignField = $this->getForeignField($fieldName, $entityName);
$tableName = Util::toUnderScore($entityName);
$fullList = array();
//contains empty string (" ") like delimiter
$fullListReverse = array();
//reverse of $fullList
$fieldList = array();
//doesn't contain empty string (" ") like delimiter
$like = array();
$equal = array();
foreach ($foreignField as $foreignFieldName) {
$fieldNameTrimmed = trim($foreignFieldName);
if (!empty($fieldNameTrimmed)) {
$columnName = $tableName . '.' . Util::toUnderScore($fieldNameTrimmed);
$fullList[] = $fieldList[] = $columnName;
$like[] = $columnName . " LIKE '{text}'";
$equal[] = $columnName . " = '{text}'";
} else {
$fullList[] = "'" . $foreignFieldName . "'";
}
}
$fullListReverse = array_reverse($fullList);
return array($entityName => array('fields' => array($fieldName => array('type' => 'varchar', 'select' => $this->getSelect($fullList), 'where' => array('LIKE' => "(" . implode(" OR ", $like) . " OR CONCAT(" . implode(", ", $fullList) . ") LIKE '{text}' OR CONCAT(" . implode(", ", $fullListReverse) . ") LIKE '{text}')", '=' => "(" . implode(" OR ", $equal) . " OR CONCAT(" . implode(", ", $fullList) . ") = '{text}' OR CONCAT(" . implode(", ", $fullListReverse) . ") = '{text}')"), 'orderBy' => implode(", ", array_map(function ($item) {
return $item . ' {direction}';
}, $fieldList))))));
}
示例2: load
protected function load($fieldName, $entityName)
{
$subList = array('first' . ucfirst($fieldName), ' ', 'last' . ucfirst($fieldName));
$tableName = Util::toUnderScore($entityName);
$orderByField = 'first' . ucfirst($fieldName);
// TODO available in settings
$fullList = array();
$fullListReverse = array();
$fieldList = array();
$like = array();
$equal = array();
foreach ($subList as $subFieldName) {
$fieldNameTrimmed = trim($subFieldName);
if (!empty($fieldNameTrimmed)) {
$columnName = $tableName . '.' . Util::toUnderScore($fieldNameTrimmed);
$fullList[] = $fieldList[] = $columnName;
$like[] = $columnName . " LIKE {value}";
$equal[] = $columnName . " = {value}";
} else {
$fullList[] = "'" . $subFieldName . "'";
}
}
$fullListReverse = array_reverse($fullList);
return array($entityName => array('fields' => array($fieldName => array('type' => 'varchar', 'select' => $this->getSelect($fullList), 'where' => array('LIKE' => "(" . implode(" OR ", $like) . " OR CONCAT(" . implode(", ", $fullList) . ") LIKE {value} OR CONCAT(" . implode(", ", $fullListReverse) . ") LIKE {value})", '=' => "(" . implode(" OR ", $equal) . " OR CONCAT(" . implode(", ", $fullList) . ") = {value} OR CONCAT(" . implode(", ", $fullListReverse) . ") = {value})"), 'orderBy' => '' . $tableName . '.' . Util::toUnderScore($orderByField) . ' {direction}'))));
}
示例3: testToUnderScore
public function testToUnderScore()
{
$this->assertEquals('detail', Util::toUnderScore('detail'));
$this->assertEquals('detail_view', Util::toUnderScore('detailView'));
$this->assertEquals('my_detail_view', Util::toUnderScore('myDetailView'));
$this->assertEquals('my_f_f', Util::toUnderScore('myFF'));
$input = array('detail', 'detailView', 'myDetailView', 'myFF');
$result = array('detail', 'detail_view', 'my_detail_view', 'my_f_f');
$this->assertEquals($result, Util::toUnderScore($input));
}
示例4: load
protected function load($fieldName, $entityName)
{
$converedFieldName = $fieldName . 'Converted';
$currencyColumnName = Util::toUnderScore($fieldName);
$alias = Util::toUnderScore($fieldName) . "_currency_alias";
$d = array($entityName => array('fields' => array($fieldName => array("type" => "float", "orderBy" => $converedFieldName . " {direction}"))));
$params = $this->getFieldParams($fieldName);
if (!empty($params['notStorable'])) {
$d[$entityName]['fields'][$fieldName]['notStorable'] = true;
} else {
$d[$entityName]['fields'][$fieldName . 'Converted'] = array('type' => 'float', 'select' => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate", 'where' => array("=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate = {value}", ">" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate > {value}", "<" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate < {value}", ">=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate >= {value}", "<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}", "<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"), 'notStorable' => true, 'orderBy' => $converedFieldName . " {direction}");
}
return $d;
}
示例5: handleCurrencyParams
protected function handleCurrencyParams(&$params)
{
$entityName = $this->entityName;
$metadata = $this->getMetadata();
if (!$metadata) {
return;
}
$defs = $metadata->get('entityDefs.' . $entityName);
foreach ($defs['fields'] as $field => $d) {
if (isset($d['type']) && $d['type'] == 'currency') {
if (!empty($d['notStorable'])) {
continue;
}
if (empty($params['customJoin'])) {
$params['customJoin'] = '';
}
$alias = Util::toUnderScore($field) . "_currency_alias";
$params['customJoin'] .= "\n LEFT JOIN currency AS `{$alias}` ON {$alias}.id = " . Util::toUnderScore($entityName) . "." . Util::toUnderScore($field) . "_currency\n ";
}
}
}
示例6: load
protected function load($fieldName, $entityName)
{
return array($entityName => array('fields' => array($fieldName => array('select' => 'phone_number.name', 'where' => array('LIKE' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n\t\t\t\t\t\t\t\tSELECT entity_id \n\t\t\t\t\t\t\t\tFROM entity_phone_number\n\t\t\t\t\t\t\t\tJOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\tentity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n\t\t\t\t\t\t\t\t\tphone_number.deleted = 0 AND phone_number.name LIKE '{text}' \t\t\n\t\t\t\t\t\t\t)", '=' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n\t\t\t\t\t\t\t\tSELECT entity_id \n\t\t\t\t\t\t\t\tFROM entity_phone_number\n\t\t\t\t\t\t\t\tJOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\tentity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n\t\t\t\t\t\t\t\t\tphone_number.deleted = 0 AND phone_number.name = '{text}' \t\t\n\t\t\t\t\t\t\t)"), 'orderBy' => 'phone_number.name {direction}'), $fieldName . 'Data' => array('type' => 'text', 'notStorable' => true)), 'relations' => array($fieldName . 's' => array('type' => 'manyMany', 'entity' => 'PhoneNumber', 'relationName' => 'entityPhoneNumber', 'midKeys' => array('entity_id', 'phone_number_id'), 'conditions' => array('entityType' => $entityName), 'additionalColumns' => array('entityType' => array('type' => 'varchar', 'len' => 100), 'primary' => array('type' => 'bool', 'default' => false))))));
}
示例7: createRecord
protected function createRecord($entityName, $data)
{
if (isset($data['id'])) {
$entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
if (!isset($entity)) {
$pdo = $this->getEntityManager()->getPDO();
$sql = "SELECT id FROM `" . Util::toUnderScore($entityName) . "` WHERE `id` = '" . $data['id'] . "'";
$sth = $pdo->prepare($sql);
$sth->execute();
$deletedEntity = $sth->fetch(\PDO::FETCH_ASSOC);
if ($deletedEntity) {
$sql = "UPDATE `" . Util::toUnderScore($entityName) . "` SET deleted = '0' WHERE `id` = '" . $data['id'] . "'";
$pdo->prepare($sql)->execute();
$entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
}
}
}
if (!isset($entity)) {
$entity = $this->getEntityManager()->getEntity($entityName);
}
$entity->set($data);
$id = $this->getEntityManager()->saveEntity($entity);
return is_string($id);
}
示例8: generateIndexName
/**
* Generate index name
*
* @return string
*/
protected function generateIndexName($name, $entityName)
{
$names = array('IDX');
$names[] = strtoupper(Util::toUnderScore($entityName));
$names[] = strtoupper(Util::toUnderScore($name));
return implode('_', $names);
}
示例9: load
protected function load($fieldName, $entityName)
{
return array($entityName => array('fields' => array($fieldName => array('select' => 'emailAddresses.name', 'where' => array('LIKE' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n SELECT entity_id\n FROM entity_email_address\n JOIN email_address ON email_address.id = entity_email_address.email_address_id\n WHERE\n entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND\n email_address.deleted = 0 AND email_address.name LIKE {value}\n )", '=' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n SELECT entity_id\n FROM entity_email_address\n JOIN email_address ON email_address.id = entity_email_address.email_address_id\n WHERE\n entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND\n email_address.deleted = 0 AND email_address.name = {value}\n )", '<>' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n SELECT entity_id\n FROM entity_email_address\n JOIN email_address ON email_address.id = entity_email_address.email_address_id\n WHERE\n entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND\n email_address.deleted = 0 AND email_address.name <> {value}\n )"), 'orderBy' => 'emailAddresses.name {direction}'), $fieldName . 'Data' => array('type' => 'text', 'notStorable' => true)), 'relations' => array($fieldName . 'es' => array('type' => 'manyMany', 'entity' => 'EmailAddress', 'relationName' => 'entityEmailAddress', 'midKeys' => array('entity_id', 'email_address_id'), 'conditions' => array('entityType' => $entityName), 'additionalColumns' => array('entityType' => array('type' => 'varchar', 'len' => 100), 'primary' => array('type' => 'bool', 'default' => false))))));
}
示例10: prepareManyMany
/**
* Prepare a relation table for the manyMany relation
*
* @param string $entityName
* @param array $relationParams
* @param array $tables
*
* @return \Doctrine\DBAL\Schema\Table
*/
protected function prepareManyMany($entityName, $relationParams, $tables)
{
$tableName = Util::toUnderScore($relationParams['relationName']);
if ($this->getSchema()->hasTable($tableName)) {
$GLOBALS['log']->debug('DBAL: Table [' . $tableName . '] exists.');
return $this->getSchema()->getTable($tableName);
}
$table = $this->getSchema()->createTable($tableName);
$table->addColumn('id', 'int', array('length' => $this->defaultLength['int'], 'autoincrement' => true, 'notnull' => true));
//'unique' => true,
//add midKeys to a schema
foreach ($relationParams['midKeys'] as $index => $midKey) {
$usMidKey = Util::toUnderScore($midKey);
$table->addColumn($usMidKey, $this->idParams['dbType'], array('length' => $this->idParams['len']));
$table->addIndex(array($usMidKey));
}
//END: add midKeys to a schema
//add additionalColumns
if (isset($relationParams['additionalColumns'])) {
foreach ($relationParams['additionalColumns'] as $fieldName => $fieldParams) {
if (!isset($fieldParams['type'])) {
$fieldParams = array_merge($fieldParams, array('type' => 'varchar', 'length' => $this->defaultLength['varchar']));
}
$table->addColumn(Util::toUnderScore($fieldName), $fieldParams['type'], $this->getDbFieldParams($fieldParams));
}
}
//END: add additionalColumns
$table->addColumn('deleted', 'bool', array('default' => 0));
$table->setPrimaryKey(array("id"));
return $table;
}