예제 #1
0
    public function proceed()
    {
        $rtn = "\n  // proceed for \$" . $this->name . "\n";
        $rtn .= '  $object->set' . format_as_class_name($this->name) . '($' . $this->name . ');
';
        return $rtn;
    }
예제 #2
0
function build_form($model, $override = false)
{
    global $enabled_modules;
    // check each module's schema.yml file, see if we can find a form for the model to build
    foreach ($enabled_modules as $module) {
        if (is_file(MODULESROOT . DS . $module . DS . 'schema.yml')) {
            $schemas = load_fixture($module, 'schema.yml');
            // when found, build the form
            if (array_key_exists($model, $schemas)) {
                $schema = $schemas[$model];
                if (isset($schema['form'])) {
                    // load form fields
                    $form_fields = array();
                    foreach ($schema['form']['fields'] as $field => $conf) {
                        $f = array();
                        $f['widget'] = $conf['widget'];
                        $f['widget_class'] = 'FormWidget' . format_as_class_name($conf['widget']);
                        $f['widget_conf'] = isset($conf['widget_conf']) ? $conf['widget_conf'] : array();
                        $form_fields[$field] = $f;
                    }
                    $module_path = MODULESROOT . DS . $module;
                    // create controllers folder if not exist
                    if (!is_dir($module_path . DS . 'controllers')) {
                        mkdir($module_path . DS . 'controllers');
                    }
                    if (!is_dir($module_path . DS . 'controllers' . DS . 'backend')) {
                        mkdir($module_path . DS . 'controllers' . DS . 'backend');
                    }
                    // create templates folder if not exist
                    if (!is_dir($module_path . DS . 'templates')) {
                        mkdir($module_path . DS . 'templates');
                    }
                    if (!is_dir($module_path . DS . 'templates' . DS . 'backend')) {
                        mkdir($module_path . DS . 'templates' . DS . 'backend');
                    }
                    // create routing.yml file if not exist
                    if (!is_file($module_path . DS . 'routing.yml')) {
                        touch($module_path . DS . 'routing.yml');
                        file_put_contents($module_path . DS . 'routing.yml', "routing:");
                    }
                    // create bootstrap.php file if not exist
                    if (!is_file($module_path . DS . 'bootstrap.php')) {
                        touch($module_path . DS . 'bootstrap.php');
                        file_put_contents($module_path . DS . 'bootstrap.php', "<?php\n");
                    }
                    // build bootstrap.php
                    $bootstrap = file_get_contents($module_path . DS . 'bootstrap.php');
                    if (strpos($bootstrap, "admin/{$model}/list") === false) {
                        echo " + module {$module}: add code snippet to bootstrap.php for model '{$model}'\n";
                        ob_start();
                        require MODULESROOT . DS . 'core' . DS . 'bootstrap.template.php';
                        $content = ob_get_clean();
                        file_put_contents($module_path . DS . 'bootstrap.php', $content, FILE_APPEND);
                    } else {
                        echo " > module {$module}: code snippet exists for model '{$model}'. skip\n";
                    }
                    // build routings.yml
                    $routing = file_get_contents($module_path . DS . 'routing.yml');
                    if (!preg_match('/admin_' . $model . '_list/', $routing)) {
                        ob_start();
                        require MODULESROOT . DS . 'core' . DS . 'routing.yml.php';
                        $content = ob_get_clean();
                        file_put_contents($module_path . DS . 'routing.yml', $content, FILE_APPEND);
                    }
                    $module;
                    $model;
                    $fields = array_keys($schema['fields']);
                    $form_fields;
                    $model_class = format_as_class_name($model);
                    $model_names = $schema['form']['names'];
                    // build controllers
                    foreach (array('list', 'delete', 'create', 'edit') as $controller) {
                        if ($override || !is_file($module_path . DS . 'controllers' . DS . 'backend' . DS . $model . "_{$controller}.php")) {
                            echo " + module {$module}: create controller '" . $model . "_{$controller}.php'\n";
                            ob_start();
                            require MODULESROOT . DS . 'core' . DS . 'controllers' . DS . 'backend' . DS . "{$controller}.template.php";
                            $content = "<?php\n" . ob_get_clean();
                            file_put_contents($module_path . DS . 'controllers' . DS . 'backend' . DS . $model . "_{$controller}.php", $content);
                        } else {
                            echo " > module {$module}: controller '" . $model . "_{$controller}.php' exists. skip\n";
                        }
                    }
                    // build templates
                    foreach (array('list', 'create', 'edit') as $template) {
                        Asset::clearDynamicAssets();
                        if ($override || !is_file($module_path . DS . 'templates' . DS . 'backend' . DS . $model . "_{$template}.tpl.php")) {
                            echo " + module {$module}: create template '" . $model . "_{$template}.tpl.php'\n";
                            ob_start();
                            require MODULESROOT . DS . 'core' . DS . 'templates' . DS . 'backend' . DS . "{$template}.tpl.template.php";
                            $content = ob_get_clean();
                            $content = str_replace('[[[', '<?php', $content);
                            $content = str_replace(']]]', '?>', $content);
                            file_put_contents($module_path . DS . 'templates' . DS . 'backend' . DS . $model . "_{$template}.tpl.php", $content);
                        } else {
                            echo " > module {$module}: template '" . $model . "_{$template}.tpl.php' exists. skip\n";
                        }
                    }
                    // build field controllers
                    foreach ($form_fields as $name => $field) {
                        $widget_conf = $field['widget_conf'];
                        // image field controllers
                        if ($field['widget'] == 'image') {
                            // image submission controller
                            $upload_dir = $widget_conf['upload_dir'];
                            $transform = isset($widget_conf['transform']) ? $widget_conf['transform'] : false;
                            if ($transform) {
                                $dimension = isset($transform['dimension']) ? explode("x", $transform['dimension']) : 0;
                                $refill = isset($transform['refill']) ? $transform['refill'] : 0;
                                $watermark = isset($transform['watermark']) ? $transform['watermark'] : 0;
                            }
                            if ($override || !is_file($module_path . DS . 'controllers' . DS . 'backend' . DS . $model . "_form_field_{$name}.php")) {
                                echo " + module {$module}: create form field controller '" . $model . "_form_field_{$name}.php'\n";
                                ob_start();
                                require MODULESROOT . DS . 'core' . DS . 'controllers' . DS . 'backend' . DS . "form_field_image.template.php";
                                $content = "<?php\n" . ob_get_clean();
                                file_put_contents($module_path . DS . 'controllers' . DS . 'backend' . DS . $model . "_form_field_{$name}.php", $content);
                            } else {
                                echo " > module {$module}: controller '" . $model . "_form_field_{$name}.php' exists. skip\n";
                            }
                            // image remove controller
                            if ($override || !is_file($module_path . DS . 'controllers' . DS . 'backend' . DS . $model . "_form_field_{$name}" . "_remove.php")) {
                                echo " + module {$module}: create form field remove controller '" . $model . "_form_field_{$name}" . "_remove.php'\n";
                                ob_start();
                                require MODULESROOT . DS . 'core' . DS . 'controllers' . DS . 'backend' . DS . "form_field_image_remove.template.php";
                                $content = "<?php\n" . ob_get_clean();
                                file_put_contents($module_path . DS . 'controllers' . DS . 'backend' . DS . $model . "_form_field_{$name}" . "_remove.php", $content);
                            } else {
                                echo " > module {$module}: controller '" . $model . "_form_field_{$name}" . "_remove.php' exists. skip\n";
                            }
                        }
                    }
                }
                return;
            }
        }
    }
}
예제 #3
0
    ?>
