/**
  * Provided a modelClassName, members and corresponding rules columns array is generated for schema generation.
  * Members with unique validators are tracked separately to be used with index array generation later.
  * @param string $modelClassName
  * @param array $members
  * @param array $rules
  * @param $messageLogger
  * @return array
  * @throws CException
  */
 public static function resolve($modelClassName, array $members, array $rules, &$messageLogger)
 {
     $messageLogger->addInfoMessage(Zurmo::t('Core', 'Building Column definitions for {{model}}', array('{{model}}' => $modelClassName)));
     $membersWithRules = array();
     $columns = array();
     foreach ($rules as $rule) {
         if (in_array($rule[0], $members)) {
             $membersWithRules[$rule[0]][] = $rule;
         }
     }
     foreach ($membersWithRules as $member => $rules) {
         $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName, $rules, $messageLogger);
         if ($column) {
             $columns[] = $column;
         } else {
             $errorMessage = Zurmo::t('Core', 'Failed to resolve {{model}}.{{member}} to column', array('{{model}}' => $modelClassName, '{{member}}' => $member));
             $messageLogger->addErrorMessage($errorMessage);
             throw new CException($errorMessage);
         }
     }
     if (count($members) != count($columns)) {
         $errorMessage = Zurmo::t('Core', 'Not all members for {{model}} could be translated to columns.', array('{{model}}' => $modelClassName));
         $messageLogger->addErrorMessage($errorMessage);
         $errorMessage .= Zurmo::t('Core', 'Members') . ': (';
         $errorMessage .= join(', ', $members);
         $errorMessage .= '),' . Zurmo::t('Core', 'Columns') . ' (';
         // Not Coding Standard
         $columnNames = RedBeanModelMemberToColumnUtil::resolveColumnNamesArrayFromColumnSchemaDefinition($columns);
         $columnNames = join(', ', $columnNames);
         $errorMessage .= $columnNames . ')';
         throw new CException($errorMessage);
     }
     $messageLogger->addInfoMessage(Zurmo::t('Core', 'Column definitions Built'));
     return $columns;
 }
 protected static function createTableByTableNameAndImportCsvIntoTable($fileHandle, $tableName, $delimiter, $enclosure, $firstRowIsHeaderRow)
 {
     $maxLengths = array();
     $columns = array();
     $importArray = array();
     static::determineMaximumColumnLengthAndPopulateImportArray($fileHandle, $delimiter, $enclosure, $maxLengths, $importArray, $firstRowIsHeaderRow);
     if (!empty($maxLengths)) {
         $columnCount = static::resolveColumnsByMaximumColumnLengths($maxLengths, $columns);
         static::safeValidateColumnCountAndCreateTable($tableName, $columnCount, $columns);
         if (static::databaseSupportsLoadLocalInFile()) {
             array_walk($importArray, 'static::prependEmptyStringToAllImportRows');
             static::convertImportArrayAndWriteToTemporaryFile($importArray, $firstRowIsHeaderRow);
             static::loadDataFromTemporaryFileToTable($tableName);
         } else {
             $columnNames = RedBeanModelMemberToColumnUtil::resolveColumnNamesArrayFromColumnSchemaDefinition($columns);
             static::importArrayIntoTable($tableName, $importArray, $columnNames);
         }
     } else {
         // we need this here so even is there are nothing else to do, we clear the table, else few tests would fail.
         ZurmoRedBean::$writer->dropTableByTableName($tableName);
     }
 }
 protected static function validateIndexDefinitionsFromSchema(array $indexes, array $columns)
 {
     $columnNames = RedBeanModelMemberToColumnUtil::resolveColumnNamesArrayFromColumnSchemaDefinition($columns);
     foreach ($indexes as $indexName => $index) {
         $indexNameLength = strlen($indexName);
         if (!is_string($indexName)) {
             return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index Name: {{indexName}} is not a string', array('{{indexName}}' => $indexName)));
         }
         if ($indexNameLength > 64) {
             return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index Name: {{indexName}} is {{length}} characters, {{over}} characters over limit(64).', array('{{indexName}}' => $indexName, '{{length}}' => $indexNameLength, '{{over}}' => $indexNameLength - 64)));
         }
         if (count($index) != 2) {
             return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index: {{indexName}} does not have 2 clauses', array('{{indexName}}' => $indexName)));
         }
         if (!ArrayUtil::isValidArrayIndex('columns', $index)) {
             return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index: {{indexName}} does not have indexed column names', array('{{indexName}}' => $indexName)));
         }
         if (!ArrayUtil::isValidArrayIndex('unique', $index)) {
             return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index: {{indexName}} does not have index uniqueness clause defined', array('{{indexName}}' => $indexName)));
         }
         if (!is_array($index['columns'])) {
             return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index: {{indexName}} column definition is not an array', array('{{indexName}}' => $indexName)));
         }
         foreach ($index['columns'] as $column) {
             list($column) = explode('(', $column);
             if (!in_array($column, $columnNames)) {
                 return static::returnSchemaValidationResult(Zurmo::t('Core', 'Index: {{indexName}} column: {{columnName}} does not exist' . ' in current schema definition provided. Columns: {{columns}}', array('{{indexName}}' => $indexName, '{{columnName}}' => $column, '{{columns}}' => print_r($columnNames, true))));
             }
         }
     }
     return static::returnSchemaValidationResult(null, true);
 }