Example #1
0
 /**
  * Pass all the component's fields to the view so we can render a grid
  * of information about them.
  */
 public function render()
 {
     $this->component->getPermissions()->haltIfNotAllowed('debug');
     $this->view->displayFields = new Fields();
     $this->view->componentFields = $this->component->getFields();
     return $this->renderView();
 }
Example #2
0
 /**
  * Get the processed SQL statement from the Listing, pretty print it, and
  * pass it to our view script.
  */
 public function render()
 {
     $this->component->getPermissions()->haltIfNotAllowed('debug');
     $select = $this->component->getListing()->getModifiedSelect($this->component->getFields());
     $this->view->formattedSql = SqlFormatter::format((string) $select);
     return $this->renderView();
 }
Example #3
0
 /**
  * When receiving a POST, get the row editor setup and then call its
  * delete() method.
  */
 public function process()
 {
     if ($this->request->isPost()) {
         $rowEditor = $this->component->getRowEditor();
         $rowEditor->link();
         $rowEditor->delete();
         $this->result = 'success';
     }
 }
Example #4
0
 /**
  * Assemble elements from the component and a Counter object and pass them along
  * to the view.
  */
 public function render()
 {
     $fields = $this->component->getFields();
     $selected = $fields->getVisibleFields()->getByQueryStringId($this->request->getQuery('group_field'));
     $counter = new Counter($selected, $fields, $this->component->getListing());
     $renderer = $this->view->csvCellRenderer();
     $this->component->setShouldRenderLayout(false);
     $this->view->assign(['title' => $this->component->getTitle(), 'selected' => $selected, 'fields' => $counter->buildRenderFields(), 'data' => $counter->fetchData($renderer), 'renderer' => $renderer]);
     return $this->renderView();
 }
Example #5
0
 /**
  * Ensure permissions are correctly set and then pass the component
  * along to the view.
  */
 public function render()
 {
     $this->component->getPermissions()->haltIfNotAllowed('export');
     $filters = [];
     if ($this->enableVisibilityFilter) {
         $filters[] = $this->getVisibilityFilter();
     }
     $filters[] = $this->component->getFieldGroupsFilter();
     $this->view->assign('component', $this->component)->assign('filters', $filters);
     return $this->renderView();
 }
 /**
  * Returns a page instance for the given name or false on failure
  *
  * @param string $name
  * @return \Dewdrop\Admin\Page\PageAbstract|false
  */
 public function createPage($name)
 {
     // Remain compatible with WP style naming
     $name = $this->component->getInflector()->hyphenize($name);
     if (array_key_exists($name, $this->pageClassMap)) {
         $pageClass = $this->pageClassMap[$name];
         $reflectedClass = new ReflectionClass($pageClass);
         return new $pageClass($this->component, $this->component->getRequest(), dirname($reflectedClass->getFileName()) . '/view-scripts');
     }
     return false;
 }
 /**
  * Perform the actual tests using a ListingSortTest object and pass the
  * results to our view for rendering.
  */
 public function render()
 {
     $this->component->getPermissions()->haltIfNotAllowed('debug');
     $tester = new ListingSortTest($this->component->getFields(), $this->component->getListing());
     $reflection = new ReflectionClass($this->component);
     $this->view->namespace = $reflection->getNamespaceName();
     $this->view->component = $this->component;
     $this->view->results = $tester->run();
     $this->view->displayFields = new Fields();
     $this->view->componentFields = $this->component->getFields();
     return $this->renderView();
 }
 /**
  * Grab the selected visible columns from POST and save them back to
  * the visibility filter.
  *
  * @param ResponseHelper $responseHelper
  */
 public function process(ResponseHelper $responseHelper)
 {
     $this->component->getPermissions()->haltIfNotAllowed('adjust-columns');
     $selections = $this->request->getPost('visible_columns');
     $applyToAllUsers = (bool) $this->request->getPost('apply_to_all_users', false);
     if (is_array($selections)) {
         /* @var $filter VisibilityFilter */
         $filter = $this->component->getVisibilityFilter();
         $filter->save($this->component->getFields(), $selections, $applyToAllUsers);
     }
     $responseHelper->redirectToAdminPage('index');
 }
