camelcase2Underscore() public static method

public static camelcase2Underscore ( $value )
Example #1
0
 protected function setupColumnAttributes(ColumnDefinitionInterface $column, $xmlColumn)
 {
     $xmlColumn['name'] = Tools::camelcase2Underscore($column->getName());
     $type = $column->getSqlDataType();
     $size = null;
     if (false !== ($pos = strpos($type, '('))) {
         $size = trim(str_replace(['(', ')'], '', substr($type, $pos)));
         $type = substr($type, 0, $pos);
     }
     $propelType = $this->getPropelColumnType($type);
     $xmlColumn['type'] = strtoupper($propelType);
     if ($size) {
         $xmlColumn['size'] = $size;
     }
 }
Example #2
0
 /**
  * Returns the column name for database access.
  *
  * @return string
  */
 public function getColumnName()
 {
     return Tools::camelcase2Underscore($this->getId());
 }
Example #3
0
 public function bootRunTime(Object $object, Configs $configs)
 {
     $contentsObjectName = $object->getId() . ucfirst($this->getFieldDefinition()->getId());
     $contentsObject = $object->getBundle()->getObject($contentsObjectName);
     if (!$contentsObject) {
         $contentsObject = new Object();
         $contentsObject->setId($contentsObjectName);
         if ($object->getWorkspace()) {
             $contentsObject->setWorkspace(true);
         }
         $contentsObject->setAutoCrud(false);
         $contentsObject->setSearchable(false);
         $contentsObject->setExcludeFromREST(true);
         $contentsObject->setNested(true);
         $contentsObject->setNestedRootAsObject(true);
         $contentsObject->setNestedRootObject($object->getKey());
         $contentsObject->setNestedRootObjectField('foreignId');
         $contentsObject->setTable($object->getTable() . '_' . Tools::camelcase2Underscore($this->getFieldDefinition()->getId()));
         $contentsObject->setStorageService($object->getStorageService());
     }
     $fields = ['id' => ['type' => 'number', 'autoIncrement' => true, 'primaryKey' => true], 'foreignId' => ['type' => 'number'], 'slotId' => ['type' => 'number'], 'sort' => ['type' => 'number'], 'content' => ['type' => 'textarea'], 'template' => ['type' => 'view'], 'type' => ['type' => 'text'], 'hide' => ['type' => 'checkbox'], 'unsearchable' => ['type' => 'checkbox'], 'access_from' => ['type' => 'datetime'], 'access_to' => ['type' => 'datetime'], 'access_from_groups' => ['type' => 'text']];
     foreach ($fields as $k => $def) {
         if (!$contentsObject->getField($k)) {
             $def['id'] = $k;
             $field = new Field($def, $object->getJarves());
             $contentsObject->addField($field);
             $configs->addReboot(sprintf('[ContentElements] Added field %s to %s', $k, $contentsObject->getKey()));
         }
     }
     if (!$contentsObject->hasRelation('ForeignObject')) {
         $relation = new RelationDefinition();
         $relation->setName('ForeignObject');
         $relation->setType(AbstractStorage::MANY_TO_ONE);
         $relation->setForeignObjectKey($object->getKey());
         $relation->setRefName(ucfirst($this->getFieldDefinition()->getId()));
         $reference = new RelationReferenceDefinition();
         $primaryFields = $object->getPrimaryKeys();
         if (1 < count($primaryFields)) {
             throw new ModelBuildException(sprintf('FieldType `ContentElements` can not be used on the object `%s` with composite PrimaryKey', $object->getId()));
         }
         if (0 === count($primaryFields)) {
             throw new ModelBuildException(sprintf('FieldType `ContentElements` can not be used on the object `%s` with no PrimaryKey', $object->getId()));
         }
         $columns = $primaryFields[0]->getFieldType()->getColumns();
         if (1 < count($columns)) {
             throw new ModelBuildException(sprintf('FieldType `ContentElements` can not be used on the object `%s` with composite PrimaryKey', $object->getId()));
         }
         $reference->setForeignColumn($columns[0]);
         $field = $contentsObject->getField('foreignId');
         $columns = $field->getFieldType()->getColumns();
         $reference->setLocalColumn($columns[0]);
         $relation->setReferences([$reference]);
         $contentsObject->addRelation($relation);
         $configs->addReboot(sprintf('[ContentElements] Added relation ForeignObject to %s', $contentsObject->getKey()));
     }
     if (!$contentsObject->getBundle()) {
         $object->getBundle()->addObject($contentsObject);
     }
     if (!$object->hasRelation($this->getFieldDefinition()->getId())) {
         $relation = new RelationDefinition();
         $relation->setName(ucfirst($this->getFieldDefinition()->getId()));
         $relation->setType(AbstractStorage::ONE_TO_MANY);
         $relation->setForeignObjectKey($contentsObject->getKey());
         $relation->setRefName('ForeignObject');
         $reference = new RelationReferenceDefinition();
         $primaryFields = $object->getPrimaryKeys();
         $columns = $primaryFields[0]->getFieldType()->getColumns();
         $reference->setLocalColumn($columns[0]);
         $field = $contentsObject->getField('foreignId');
         $columns = $field->getFieldType()->getColumns();
         $reference->setForeignColumn($columns[0]);
         $relation->setReferences([$reference]);
         $object->addRelation($relation);
         $configs->addReboot(sprintf('[ContentElements] Added relation %s to %s', ucfirst($this->getFieldDefinition()->getId()), $object->getKey()));
     }
 }
