require_once getenv('PHOCOA_PROJECT_CONF');
$modulePath = rtrim($argv[1], '/');
$dir = $modulePath;
print "About to convert shared setup to YAML for module at: '{$modulePath}'\n";
$instancesFile = "{$dir}/shared.instances";
$configFile = "{$dir}/shared.config";
if (!file_exists($instancesFile)) {
    print "No instances file for module, thus no YAML conversion needed.\n";
    exit(0);
}
include $instancesFile;
if (file_exists($configFile)) {
    include $configFile;
} else {
    $__config = array();
}
$combined = array();
foreach ($__instances as $id => $class) {
    $combined[$id]['class'] = $class;
    if (isset($__config[$id])) {
        $combined[$id]['properties'] = $__config[$id]['properties'];
    }
}
$yaml = WFYaml::dump($combined);
$bytes = file_put_contents("{$dir}/shared.yaml", $yaml);
if ($bytes === false) {
    print "Failed saving yaml file: {$dir}/shared.yaml\n";
    exit(1);
}
print "Saved YAML for module to file: {$dir}/shared.yaml\n";
exit(0);
Example #2
0
 function generateModuleForEntity($entity)
 {
     print "Generating module for entity '" . $entity->valueForKey('name') . "'\n";
     $cwd = getcwd();
     $moduleName = strtolower($entity->valueForKey('name'));
     $moduleDir = $cwd . '/' . $moduleName;
     if (file_exists($moduleDir)) {
         print "WARNING: Module {$moduleName} already exists. Skipping\n";
         return;
     }
     mkdir($moduleDir);
     // module dir
     $this->modulePath .= $moduleName;
     // setup shared instances
     $sharedYaml[$entity->valueForKey('name')] = array('class' => 'WFArrayController', 'properties' => array('class' => $entity->valueForKey('name'), 'classIdentifiers' => $entity->valueForKey('primaryKeyProperty'), 'selectOnInsert' => true, 'automaticallyPreparesContent' => false));
     $sharedYaml['paginator'] = array('class' => 'WFPaginator', 'properties' => array('modeForm' => 'search', 'pageSize' => 25, 'itemPhraseSingular' => $entity->valueForKey('name'), 'itemPhrasePlural' => $entity->valueForKey('name') . 's'));
     file_put_contents($moduleDir . '/shared.yaml', WFYaml::dump($sharedYaml));
     $sharedEntityId = $entity->valueForKey('name');
     // build module code
     $this->smarty->assign('moduleName', $moduleName);
     $this->smarty->assign('entity', $entity);
     $this->smarty->assign('entityName', $entity->valueForKey('name'));
     $this->smarty->assign('sharedEntityId', $sharedEntityId);
     $this->smarty->assign('sharedEntityPrimaryKeyProperty', $entity->valueForKey('primaryKeyProperty'));
     $this->smarty->assign('descriptiveColumnName', $entity->valueForKey('descriptiveColumnName'));
     // look up Peer column constant name from the PHP name; call ObjPeer::translateFieldName($name, $fromType, $toType)
     $translateF = array($entity->valueForKey('name') . 'Peer', 'translateFieldName');
     $peerColName = call_user_func($translateF, ucfirst($entity->valueForKey('descriptiveColumnName')), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME);
     $this->smarty->assign('descriptiveColumnConstantName', strtoupper($peerColName));
     $moduleCode = $this->smarty->fetch(FRAMEWORK_DIR . '/framework/generator/module.tpl');
     file_put_contents($moduleDir . '/' . $moduleName . '.php', $moduleCode);
     // build list page
     // list.yaml
     $listYaml = array();
     $listFormId = 'search' . $entity->valueForKey('name') . 'Form';
     $listYaml[$listFormId] = array('class' => 'WFForm', 'children' => array('search' => array('class' => 'WFSubmit', 'properties' => array('label' => 'Search')), 'clear' => array('class' => 'WFSubmit', 'properties' => array('label' => 'Clear')), 'paginatorState' => array('class' => 'WFPaginatorState', 'properties' => array('paginator' => '#module#paginator')), 'query' => array('class' => 'WFTextField')));
     $listYaml['paginatorNavigation'] = array('class' => 'WFPaginatorNavigation', 'properties' => array('paginator' => '#module#paginator'));
     $listYaml['paginatorPageInfo'] = array('class' => 'WFPaginatorPageInfo', 'properties' => array('paginator' => '#module#paginator'));
     $descriptiveColumnName = $entity->valueForKey('descriptiveColumnName');
     $listYaml[$descriptiveColumnName] = array('class' => 'WFDynamic', 'properties' => array('arrayController' => "#module#{$sharedEntityId}"), 'children' => array("{$descriptiveColumnName}Prototype" => array('class' => 'WFLink', 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => '#current#', 'modelKeyPath' => $entity->valueForKey('primaryKeyProperty'), 'options' => array('ValuePattern' => $this->modulePath . '/detail/%1%')), 'label' => array('instanceID' => $sharedEntityId, 'controllerKey' => '#current#', 'modelKeyPath' => $entity->valueForKey('descriptiveColumnName'))))));
     $listYaml['editLink'] = array('class' => 'WFDynamic', 'properties' => array('arrayController' => "#module#{$sharedEntityId}"), 'children' => array("editLinkPrototype" => array('class' => 'WFLink', 'properties' => array('label' => 'Edit'), 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => '#current#', 'modelKeyPath' => $entity->valueForKey('primaryKeyProperty'), 'options' => array('ValuePattern' => $this->modulePath . '/edit/%1%'))))));
     $listYaml['deleteLink'] = array('class' => 'WFDynamic', 'properties' => array('arrayController' => "#module#{$sharedEntityId}"), 'children' => array("deleteLinkPrototype" => array('class' => 'WFLink', 'properties' => array('label' => 'Delete'), 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => '#current#', 'modelKeyPath' => $entity->valueForKey('primaryKeyProperty'), 'options' => array('ValuePattern' => $this->modulePath . '/confirmDelete/%1%'))))));
     file_put_contents($moduleDir . '/list.yaml', WFYaml::dump($listYaml));
     // build list.tpl
     $this->smarty->assign('listFormId', $listFormId);
     file_put_contents($moduleDir . '/list.tpl', $this->smarty->fetch(FRAMEWORK_DIR . '/framework/generator/list.tpl'));
     // build edit page
     // build edit.yaml
     $editYaml = array();
     $editFormId = 'edit' . $entity->valueForKey('name') . 'Form';
     $editYaml[$editFormId] = array('class' => 'WFForm', 'children' => array());
     $widgets = array();
     foreach ($entity->getProperties() as $property) {
         $widgetID = $property->valueForKey('name');
         $widgets[$widgetID] = $property;
         if ($property->valueForKey('name') === $entity->valueForKey('primaryKeyProperty')) {
             $class = 'WFHidden';
         } else {
             switch ($property->valueForKey('type')) {
                 case WFModelEntityProperty::TYPE_TEXT:
                     $class = 'WFTextArea';
                     break;
                 case WFModelEntityProperty::TYPE_NUMBER:
                 case WFModelEntityProperty::TYPE_STRING:
                 case WFModelEntityProperty::TYPE_DATETIME:
                 case WFModelEntityProperty::TYPE_TIME:
                 case WFModelEntityProperty::TYPE_DATE:
                     $class = 'WFTextField';
                     break;
                 case WFModelEntityProperty::TYPE_BOOLEAN:
                     $class = 'WFCheckbox';
                     break;
                 default:
                     $class = 'WFTextField';
             }
         }
         $editYaml[$editFormId]['children'][$widgetID] = array('class' => $class, 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => $widgetID)));
     }
     // status message
     $editYaml['statusMessage'] = array('class' => 'WFMessageBox');
     $editYaml[$editFormId]['children']['saveNew'] = array('class' => 'WFSubmit', 'properties' => array('label' => 'Create ' . $entity->valueForKey('name'), 'action' => 'save'), 'bindings' => array('hidden' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => 'isNew', 'options' => array('valueTransformer' => 'WFNegateBoolean'))));
     $editYaml[$editFormId]['children']['save'] = array('class' => 'WFSubmit', 'properties' => array('label' => 'Save'), 'bindings' => array('hidden' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => 'isNew')));
     $editYaml[$editFormId]['children']['deleteObj'] = array('class' => 'WFSubmit', 'properties' => array('label' => 'Delete'), 'bindings' => array('hidden' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => 'isNew')));
     file_put_contents($moduleDir . '/edit.yaml', WFYaml::dump($editYaml));
     // build edit.tpl
     $this->smarty->assign('editFormId', $editFormId);
     $this->smarty->assign('widgets', $widgets);
     file_put_contents($moduleDir . '/edit.tpl', $this->smarty->fetch(FRAMEWORK_DIR . '/framework/generator/edit.tpl'));
     // build confirmDelete page
     $confirmDeleteYaml = array();
     $confirmDeleteFormId = 'confirmDelete' . $entity->valueForKey('name') . 'Form';
     $pkId = $entity->valueForKey('primaryKeyProperty');
     $confirmDeleteYaml[$confirmDeleteFormId] = array('class' => 'WFForm', 'children' => array($pkId => array('class' => 'WFHidden', 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => $entity->valueForKey('primaryKeyProperty')))), 'cancel' => array('class' => 'WFSubmit', 'properties' => array('label' => 'Cancel')), 'deleteObj' => array('class' => 'WFSubmit', 'properties' => array('label' => 'Delete'))));
     $confirmDeleteYaml['confirmMessage'] = array('class' => 'WFMessageBox', 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => $descriptiveColumnName, 'options' => array('ValuePattern' => 'Are you sure you want to delete ' . $entity->valueForKey('name') . ' "%1%"?'))));
     file_put_contents($moduleDir . '/confirmDelete.yaml', WFYaml::dump($confirmDeleteYaml));
     // confirmDelete.tpl file
     $this->smarty->assign('confirmDeleteFormId', $confirmDeleteFormId);
     file_put_contents($moduleDir . '/confirmDelete.tpl', $this->smarty->fetch(FRAMEWORK_DIR . '/framework/generator/confirmDelete.tpl'));
     // delete success
     $deleteSuccessYaml = array();
     $deleteSuccessYaml['statusMessage'] = array('class' => 'WFMessageBox', 'properties' => array('value' => $entity->valueForKey('name') . ' successfully deleted.'));
     file_put_contents($moduleDir . '/deleteSuccess.yaml', WFYaml::dump($deleteSuccessYaml));
     file_put_contents($moduleDir . '/deleteSuccess.tpl', $this->smarty->fetch(FRAMEWORK_DIR . '/framework/generator/deleteSuccess.tpl'));
     // detail page
     $detailYaml = array();
     $widgets = array();
     foreach ($entity->getProperties() as $property) {
         $widgetID = $property->valueForKey('name');
         $widgets[$widgetID] = $property;
         $detailYaml[$widgetID] = array('class' => 'WFLabel', 'bindings' => array('value' => array('instanceID' => $sharedEntityId, 'controllerKey' => 'selection', 'modelKeyPath' => $widgetID)));
     }
     file_put_contents($moduleDir . '/detail.yaml', WFYaml::dump($detailYaml));
     // build detail.tpl
     $this->smarty->assign('widgets', $widgets);
     file_put_contents($moduleDir . '/detail.tpl', $this->smarty->fetch(FRAMEWORK_DIR . '/framework/generator/detail.tpl'));
 }