Example #9
0
 public function render()
 {
     $handler = $this->component->getActivityLogHandler();
     $currentPage = $this->request->getQuery('listing-page', 1);
     $criteria = ['handlers' => $handler, 'limit' => $this->pageSize, 'offset' => ($currentPage - 1) * $this->pageSize];
     if ($this->request->getQuery('id')) {
         $entity = $handler->createEntity($this->request->getQuery('id'));
         $criteria['entities'] = $entity;
         $this->view->assign('entity', $entity);
     }
     $entries = $this->getActivityLog()->getEntries($criteria);
     $this->view->assign('entries', $entries)->assign('title', $this->component->getTitle())->assign('entryCount', $entries->getTotalCount())->assign('pageSize', $this->pageSize)->assign('currentPage', $currentPage);
 }
 public function render()
 {
     $this->component->getPermissions()->haltIfNotAllowed('create');
     $renderer = $this->view->editControlRenderer();
     $rowEditor = $this->component->getRowEditor();
     $field = $this->component->getFields()->get($this->request->getQuery('field'));
     $value = $this->request->getQuery('value');
     $rowEditor->link();
     if ($field instanceof ManyToManyField) {
         $field->setValue([$value]);
     } else {
         $field->setValue($value);
     }
     $this->component->setShouldRenderLayout(false);
     return $renderer->getControlRenderer()->render($field, 0);
 }
Example #11
0
 public function getPrimaryRowName()
 {
     if (!$this->primaryRowName) {
         $this->primaryRowName = $this->component->getPrimaryModel()->getTableName();
     }
     return $this->primaryRowName;
 }
Example #12
0
 protected function logActivity(RowEditor $rowEditor)
 {
     $model = $this->component->getPrimaryModel();
     $rows = $rowEditor->getRows();
     $id = null;
     /* @var $row \Dewdrop\Db\Row */
     foreach ($rows as $row) {
         if ($row->getTable() === $model) {
             $id = $row->get(current($model->getPrimaryKey()));
         }
     }
     if ($id) {
         /* @var $handler \Dewdrop\ActivityLog\Handler\CrudHandlerAbstract */
         $handler = $this->component->getActivityLogHandler();
         $handler->restore($id);
     }
 }
Example #13
0
 public function getUploadPath()
 {
     if (!$this->uploadPath) {
         /* @var $paths \Dewdrop\Paths */
         $paths = Pimple::getResource('paths');
         $root = $paths->getAppRoot();
         $this->uploadPath = $root . '/private-uploads/dewdrop-import/' . str_replace('/', '__', $this->component->getFullyQualifiedName());
     }
     return $this->uploadPath;
 }
Example #14
0
 /**
  * Pass a whole log of stuff into the view.
  */
 public function render()
 {
     $fields = $this->component->getFields();
     $listing = $this->component->getListing();
     $filter = $this->component->getVisibilityFilter();
     $this->view->assign(['component' => $this->component, 'permissions' => $this->component->getPermissions(), 'singularTitle' => $this->component->getPrimaryModel()->getSingularTitle(), 'pluralTitle' => $this->component->getPrimaryModel()->getPluralTitle(), 'listing' => $listing, 'visibilityFilter' => $filter, 'groupingFilter' => $this->component->getFieldGroupsFilter(), 'fields' => $fields, 'debug' => Pimple::getResource('debug'), 'isSortable' => $this->component instanceof SortableListingInterface, 'page' => $this, 'createUrl' => $this->getCreateUrl()]);
     if ($this->component instanceof BulkActionProcessorInterface) {
         $this->view->assign(['bulkActions' => $this->component->getBulkActions(), 'bulkActionFailureMessage' => $this->bulkActionFailureMessage]);
     }
     return $this->renderView();
 }
