/** * Creates a table for a custom entity. * The custom entity is an entity which has no PHP class in any bundle. The definition of such entity is * created automatically in Symfony cache * * @param Schema $schema * @param string $entityName * @param array $options * * @return Table * * @throws \InvalidArgumentException */ public function createCustomEntityTable(Schema $schema, $entityName, array $options = []) { $className = ExtendHelper::ENTITY_NAMESPACE . $entityName; $tableName = $this->nameGenerator->generateCustomEntityTableName($className); $table = $schema->createTable($tableName); $this->entityMetadataHelper->registerEntityClass($tableName, $className); $options = new OroOptions($options); // set options $options->setAuxiliary(ExtendOptionsManager::ENTITY_CLASS_OPTION, $className); if ($options->has('extend', 'owner')) { if ($options->get('extend', 'owner') !== ExtendScope::OWNER_CUSTOM) { throw new \InvalidArgumentException(sprintf('The "extend.owner" option for a custom entity must be "%s".', ExtendScope::OWNER_CUSTOM)); } } else { $options->set('extend', 'owner', ExtendScope::OWNER_CUSTOM); } if ($options->has('extend', 'is_extend')) { if ($options->get('extend', 'is_extend') !== true) { throw new \InvalidArgumentException('The "extend.is_extend" option for a custom entity must be TRUE.'); } } else { $options->set('extend', 'is_extend', true); } $table->addOption(OroOptions::KEY, $options); // add a primary key $table->addColumn(self::AUTO_GENERATED_ID_COLUMN_NAME, 'integer', ['autoincrement' => true]); $table->setPrimaryKey([self::AUTO_GENERATED_ID_COLUMN_NAME]); return $table; }
/** * @param Schema $schema */ public static function enableActivityAssociations(Schema $schema) { $options = new OroOptions(); $options->set('activity', 'immutable', false); $schema->getTable('orocrm_magento_cart')->addOption(OroOptions::KEY, $options); $schema->getTable('orocrm_magento_order')->addOption(OroOptions::KEY, $options); }
/** * Add inheritance tables to target to show inherited activities * * @param Schema $schema * @param string $targetTableName Target entity table name * @param string $inheritanceTableName Inheritance entity table name * @param string[] $path Path of relations to target entity */ public function addInheritanceTargets(Schema $schema, $targetTableName, $inheritanceTableName, $path) { $targetTable = $schema->getTable($targetTableName); $options = new OroOptions(); $inheritance['target'] = $this->extendExtension->getEntityClassByTableName($inheritanceTableName); $inheritance['path'] = $path; $inheritances[] = $inheritance; $options->append('activity', 'inheritance_targets', $inheritances); $targetTable->addOption(OroOptions::KEY, $options); }
/** * Adds the association between the target table and the note table * * @param Schema $schema * @param string $targetTableName Target entity table name * @param string $targetColumnName A column name is used to show related entity */ public function addNoteAssociation(Schema $schema, $targetTableName, $targetColumnName = null) { $noteTable = $schema->getTable(self::NOTE_TABLE_NAME); $targetTable = $schema->getTable($targetTableName); if (empty($targetColumnName)) { $primaryKeyColumns = $targetTable->getPrimaryKeyColumns(); $targetColumnName = array_shift($primaryKeyColumns); } $options = new OroOptions(); $options->set('note', 'enabled', true); $targetTable->addOption(OroOptions::KEY, $options); $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName)); $this->extendExtension->addManyToOneRelation($schema, $noteTable, $associationName, $targetTable, $targetColumnName); }
/** * Adds the association between the target table and the attachment table * * @param Schema $schema * @param string $targetTableName Target entity table name * @param string[] $allowedMimeTypes The list of allowed MIME types * @param int $maxFileSize Max allowed file size in megabytes */ public function addAttachmentAssociation(Schema $schema, $targetTableName, array $allowedMimeTypes = [], $maxFileSize = 1) { $noteTable = $schema->getTable(self::ATTACHMENT_ASSOCIATION_TABLE_NAME); $targetTable = $schema->getTable($targetTableName); $primaryKeyColumns = $targetTable->getPrimaryKeyColumns(); $targetColumnName = array_shift($primaryKeyColumns); $options = new OroOptions(); $options->set('attachment', 'enabled', true); $options->set('attachment', 'maxsize', $maxFileSize); $options->set('attachment', 'mimetypes', implode("\n", $allowedMimeTypes)); $targetTable->addOption(OroOptions::KEY, $options); $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName)); $this->extendExtension->addManyToOneRelation($schema, $noteTable, $associationName, $targetTable, $targetColumnName); }
/** * Adds the association between the given table and the table contains activity records * * The activity entity must be included in 'activity' group ('groups' attribute of 'grouping' scope) * * @param Schema $schema * @param string $activityTableName Activity entity table name. It is owning side of the association * @param string $targetTableName Target entity table name * @param bool $immutable Set TRUE to prohibit disabling the activity association from UI */ public function addActivityAssociation(Schema $schema, $activityTableName, $targetTableName, $immutable = false) { $targetTable = $schema->getTable($targetTableName); // Column names are used to show a title of target entity $targetTitleColumnNames = $targetTable->getPrimaryKeyColumns(); // Column names are used to show detailed info about target entity $targetDetailedColumnNames = $targetTable->getPrimaryKeyColumns(); // Column names are used to show target entity in a grid $targetGridColumnNames = $targetTable->getPrimaryKeyColumns(); $activityClassName = $this->extendExtension->getEntityClassByTableName($activityTableName); $options = new OroOptions(); $options->append('activity', 'activities', $activityClassName); if ($immutable) { $options->append('activity', 'immutable', $activityClassName); } $targetTable->addOption(OroOptions::KEY, $options); $associationName = ExtendHelper::buildAssociationName($this->extendExtension->getEntityClassByTableName($targetTableName), ActivityScope::ASSOCIATION_KIND); $this->extendExtension->addManyToManyRelation($schema, $activityTableName, $associationName, $targetTable, $targetTitleColumnNames, $targetDetailedColumnNames, $targetGridColumnNames, ['extend' => ['without_default' => true]]); }
/** * @param string $scope * @param string $code * @param string $val * @return array */ protected function getAppendedOption($scope, $code, $val) { $options = new OroOptions(); $options->append($scope, $code, $val); return $options->toArray(); }
/** * Prohibits to enable any activity to ContactRequest entity * * This is temporary solution till workflows cannot use system wide actions * * @param Schema $schema */ public static function disableActivityAssociations(Schema $schema) { $options = new OroOptions(); $options->set('activity', 'immutable', true); $schema->getTable('orocrm_contactus_request')->addOption(OroOptions::KEY, $options); }