Пример #1
0
 function __construct($app, $model, $q, $list_display = false, $list_display_links = false, $list_filter = false, $date_hierarchy = false, $search_fields = false, $list_per_page = false, $row_actions = false, $actions = false)
 {
     $this->app = $app;
     $this->model = $model;
     if (func_num_args() == 1) {
         $q = $app;
         preg_match('/FROM\\s[a-zA-Z\\\\]{3,30}/i', $q->getDQL(), $matches);
         $this->model = trim(str_replace('FROM', '', $matches[0]));
     }
     $site = \Pjango\Contrib\Admin\AdminSite::getInstance();
     $registry = $site->getRegistry();
     if ($this->app && $this->model) {
         if (isset($registry[$this->app][$this->model])) {
             $this->model_admin = new $registry[$this->app][$this->model]();
         }
     }
     if ($this->model_admin) {
         $this->list_display = $this->model_admin->list_display;
         $this->list_display_links = $this->model_admin->list_display_links;
         $this->list_filter = $this->model_admin->list_filter;
         $this->list_select_related = $this->model_admin->list_select_related;
         $this->list_per_page = $this->model_admin->list_per_page;
         $this->list_editable = $this->model_admin->list_editable;
         $this->search_fields = $this->model_admin->search_fields;
         $this->date_hierarchy = $this->model_admin->date_hierarchy;
         $this->save_as = $this->model_admin->save_as;
         $this->save_on_top = $this->model_admin->save_on_top;
         $this->ordering = $this->model_admin->ordering;
         $this->actions = $this->model_admin->actions;
         $this->row_actions = $this->model_admin->row_actions;
         $this->actions = $this->model_admin->actions;
     }
     if ($list_display) {
         $this->list_display = $list_display;
     }
     if ($list_display_links) {
         $this->list_display_links = $list_display_links;
     }
     if ($list_filter) {
         $this->list_filter = $list_filter;
     }
     if ($date_hierarchy) {
         $this->date_hierarchy = $date_hierarchy;
     }
     if ($search_fields) {
         $this->search_fields = $search_fields;
     }
     if ($row_actions) {
         $this->row_actions = $row_actions;
     }
     if ($list_per_page) {
         $this->list_per_page = $list_per_page;
     }
     if ($actions) {
         $this->actions = $actions;
     }
     if (is_array($this->list_filter)) {
         $this->has_filters = true;
     }
     //         $requestUri = parse_url($_SERVER['REQUEST_URI']);
     //         $queryString = $requestUri['query'];
     //         $params = array();
     //         if (strlen($queryString)>0){
     //             $pairs = explode("&", $queryString);
     //             foreach ($pairs as $pair) {
     //                 $nv = explode("=", $pair);
     //                 $name = urldecode($nv[0]);
     //                 $value = urldecode($nv[1]);
     //                 $params[$name] = $value;
     //             }
     //         }
     $this->params = $_GET;
     $this->query_set = $q;
     $this->query = isset($this->params[SEARCH_VAR]) ? $this->params[SEARCH_VAR] : '';
     $this->page_num = isset($this->params[PAGE_VAR]) ? $this->params[PAGE_VAR] : 1;
     $this->order_field = isset($this->params[ORDER_VAR]) ? $this->params[ORDER_VAR] : false;
     $this->order_type = isset($this->params[ORDER_TYPE_VAR]) ? $this->params[ORDER_TYPE_VAR] : false;
     $this->show_all = in_array(ALL_VAR, $this->params);
     $this->is_popup = in_array(IS_POPUP_VAR, $this->params);
     $this->to_field = isset($this->params[TO_FIELD_VAR]) ? $this->params[TO_FIELD_VAR] : false;
     foreach (array(ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR, TO_FIELD_VAR, IS_POPUP_VAR, ERROR_FLAG, LANG_VAR, RESPONSE_TYPE_VAR, SITE_VAR) as $value) {
         if (isset($this->params[$value])) {
             unset($this->params[$value]);
         }
     }
     $this->get_results();
 }
Пример #2
0
 function render($context, $stream)
 {
     $site = AdminSite::getInstance();
     $headerTemplate = '<li class="nav-header">%s</li>';
     $menuTemplate = '<li class="%s"><a href="%s">%s</a></li>';
     $currentMainMenuName = $context->resolve($this->args[0]);
     $currentMenuName = $context->resolve($this->args[1]);
     $currentSubMenuName = $context->resolve($this->args[2]);
     $site = AdminSite::getInstance();
     $registry = $site->getRegistry();
     $menuArr = array();
     foreach ($registry as $appName => $modelArr) {
         foreach ($modelArr as $modelName => $modelAdminClass) {
             if (is_string($modelAdminClass)) {
                 $modelAdmin = new $modelAdminClass();
                 if ($modelAdmin instanceof \Pjango\Core\ModelAdmin) {
                     if (is_array($modelAdmin->admin_menu) && $modelAdmin->admin_menu[0] == $currentMainMenuName) {
                         $menuArr = array_slice($modelAdmin->admin_menu, 3);
                     }
                     if (is_array($modelAdmin->apps_menu) && $modelAdmin->apps_menu[0] == $currentMainMenuName) {
                         $menuArr = array_slice($modelAdmin->apps_menu, 3);
                     }
                 }
             }
         }
     }
     $navArray = array();
     foreach ($menuArr as $menuItem) {
         $navArray[] = sprintf($headerTemplate, $menuItem[1]);
         if (count($menuItem) > 3) {
             $subMenuArr = array_slice($menuItem, 3);
             foreach ($subMenuArr as $subMenuItem) {
                 $subMenuName = $subMenuItem[0];
                 $subMenuUrl = pjango_ini_get('SITE_URL') . $subMenuItem[2];
                 $subMenuValue = $subMenuItem[1];
                 $currentSubMenuClass = '';
                 if ($subMenuName == $currentSubMenuName) {
                     $currentSubMenuClass = 'active';
                 }
                 $navArray[] = sprintf($menuTemplate, $currentSubMenuClass, $subMenuUrl, $subMenuValue);
             }
         }
     }
     $stream->write(implode('', $navArray));
 }