Example #15
0
 /**
  * Pass a bunch of dependencies to the View.
  */
 public function render()
 {
     $listing = $this->component->getListing();
     $id = $this->request->getQuery($listing->getPrimaryKey()->getName());
     $fields = $this->component->getFields()->getVisibleFields();
     $data = $this->component->getListing()->fetchRow($fields, $id);
     $primaryKey = $this->component->getPrimaryModel()->getPrimaryKey();
     $params = array();
     foreach ($primaryKey as $field) {
         $params[$field] = $this->request->getQuery($field);
     }
     $this->view->assign(['params' => $params, 'fields' => $fields, 'singularTitle' => $this->component->getPrimaryModel()->getSingularTitle(), 'data' => $data, 'id' => $id, 'groupingFilter' => $this->component->getFieldGroupsFilter(), 'permissions' => $this->component->getPermissions(), 'isAjax' => $this->request->isAjax()]);
     // When requested over XHR, turn off the layout (admin shell chrome)
     if ($this->request->isAjax()) {
         $this->component->setShouldRenderLayout(false);
     }
     return $this->renderView();
 }
Example #16
0
 /**
  * Setup notification fields and pass various dependencies to the View.
  */
 public function render()
 {
     $gateway = new NotificationGateway($this->component->getDb());
     $select = $gateway->selectByComponent($this->component->getFullyQualifiedName());
     $fields = $gateway->buildFields($this->component->url('notification-edit'), $this->component->getFields());
     $this->view->assign(['fields' => $fields, 'listing' => new Listing($select, $gateway->field('dewdrop_notification_subscription_id')), 'component' => $this->component, 'componentModel' => $this->component->getPrimaryModel()]);
     return $this->renderView();
 }
Example #17
0
 /**
  * Save newly POSTed sort order for the listing.
  *
  * @param ResponseHelper $responseHelper
  */
 public function process(ResponseHelper $responseHelper)
 {
     if (!$this->request->isPost()) {
         $this->error = ['result' => 'error', 'message' => 'Must be POST.'];
         return;
     }
     if (!is_array($this->request->getPost('sort_order'))) {
         $this->error = ['result' => 'error', 'message' => 'sort_order array not available.'];
         return;
     }
     $listing = $this->component->getListing();
     $primaryKey = $listing->getPrimaryKey();
     $model = $primaryKey->getTable();
     $dbAdapter = $model->getAdapter();
     $sortField = $this->component->getSortField();
     foreach ($this->request->getPost('sort_order') as $index => $id) {
         try {
             $model->update(array($sortField->getName() => $index), $dbAdapter->quoteInto("{$primaryKey->getName()} = ?", $id));
         } catch (Exception $e) {
             $this->error = ['result' => 'error', 'message' => 'Failed to save.'];
         }
     }
 }
Example #18
0
 /**
  * Assemble elements from the component and a Counter object and pass them along
  * to the view.
  */
 public function render()
 {
     $fields = $this->component->getFields();
     $selected = null;
     $counter = null;
     $renderer = $this->view->tableCellRenderer();
     if ($this->request->getQuery('group_field')) {
         $selected = $fields->getVisibleFields()->getByQueryStringId($this->request->getQuery('group_field'));
         $counter = new Counter($selected, $fields, $this->component->getListing());
     }
     $this->view->assign(['title' => $this->component->getTitle(), 'model' => $this->component->getPrimaryModel(), 'fields' => $this->component->getFields(), 'listing' => $this->component->getListing(), 'renderer' => $renderer, 'selectedField' => $selected ? $selected->getQueryStringId() : null, 'countFields' => $counter ? $counter->buildRenderFields() : null, 'data' => $selected ? $counter->fetchData($renderer) : [], 'request' => $this->request]);
     return $this->renderView();
 }