Example #4
0
 /**
  * @param $fieldId
  *
  * @return Field
  */
 public function getField($fieldId)
 {
     if (null !== $this->fields) {
         $id = Tools::camelcase2Underscore($fieldId);
         return isset($this->fields[$id]) ? $this->fields[$id] : null;
     }
 }
Example #5
0
 /**
  * @param \Jarves\Configuration\Object $objectDefinition
  * @param Configs $configs
  * @return bool
  */
 protected function defineCrossObject(Object $objectDefinition, Configs $configs)
 {
     $changed = false;
     $bundle = $objectDefinition->getBundle();
     $foreignObjectDefinition = $configs->getObject($this->getFieldDefinition()->getObject());
     $possibleObjectName = ucfirst($objectDefinition->getId()) . ucfirst($foreignObjectDefinition->getId());
     $possibleObjectKey = $bundle->getName() . '/' . $possibleObjectName;
     if (!($crossObjectKey = $this->getFieldDefinition()->getObjectRelationCrossObjectKey())) {
         $crossObjectKey = $possibleObjectKey;
     }
     $crossObject = $configs->getObject($crossObjectKey);
     if (!$crossObject) {
         if (!($crossObject = $configs->getObject($possibleObjectKey))) {
             $crossObject = new Object(null, $objectDefinition->getJarves());
             $crossObject->setId($possibleObjectName);
             $crossObject->setSearchable(false);
             $crossObject->setAutoCrud(false);
             $crossObject->setExcludeFromREST(true);
             $crossObject->setTable($objectDefinition->getTable() . '_' . Tools::camelcase2Underscore($foreignObjectDefinition->getId()));
             $changed = true;
         }
     }
     if (!$crossObject->isCrossRef()) {
         $crossObject->setCrossRef(true);
         $changed = true;
     }
     $leftFieldName = $this->getFieldDefinition()->getObjectRefRelationName() ?: $objectDefinition->getId();
     if (!$crossObject->getField($leftFieldName)) {
         $leftObjectField = new Field(null, $objectDefinition->getJarves());
         $leftObjectField->setId($leftFieldName);
         $leftObjectField->setType('object');
         $leftObjectField->setObject($objectDefinition->getKey());
         $leftObjectField->setObjectRelation(AbstractStorage::ONE_TO_ONE);
         $leftObjectField->setPrimaryKey(true);
         $crossObject->addField($leftObjectField);
         $changed = true;
     }
     if (!$crossObject->getField($this->getFieldDefinition()->getId())) {
         $rightObjectField = new Field(null, $objectDefinition->getJarves());
         $rightObjectField->setId($this->getFieldDefinition()->getId());
         $rightObjectField->setType('object');
         $rightObjectField->setObject($foreignObjectDefinition->getKey());
         $rightObjectField->setObjectRelation(AbstractStorage::ONE_TO_ONE);
         $rightObjectField->setPrimaryKey(true);
         $crossObject->addField($rightObjectField);
         $changed = true;
     }
     if (!$crossObject->getBundle()) {
         //we created a new object
         $bundle->addObject($crossObject);
     }
     return $changed;
 }
