public static function getList(array $properties = [], $alias = 'role_permission') { if (empty($properties)) { $list = $alias . '.role_id AS ' . $alias . 'RoleId, ' . $alias . '.permission_id AS ' . $alias . 'PermissionId'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'user') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.username AS ' . $alias . 'Username, ' . $alias . '.email AS ' . $alias . 'Email, ' . $alias . '.password AS ' . $alias . 'Password, ' . $alias . '.firstname AS ' . $alias . 'Firstname, ' . $alias . '.lastname AS ' . $alias . 'Lastname, ' . $alias . '.avatar_id AS ' . $alias . 'AvatarId, ' . $alias . '.is_admin AS ' . $alias . 'IsAdmin, ' . $alias . '.is_dev AS ' . $alias . 'IsDev, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'feedback') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.user_id AS ' . $alias . 'UserId, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.type AS ' . $alias . 'Type, ' . $alias . '.description AS ' . $alias . 'Description, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'page') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.parent_id AS ' . $alias . 'ParentId, ' . $alias . '.template_id AS ' . $alias . 'TemplateId, ' . $alias . '.layout_id AS ' . $alias . 'LayoutId, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.css AS ' . $alias . 'Css, ' . $alias . '.js AS ' . $alias . 'Js, ' . $alias . '.in_nav_header AS ' . $alias . 'InNavHeader, ' . $alias . '.in_nav_side AS ' . $alias . 'InNavSide, ' . $alias . '.in_sitemap AS ' . $alias . 'InSitemap, ' . $alias . '.in_breadcrumb AS ' . $alias . 'InBreadcrumb, ' . $alias . '.in_nav_footer AS ' . $alias . 'InNavFooter, ' . $alias . '.friendly_url_path AS ' . $alias . 'FriendlyUrlPath, ' . $alias . '.friendly_url AS ' . $alias . 'FriendlyUrl, ' . $alias . '.redirect AS ' . $alias . 'Redirect, ' . $alias . '.class AS ' . $alias . 'Class, ' . $alias . '.permission AS ' . $alias . 'Permission, ' . $alias . '.display_order AS ' . $alias . 'DisplayOrder, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'user_settings') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.user_id AS ' . $alias . 'UserId, ' . $alias . '.media_view AS ' . $alias . 'MediaView, ' . $alias . '.media_paging AS ' . $alias . 'MediaPaging, ' . $alias . '.content_paging AS ' . $alias . 'ContentPaging, ' . $alias . '.paging AS ' . $alias . 'Paging'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'folder') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.parent_id AS ' . $alias . 'ParentId, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.display_order AS ' . $alias . 'DisplayOrder, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'gadget') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.page_id AS ' . $alias . 'PageId, ' . $alias . '.component_id AS ' . $alias . 'ComponentId, ' . $alias . '.col AS ' . $alias . 'Col, ' . $alias . '.filter_id AS ' . $alias . 'FilterId, ' . $alias . '.custom_filter AS ' . $alias . 'CustomFilter, ' . $alias . '.display_order AS ' . $alias . 'DisplayOrder, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'user_security') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.user_id AS ' . $alias . 'UserId, ' . $alias . '.sign_in AS ' . $alias . 'SignIn, ' . $alias . '.secure AS ' . $alias . 'Secure, ' . $alias . '.type AS ' . $alias . 'Type, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'media') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.folder_id AS ' . $alias . 'FolderId, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.tags AS ' . $alias . 'Tags, ' . $alias . '.upload AS ' . $alias . 'Upload, ' . $alias . '.original_filename AS ' . $alias . 'OriginalFilename, ' . $alias . '.path AS ' . $alias . 'Path, ' . $alias . '.extension AS ' . $alias . 'Extension, ' . $alias . '.mime_type AS ' . $alias . 'MimeType, ' . $alias . '.file_size AS ' . $alias . 'FileSize, ' . $alias . '.width AS ' . $alias . 'Width, ' . $alias . '.height AS ' . $alias . 'Height, ' . $alias . '.alt AS ' . $alias . 'Alt, ' . $alias . '.is_selectable AS ' . $alias . 'IsSelectable, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'layout') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.summary AS ' . $alias . 'Summary, ' . $alias . '.filename AS ' . $alias . 'Filename, ' . $alias . '.columns AS ' . $alias . 'Columns, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'content') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.module_id AS ' . $alias . 'ModuleId, ' . $alias . '.app_id AS ' . $alias . 'AppId, ' . $alias . '.content_group AS ' . $alias . 'ContentGroup, ' . $alias . '.filter_id AS ' . $alias . 'FilterId, ' . $alias . '.author_id AS ' . $alias . 'AuthorId, ' . $alias . '.publisher_id AS ' . $alias . 'PublisherId, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.url_friendly_title AS ' . $alias . 'UrlFriendlyTitle, ' . $alias . '.use_expiration AS ' . $alias . 'UseExpiration, ' . $alias . '.go_live_date AS ' . $alias . 'GoLiveDate, ' . $alias . '.expiry_date AS ' . $alias . 'ExpiryDate, ' . $alias . '.published_date AS ' . $alias . 'PublishedDate, ' . $alias . '.version AS ' . $alias . 'Version, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'module_media') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.module_id AS ' . $alias . 'ModuleId, ' . $alias . '.field AS ' . $alias . 'Field, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'x') { if (empty($properties)) { $list = $alias . '.app_id AS ' . $alias . 'AppId, ' . $alias . '.media_id AS ' . $alias . 'MediaId, ' . $alias . '.description AS ' . $alias . 'Description'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'site') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.google_analytics AS ' . $alias . 'GoogleAnalytics, ' . $alias . '.keywords AS ' . $alias . 'Keywords, ' . $alias . '.description AS ' . $alias . 'Description, ' . $alias . '.css AS ' . $alias . 'Css, ' . $alias . '.js AS ' . $alias . 'Js, ' . $alias . '.sign_in_url AS ' . $alias . 'SignInUrl, ' . $alias . '.environment AS ' . $alias . 'Environment, ' . $alias . '.sql_log AS ' . $alias . 'SqlLog, ' . $alias . '.timezone AS ' . $alias . 'Timezone, ' . $alias . '.is_cms AS ' . $alias . 'IsCms, ' . $alias . '.cache_time AS ' . $alias . 'CacheTime, ' . $alias . '.use_device_template AS ' . $alias . 'UseDeviceTemplate, ' . $alias . '.skin AS ' . $alias . 'Skin, ' . $alias . '.send_mail_on_error AS ' . $alias . 'SendMailOnError, ' . $alias . '.mail_list_on_error AS ' . $alias . 'MailListOnError, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'log') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.code AS ' . $alias . 'Code, ' . $alias . '.user_id AS ' . $alias . 'UserId, ' . $alias . '.ip AS ' . $alias . 'Ip, ' . $alias . '.request_uri AS ' . $alias . 'RequestUri, ' . $alias . '.referer AS ' . $alias . 'Referer, ' . $alias . '.message AS ' . $alias . 'Message, ' . $alias . '.trace AS ' . $alias . 'Trace, ' . $alias . '.file AS ' . $alias . 'File, ' . $alias . '.line AS ' . $alias . 'Line, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
public static function getList(array $properties = [], $alias = 'module') { if (empty($properties)) { $list = $alias . '.id AS ' . $alias . 'Id, ' . $alias . '.title AS ' . $alias . 'Title, ' . $alias . '.summary AS ' . $alias . 'Summary, ' . $alias . '.workflow AS ' . $alias . 'Workflow, ' . $alias . '.has_filter AS ' . $alias . 'HasFilter, ' . $alias . '.has_content AS ' . $alias . 'HasContent, ' . $alias . '.status AS ' . $alias . 'Status, ' . $alias . '.created_date AS ' . $alias . 'CreatedDate, ' . $alias . '.modified_date AS ' . $alias . 'ModifiedDate'; return $list; } $list = ''; foreach ($properties as $property) { $list .= $alias . '.' . $property . ' AS ' . $alias . Util\Converter::toCamelCase($property, true) . ', '; } return rtrim(trim($list), ','); }
private function updateColumns($sqlCols) { $updated = false; foreach ($this->xmlProperties as $property) { if ($this->ignoreColumn($property)) { continue; } $propertyName = $property->getAttribute('name'); $type = $property->getAttribute('type'); $sqlType = $this->getDefaultMysqlType($property->getAttribute('mysql'), $type); $default = $property->getAttribute('default'); $default = $default != '' ? ' DEFAULT ' . $default : ''; $oldPropertyName = $property->getAttribute('old-name'); $update = $property->getAttribute('update'); $maxLength = $this->maxLength; $validations = $property->getElementsByTagName('validation'); foreach ($validations as $validation) { if ($validation->getAttribute('condition') == 'maxLength') { $maxLength = $validation->getAttribute('value'); break; } } if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'app_id' : 'id'; } else { if (in_array($type, ['foreignKey', 'singleKey', 'multipleKey', 'media'])) { $oldPropertyName = $propertyName . 'Id'; $propertyName .= '_id'; } } if (in_array($oldPropertyName, ['', '_id'])) { $temp = Converter::toCamelCase($propertyName); if ($temp != $propertyName) { $oldPropertyName = $temp; } } $newExist = $this->columnExists($sqlCols, $propertyName); $oldExist = $this->columnExists($sqlCols, $oldPropertyName); if ($newExist && $oldExist) { $this->info[] = '<div class="error">The column cannot be renamed because it already exists: ' . $propertyName . ', old column name: ' . $oldPropertyName . '</div>'; continue; } if ($oldExist && !in_array($oldPropertyName, ['', '_id', 'Id'])) { $sqlUpdate = $this->fieldList('column-rename', $propertyName, $type, $sqlType, $maxLength, $default, $this->table, $oldPropertyName); $this->db->execute($sqlUpdate); $this->info[] = '<div>Column renamed from <b>' . $oldPropertyName . '</b> to <b>' . $propertyName . '</b></div>'; $updated = true; } if ($newExist && $update == 'true') { $sqlUpdate = $this->fieldList('column-update', $propertyName, $type, $sqlType, $maxLength, $default, $this->table); $this->db->execute($sqlUpdate); $this->info[] = '<div>Column updated: <b>' . $propertyName . '</b></div>'; } } return $updated; }
private function deleteBy($entity, $table, $sqlPropertyName) { $tpl = new Template(Template::SITE, ['generator', 'data', 'parts']); $tpl->set('entity', $entity); $tpl->set('table', $table); $tpl->set('sqlPropertyName', $sqlPropertyName); $tpl->set('propertyName', Converter::toCamelCase($sqlPropertyName)); return $tpl->render('delete-by'); }
private function produceBaseModel() { $baseTplName = 'base'; // Base class $baseTpl = new Template(Template::SITE, ['generator', 'model']); $baseTpl->set('package', $this->package); $baseTpl->set('entity', $this->entity); $baseTpl->set('isPersistent', $this->isPersistent); $toString = '\'' . $this->entity . ': \' . $this->getId()'; $primaryKey = null; $multipleKeyVar = []; $propertyList = []; $propertySetDefault = []; $propertyMethod = []; $toArray = []; foreach ($this->xmlProperties as $property) { $type = $property->getAttribute('type'); $propertyName = Converter::toCamelCase($property->getAttribute('name')); if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'app_id' : 'id'; $primaryKey = $propertyName; $baseTpl->set('primaryKey', $primaryKey); } if ($type == 'multipleKey') { $multipleKeyVar[] = '$this->' . $propertyName . 'Id'; } } foreach ($this->xmlProperties as $property) { $type = $property->getAttribute('type'); $propertyName = Converter::toCamelCase($property->getAttribute('name')); if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'appId' : 'id'; } $default = $this->getDefaultValue($property->getAttribute('default'), $type); $relation = $property->getAttribute('relation'); $link = $property->getAttribute('link'); if ($link == '') { $link = 'id'; } if ($type == 'media') { $relation = 'Core\\Media'; $link = 'id'; } $enumList = []; $enums = $property->getElementsByTagName('enum'); foreach ($enums as $enum) { $index = $enum->getAttribute('index'); $value = $enum->getAttribute('value'); $enumList[$index] = $value; } $enumClass = $property->getAttribute('enum-class'); $propertyList[] = $this->propertyList($propertyName, $type, $enumClass); $propertySetList[] = $this->propertySetList($propertyName, $type, $enumList); $propertySetDefault[] = $this->propertySetDefault($propertyName, $type, $default); $propertyMethod[] = $this->propertyMethod($propertyName, $type, $relation, $link, $enumClass); if ($propertyName == $this->main) { if ($type == 'enum') { $toString = '$this->get' . ucfirst($propertyName) . 'Value()'; } else { $toString = '$this->get' . ucfirst($propertyName) . '()'; } } $toArray[] = $this->toArray($propertyName, $type); } $baseTpl->set('toArray', implode('', $toArray)); $baseTpl->set('toString', $toString); $baseTpl->set('multipleKeyVar', $multipleKeyVar); $baseTpl->set('propertyList', implode('', $propertyList)); $baseTpl->set('propertySetList', implode('', $propertySetList)); $baseTpl->set('propertySetDefault', implode('', $propertySetDefault)); $baseTpl->set('propertyMethod', implode('', $propertyMethod)); $basePath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/Base/Model.php'; if ($this->package == 'App') { $baseTplName = 'base-app'; } $render = str_replace('<#php', '<?php', $baseTpl->render($baseTplName)); \Rebond\Util\File::save($basePath, 'w', $render); $this->info[] = '<div>Base Model created.</div>'; }
public function run() { $entities = $this->xmlModel->getElementsByTagName('entity'); foreach ($entities as $ent) { $sqlEntity = $ent->getAttribute('name'); $entity = Converter::toCamelCase($sqlEntity, true); $main = $ent->getAttribute('main-property'); $enabled = $ent->getAttribute('enabled') == 'true' ? true : false; $hasContent = $ent->getAttribute('has-content') == 'false' ? false : true; $isPersistent = $ent->getAttribute('persistent') == 'false' ? false : true; $this->info[] = '<h2>' . $entity . '</h2>'; if (!$enabled) { $this->info[] = '<div class="orange">' . $entity . ' skipped.</div>'; continue; } if (!$this->validPackage($this->package)) { $this->info[] = '<div class="error">Invalid package: ' . $this->package . '. It must be one of the following: core, cms, bus, app.</div>'; continue; } if (!$this->validEntity($sqlEntity)) { $this->info[] = '<div class="error">Invalid entity: ' . $sqlEntity . '. It must start with a letter and contains alphanumeric characters.</div>'; continue; } $properties = $ent->getElementsByTagName('property'); $views = $ent->getElementsByTagName('view'); if (!$this->validProperties($properties)) { $this->info[] = '<div class="error">Invalid properties. Please check the manual.</div>'; continue; } if (!$this->validViews($views)) { $this->info[] = '<div class="error">Invalid views. Please check the manual.</div>'; continue; } $modelFolder = \Rebond\Config::getPath('rebond') . $this->package . '/' . $entity; if (!is_dir($modelFolder)) { $this->info[] = '<div>' . $entity . ' created.</div>'; } else { $this->info[] = '<div>' . $entity . ' updated.</div>'; } \Rebond\Util\Nav::createFolder($modelFolder . '/template'); \Rebond\Util\Nav::createFolder($modelFolder . '/Base'); // For App with content, Cms, Core, Bus if ($hasContent) { $model = new \Rebond\Generator\Model($this->package, $entity, $main, $isPersistent, $properties); $model->produce(); $this->info = array_merge($this->info, $model->getInfo()); $form = new \Rebond\Generator\Form($this->package, $entity, $properties); $form->produce(); $this->info = array_merge($this->info, $form->getInfo()); $service = new \Rebond\Generator\Service($this->package, $entity); $service->produce(); $this->info = array_merge($this->info, $service->getInfo()); if ($isPersistent) { $mysql = new \Rebond\Generator\Mysql($this->package, $sqlEntity, $properties); $mysql->produce(); $this->info = array_merge($this->info, $mysql->getInfo()); $view = new \Rebond\Generator\View($this->package, $entity, $main, $properties, $views, $this->generate); $view->produce(); $this->info = array_merge($this->info, $view->getInfo()); $data = new \Rebond\Generator\Data($this->package, $sqlEntity, $properties); $data->produce(); $this->info = array_merge($this->info, $data->getInfo()); } } if ($this->package == 'App') { $module = Module\Data::loadByTitle($entity); if (!isset($module)) { $module = new Module\Model(); $module->setTitle($entity); $module->setSummary($entity . ' summary'); $module->setStatus(StatusType::DELETED); $module->setHasContent($hasContent); $module->save(); } $gadget = new \Rebond\Generator\Gadget($entity, $views, $hasContent, $module->getId()); $gadget->produce(); $this->info = array_merge($this->info, $gadget->getInfo()); } } return implode('', $this->info); }
private function produceBaseForm() { $baseTplName = 'base'; // Base class $baseTpl = new Template(Template::SITE, ['generator', 'form']); $baseTpl->set('package', $this->package); $baseTpl->set('entity', $this->entity); $primaryKey = null; $propertyInitBase = []; $propertyList = []; $propertySetPost = []; $propertyMethod = []; $propertyValidate = []; foreach ($this->xmlProperties as $property) { $type = $property->getAttribute('type'); $propertyName = Converter::toCamelCase($property->getAttribute('name')); if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'appId' : 'id'; $primaryKey = $propertyName; $baseTpl->set('primaryKey', $primaryKey); } } foreach ($this->xmlProperties as $property) { $type = $property->getAttribute('type'); $propertyName = Converter::toCamelCase($property->getAttribute('name')); if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'appId' : 'id'; } $relation = $property->getAttribute('relation'); $link = $property->getAttribute('link'); if ($type == 'media') { $relation = 'Core\\Media'; $link = 'title'; } $validationList = []; $validations = $property->getElementsByTagName('validation'); $validationList[$type] = 'true'; foreach ($validations as $validation) { $condition = $validation->getAttribute('condition'); $value = $validation->getAttribute('value'); $validationList[$condition] = $value; } $propertyList[] = $this->propertyList($propertyName, $type, $validationList); $propertyInitBase[] = $this->propertyInitBase($propertyName, $type, $validationList); $propertySetPost[] = $this->propertySetPost($propertyName, $type); $propertyMethod[] = $this->propertyMethod($propertyName, $type, $relation, $link); $propertyValidate[] = $this->propertyValidate($propertyName, $type); } $baseTpl->set('propertyList', implode('', $propertyList)); $baseTpl->set('propertyInitBase', implode('', $propertyInitBase)); $baseTpl->set('propertySetPost', implode('', $propertySetPost)); $baseTpl->set('propertyValidate', implode('', $propertyValidate)); $baseTpl->set('propertyMethod', implode('', $propertyMethod)); $basePath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/Base/Form.php'; if ($this->package == 'App') { $baseTplName = 'base-app'; } $render = str_replace('<#php', '<?php', $baseTpl->render($baseTplName)); \Rebond\Util\File::save($basePath, 'w', $render); $this->info[] = '<div>Base Form created.</div>'; }
public function produceViews() { foreach ($this->views as $view) { $viewPath = \Rebond\Config::getPath('rebond') . $this->package . '/' . $this->entity . '/template/' . $view . '.tpl'; if (file_exists($viewPath) && in_array($view, ['filter', 'form-success'])) { $this->info[] = '<div class="exist">' . $view . ' already exists.</div>'; continue; } $propertyList = []; $propertyList2 = []; $multipleKey = []; $primaryKey = null; $viewTpl = new Template(Template::SITE, ['generator', 'views']); $viewTpl->set('package', $this->package); $viewTpl->set('entity', $this->entity); $viewTpl->set('isGenerated', false); $viewTpl->set('hasStatus', false); if (!in_array($view, ['filter'])) { foreach ($this->xmlProperties as $property) { $type = $property->getAttribute('type'); $viewList = $property->getAttribute('view-list') == 'false' ? false : true; $skip = $property->getAttribute('persistent') == 'false' ? true : false; $skip = in_array($view, ['listing', 'bus-listing', 'admin-listing', 'admin-trail']) && (!$viewList || in_array($type, ['foreignKeyLink', 'singleKeyList'])) ? true : $skip; if ($skip) { continue; } $propertyName = Converter::toCamelCase($property->getAttribute('name')); if ($type == 'primaryKey') { $propertyName = $this->package == 'App' ? 'appId' : 'id'; $primaryKey = $propertyName; $viewTpl->set('primaryKey', $primaryKey); } if ($type == 'multipleKey') { $multipleKey[] = $propertyName . 'Id'; } if ($type == 'status') { $viewTpl->set('hasStatus', true); } $propertyList[] = $this->addViewList($this->package, $this->entity, $propertyName, $type, $propertyName == $this->main, $view); if (in_array($view, ['listing', 'admin-listing', 'bus-listing', 'admin-trail'])) { $propertyList2[] = $this->addViewList($this->package, $this->entity, $propertyName, $type, $propertyName == $this->main, $view . '-2'); } } $viewTpl->set('propertyList', implode('', $propertyList)); if (in_array($view, ['listing', 'admin-listing', 'bus-listing', 'admin-trail'])) { $viewTpl->set('propertyList2', implode('', $propertyList2)); } } $realView = $view; if (in_array($view, ['bus-editor', 'editor'])) { if (!isset($primaryKey)) { $realView .= '-nokey'; } } else { if (in_array($view, ['bus-listing', 'listing'])) { if (count($multipleKey) > 0) { $viewTpl->set('multipleKey', $multipleKey); $realView .= '-multikey'; } else { if (!isset($primaryKey)) { $realView .= '-nokey'; } } } } if (file_exists($viewPath) && in_array($view, ['editor', 'view', 'listing', 'form', 'list', 'detail', 'single'])) { if (!$this->generate) { continue; } $fileNoExt = \Rebond\Util\File::getNoExtension($viewPath); $viewPath = $fileNoExt . '-generated.tpl'; $viewTpl->set('isGenerated', true); $this->info[] = '<div class="exist">' . $view . ' already exists. ' . $view . '-generated has been created.</div>'; } else { $this->info[] = '<div>' . $view . ' created.</div>'; } $render = str_replace('<#php', '<?php', $viewTpl->render($realView)); \Rebond\Util\File::save($viewPath, 'w', $render); } }