Example #19
0
 /**
  * Pass a bunch of dependencies to the View.
  */
 public function render()
 {
     $listing = $this->component->getListing();
     $id = $this->request->getQuery($listing->getPrimaryKey()->getName());
     $fields = $this->component->getFields()->getVisibleFields();
     if ($this->component->getPermissions()->can('restore') && $listing->hasSelectModifier('SelectDeletedRecords')) {
         /* @var $deletedRecordsModifier \Dewdrop\Fields\Helper\SelectDeletedRecords */
         $deletedRecordsModifier = $listing->getSelectModifierByName('SelectDeletedRecords');
         $deletedRecordsModifier->disable();
     }
     $data = $listing->fetchRow($fields, $id);
     $primaryKey = $this->component->getPrimaryModel()->getPrimaryKey();
     $params = array();
     foreach ($primaryKey as $field) {
         $params[$field] = $this->request->getQuery($field);
     }
     $this->view->assign(['params' => $params, 'fields' => $fields, 'singularTitle' => $this->component->getPrimaryModel()->getSingularTitle(), 'data' => $data, 'id' => $id, 'groupingFilter' => $this->component->getFieldGroupsFilter(), 'permissions' => $this->component->getPermissions(), 'isAjax' => $this->request->isAjax()]);
     // When requested over XHR, turn off the layout (admin shell chrome)
     if ($this->request->isAjax()) {
         $this->component->setShouldRenderLayout(false);
     }
     return $this->renderView();
 }
 /**
  * Pass dependencies into the View.
  */
 public function render()
 {
     $this->view->assign(['component' => $this->component, 'componentModel' => $this->component->getPrimaryModel(), 'fields' => $this->fields, 'rowEditor' => $this->rowEditor, 'breadcrumbTitle' => $this->rowEditor->isNew() ? 'Add' : 'Edit']);
     return $this->renderView();
 }
Example #21
0
 /**
  * Register a number of permissions that we make available on CrudInterface
  * components.
  *
  * @param CrudInterface $component
  * @return $this
  */
 public function registerAndSetDefaultsForCrudInterface(CrudInterface $component)
 {
     $plural = strtolower($component->getPrimaryModel()->getPluralTitle());
     $singular = strtolower($component->getPrimaryModel()->getSingularTitle());
     $crudPermissions = array('adjust-columns' => 'Adjust the columns that are visible on the main listing', 'create' => "Create new {$plural}", 'delete' => "Delete {$plural}", 'custom-views' => 'Create and edit custom views', 'debug' => 'Use debugging tools', 'edit' => "Edit existing {$plural}", 'export' => 'Export data to a file', 'filter' => "Filter {$plural}", 'import' => 'Import data from a file', 'count-fields' => "Count {$plural} while grouping by fields", 'restore' => "Restore deleted {$plural}", 'sort-fields' => "Sort and group {$singular} fields", 'notifications' => "Subscribe to be notified when {$plural} are added or updated", 'view' => "See an individual {$singular} in detail", 'view-activity' => 'View recent activity', 'view-listing' => "See the full {$plural} listing");
     foreach ($crudPermissions as $name => $description) {
         $this->register($name, $description)->set($name, true);
     }
     // These features are disabled by default.  Can be turned on whenever they're wanted.
     $this->set('count-fields', false);
     $this->set('import', false);
     $this->set('restore', false);
     $this->set('view-activity', false);
     // @ todo Re-enable these pages once they're complete
     $this->set('custom-views', false);
     $this->set('notifications', false);
     $this->set('debug', $this->debug);
     return $this;
 }
Example #22
0
 public function render()
 {
     $this->view->assign(['title' => $this->component->getTitle(), 'model' => $this->component->getPrimaryModel(), 'dataCopier' => $this->component->getDataCopier()]);
 }
Example #23
0
 public function renderAjaxForm()
 {
     $this->assignDefaultViewArguments();
     $this->component->setShouldRenderLayout(false);
     return $this->view->render('edit-fields-for-ajax.phtml');
 }
Example #24
0
 /**
  * Pass some dependencies into the View.
  */
 public function render()
 {
     $this->view->assign(['fieldGroups' => $this->filter->getConfigForFields($this->component->getFields()), 'component' => $this->component, 'fields' => $this->component->getFields()]);
     return $this->renderView();
 }
 /**
  * Render a filter form for the provided CrudInterface admin component.
  *
  * @param CrudInterface $component
  * @return string
  */
 public function directWithComponent(CrudInterface $component)
 {
     return $this->directWithArgs($component->getFields()->getFilterableFields($component->getFieldGroupsFilter()), $component->getListing()->getSelectModifierByName('SelectFilter'), $component->getPrimaryModel()->getPluralTitle());
 }