Example #6
0
 /**
  * @param  array $filter
  *
  * @return array|null
  */
 public static function buildFilter($filter)
 {
     $condition = null;
     if (is_array($filter)) {
         //build condition query
         $condition = array();
         foreach ($filter as $k => $v) {
             if ($condition) {
                 $condition[] = 'and';
             }
             $k = Tools::camelcase2Underscore($k);
             if (strpos($v, '*') !== false) {
                 $condition[] = array($k, 'LIKE', str_replace('*', '%', $v));
             } else {
                 $condition[] = array($k, '=', $v);
             }
         }
     }
     return $condition;
 }
Example #7
0
 /**
  * @param array $conditionRule
  * @param array $params
  * @param string $objectKey
  * @param array $usedFieldNames
  * @return string
  */
 public function singleConditionToSql(Condition $condition, $conditionRule, &$params, $objectKey, &$usedFieldNames = null)
 {
     if ($conditionRule[0] === null) {
         return '';
     }
     $tableName = '';
     if ($condition->isTableNameSet()) {
         //custom tableName overwrites the tableName from the object definition (for alias use cases for example)
         $tableName = $condition->getTableName();
     }
     $def = $this->objects->getDefinition($objectKey);
     if ($def && !$tableName) {
         $tableName = $def->getTable();
     }
     $columnName = $fieldName = $conditionRule[0];
     if (false !== ($pos = strpos($fieldName, '.'))) {
         $tableName = substr($fieldName, 0, $pos);
         $columnName = $fieldName = substr($fieldName, $pos + 1);
     }
     if ($def) {
         $field = $def->getField($fieldName);
         if ($field) {
             $columns = $field->getFieldType()->getColumns();
             if (!$columns) {
                 throw new \RuntimeException("Field {$fieldName} ({$field->getType()}) does not have columns");
             }
             $columnName = Tools::camelcase2Underscore($columns[0]->getName());
         }
     } else {
         $columnName = Tools::camelcase2Underscore($fieldName);
     }
     if (null !== $usedFieldNames) {
         $usedFieldNames[] = $fieldName;
     }
     if (!is_numeric($conditionRule[0])) {
         $result = ($tableName ? Tools::dbQuote($tableName) . '.' : '') . Tools::dbQuote($columnName) . ' ';
     } else {
         $result = $conditionRule[0];
     }
     if (strtolower($conditionRule[1]) == 'regexp') {
         $result .= strtolower($this->jarvesConfig->getSystemConfig()->getDatabase()->getMainConnection()->getType()) == 'mysql' ? 'REGEXP' : '~';
     } else {
         $result .= $conditionRule[1];
     }
     if (!is_numeric($conditionRule[0])) {
         if (isset($conditionRule[2]) && $conditionRule[2] !== null) {
             if ($conditionRule[2] instanceof ConditionSubSelect) {
                 $result .= ' (' . $this->subSelectConditionToSql($conditionRule[2], $params, $objectKey, $usedFieldNames) . ') ';
             } else {
                 $params[':p' . (count($params) + 1)] = $conditionRule[2];
                 $p = ':p' . count($params);
                 if (strtolower($conditionRule[1]) == 'in' || strtolower($conditionRule[1]) == 'not in') {
                     $result .= " ({$p})";
                 } else {
                     $result .= ' ' . $p;
                 }
             }
         }
     } else {
         $result .= ' ' . ($conditionRule[0] + 0);
     }
     return $result;
 }