</th>
        <?php 
}
?>
        <th>Actions</th>
      </tr>
  </thead>
  <tbody>
    [[[ foreach ($objects as $object): ]]]
    <tr>
      <?php 
foreach ($fields as $field) {
    ?>
      <td>[[[ echo $object->get<?php 
    echo format_as_class_name($field);
    ?>
() ]]]</td>
      <?php 
}
?>
      <td>
        <div class="btn-group">
          <a class="btn btn-default btn-sm" href="[[[ echo uri('admin/<?php 
echo $model;
?>
/edit/' . $object->getId()); ]]]"><i class="fa fa-edit"></i></a>
          <a onclick="return confirm('[[[ echo i18n(array('en' => 'Are you sure to delete this record ?', 'zh' => '你确定删除这条记录吗 ?')); ]]]');" class="btn btn-default btn-sm" href="[[[ echo uri('admin/<?php 
echo $model;
?>
/delete/' . $object->getId(), false); ]]]"><i class="fa fa-remove"></i></a>
예제 #4
0
    public function proceed()
    {
        $rtn = "\n  // proceed for \$" . $this->name . "\n";
        $rtn .= '  $files = explode("\\n", trim($' . $this->name . '));
  $rtn = array();
  foreach ($files as $file) {
    $file = trim($file);
    // for cache file, we move it to its proper location 
    if (strpos($file, str_replace(WEBROOT . DS, "", CACHE_DIR)) === 0) {
      $oldname = WEBROOT . DS . $file;
      $newname = WEBROOT . DS . "' . $this->upload_dir . '" . str_replace(CACHE_DIR, "", WEBROOT . DS . $file);
      rename($oldname, $newname);
      $file = str_replace(WEBROOT . DS, "", $newname);
    }
    $rtn[] = $file;
  }
  $object->set' . format_as_class_name($this->name) . '(implode("\\n", $rtn));
';
        return $rtn;
    }
예제 #5
0
    ?>
() {
     return $this->getDbField<?php 
    echo ucfirst($field);
    ?>
();
   }
<?php 
    /** 
     * for i18n fields 
     */
    if (preg_match('/_en$/', $field)) {
        $tokens = explode('_', $field);
        $lang = array_pop($tokens);
        $base_field = implode('_', $tokens);
        $base_field_class_name = format_as_class_name($base_field);
        ?>
  public function set<?php 
        echo $base_field_class_name;
        ?>
($var, $lang = null) {
    $lang = is_null($lang) ? get_language() : $lang;
    
    $method = "set<?php 
        echo $base_field_class_name;
        ?>
" . ucfirst($lang);
    $this->{$method}($var);
  }
  public function get<?php 
        echo $base_field_class_name;