Пример #3
0
<?php

namespace Pjango\Core\Models;

use Pjango\Core\ModelAdmin;
class SiteAdmin extends ModelAdmin
{
    public function __construct()
    {
        $this->list_display = array('site_type', 'domain', 'name', 'status');
        $this->row_actions = array('edit', 'delete');
        $this->admin_menu = array('Core', pjango_gettext('Site'), '/admin/Core/Site/', array('Site', __('Site'), '/admin/Core/Site/', array('Site', __('Site List'), '/admin/Core/Site/')));
    }
}
class PjangoMediaAdmin extends ModelAdmin
{
    public function __construct()
    {
        $this->list_display = array('get_thumb_elem', 'file_name', 'file_type', 'is_default', 'created_at', 'updated_at');
        $this->actions = array('add');
        $this->row_actions = array('edit', 'delete');
        $this->ordering = '-created_at';
    }
}
$site = \Pjango\Contrib\Admin\AdminSite::getInstance();
$site->register('Core', 'PjangoMedia', 'Pjango\\Core\\Models\\PjangoMediaAdmin');
Пример #4
0
 function app_addchange($request, $app_label = false, $model = false, $id = false)
 {
     $templateArr = array('current_admin_menu' => $app_label, 'current_admin_submenu' => $app_label, 'current_admin_submenu2' => $model, 'title' => pjango_gettext($model . ' add'));
     $site = \Pjango\Contrib\Admin\AdminSite::getInstance();
     $contentType = ContentType::get_for_model($model, $app_label);
     $modelAdminClass = $site->_registry[$app_label][$model];
     $modelUrl = sprintf('%s/admin/%s/%s/', pjango_ini_get('SITE_URL'), $app_label, $model);
     $modelAdminClassArr = explode('\\', $modelAdminClass);
     $modelAdminClassArrTmp = array();
     for ($i = 0; $i < count($modelAdminClassArr) - 2; $i++) {
         $modelAdminClassArrTmp[] = $modelAdminClassArr[$i];
     }
     $formData = array();
     $formClass = sprintf("%s\\Forms\\%sForm", implode('\\', $modelAdminClassArrTmp), $model);
     $modelAdmin = new $modelAdminClass();
     $templateArr['extraheads'] = $modelAdmin->extraheads;
     if ($id) {
         $templateArr['title'] = __($model . ' Change');
         $modelObj = Doctrine_Query::create()->from($model . ' o')->where('o.id = ?', $id)->fetchOne();
         if ($modelObj) {
             if (method_exists($modelObj, 'toMyArray')) {
                 $formData = $modelObj->toMyArray();
             } else {
                 $formData = $modelObj->toArray();
             }
             $metaData = PjangoMeta::getMeta($contentType->id, $modelObj->id);
             foreach ($metaData as $metaDataItem) {
                 $formData[$metaDataItem->meta_key] = $metaDataItem->meta_value;
             }
         }
     }
     if ($request->POST) {
         $form = new $formClass($request->POST);
         try {
             if (!$form->is_valid()) {
                 throw new Exception(pjango_gettext('There are some errors, please correct them below.'));
             }
             $formData = $form->cleaned_data();
             if (!$modelObj) {
                 $modelObj = new $model();
             }
             // 	            if contains site_id field
             $formData['site_id'] = SITE_ID;
             // 	            if contains created_by and updated_by  field
             if ($modelObj->state() == Doctrine_Record::STATE_TCLEAN) {
                 $formData['created_by'] = $request->user->id;
             }
             $formData['updated_by'] = $request->user->id;
             if (method_exists($modelObj, 'fromMyArray')) {
                 $modelObj->fromMyArray($formData);
             } else {
                 $modelObj->fromArray($formData);
             }
             $modelObj->save();
             PjangoMeta::setMeta($contentType->id, $modelObj->id, false, $request->POST);
             Messages::Info('The operation completed successfully');
             HttpResponseRedirect("/admin/{$app_label}/{$model}/");
         } catch (Exception $e) {
             Messages::Error($e->getMessage());
         }
     }
     if (!$form) {
         $form = new $formClass($formData);
     }
     $templateArr['addchange_form'] = $form;
     if (is_file(sprintf('%s/templates/%s/admin/addchange.html', SITE_PATH, strtolower($app_label)))) {
         $templateFile = sprintf('%s/admin/addchange.html', strtolower($app_label));
     } else {
         if (is_file(sprintf('%s/apps/%s/Templates/%s/admin/addchange.html', APPLICATION_PATH, $app_label, strtolower($app_label)))) {
             $templateFile = sprintf('%s/admin/addchange.html', strtolower($app_label));
         } else {
             $templateFile = 'admin/addchange.html';
         }
     }
     $templateArr['third_level_navigation'] = $modelAdmin->get_third_level_navigation('edit', $modelUrl, $id);
     render_to_response($templateFile, $templateArr);
 }