/**
  * 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();
 }
 /**
  * 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();
 }
Exemple #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';
     }
 }
 /**
  * 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();
 }
Exemple #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;
 }
Exemple #7
0
 public function createPage($name)
 {
     if ('upload' === $name) {
         $page = new UploadPage($this->component, $this->component->getRequest());
         foreach ($this->fileHandlers as $fileHandler) {
             $page->addFileHandler($fileHandler);
         }
         return $page;
     }
     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');
 }
 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);
 }
 public function getPrimaryRowName()
 {
     if (!$this->primaryRowName) {
         $this->primaryRowName = $this->component->getPrimaryModel()->getTableName();
     }
     return $this->primaryRowName;
 }
Exemple #13
0
 /**
  * Check to see if the given permission is granted to the current user (or
  * anonymous users, if no user resource is available in Pimple.  You can optionally
  * choose to just throw an exception to halt execution when the user doesn't
  * have the requested permission.  This can be convenient when the user
  * can only reach the point where this permission is checked by circumventing
  * the normal navigation provided in the UI (e.g. by manipulating the URL).
  *
  * @throws Exception
  * @param string $name
  * @param boolean $throwExceptionOnFail
  * @return boolean
  */
 public function can($name, $throwExceptionOnFail = false)
 {
     if (!array_key_exists($name, $this->registeredPermissions)) {
         throw new Exception("Could not find permission with name '{$name}'");
     }
     $can = $this->settings[$name];
     if (is_array($can)) {
         $allowedRoles = $can;
         $can = false;
         $user = null;
         if ($this->component->hasPimpleResource('user')) {
             $user = $this->component->getPimpleResource('user');
         }
         foreach ($allowedRoles as $role) {
             if ($user && in_array($role, $this->getUserRoleValues($user))) {
                 $can = true;
                 break;
             }
         }
     }
     if (!$can && $throwExceptionOnFail) {
         throw new Exception("Permission denied: {$this->component->getFullyQualifiedName()}/{$name}.");
     }
     return $can;
 }
Exemple #14
0
 /**
  * @return \Dewdrop\ActivityLog\Handler\TableHandler
  */
 public function getActivityLogHandler()
 {
     if (parent::getActivityLogHandler() instanceof ActivityLogNullHandler) {
         return $this->getPrimaryModel()->getActivityLogHandler();
     } else {
         return parent::getActivityLogHandler();
     }
 }
Exemple #15
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);
     }
 }
Exemple #16
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;
 }
Exemple #17
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();
 }
Exemple #18
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();
 }
 /**
  * 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();
 }
Exemple #20
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.'];
         }
     }
 }
Exemple #21
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();
 }
Exemple #22
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();
 }
 /**
  * Render the nav for the provided component.
  *
  * @param ComponentAbstract $component
  * @return string
  */
 public function direct(ComponentAbstract $component, array $options = [])
 {
     if ($component instanceof CrudInterface) {
         $singularTitle = $component->getPrimaryModel()->getSingularTitle();
     } else {
         $singularTitle = $component->getTitle();
     }
     if ($component instanceof CrudInterface) {
         $pluralTitle = $component->getPrimaryModel()->getPluralTitle();
     } else {
         $pluralTitle = $component->getTitle();
     }
     if (!isset($options['createUrl'])) {
         $options['createUrl'] = null;
     }
     return $this->partial('admin-component-nav.phtml', array('permissions' => $component->getPermissions(), 'singularTitle' => $singularTitle, 'pluralTitle' => $pluralTitle, 'createUrl' => $options['createUrl']));
 }
 /**
  * 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();
 }
 public function testCanConfigureTheComponentToNotRenderTheAdminLayout()
 {
     $this->assertTrue($this->component->shouldRenderLayout());
     $this->component->setShouldRenderLayout(false);
     $this->assertFalse($this->component->shouldRenderLayout());
 }
Exemple #26
0
 public function render()
 {
     $this->view->assign(['title' => $this->component->getTitle(), 'model' => $this->component->getPrimaryModel(), 'dataCopier' => $this->component->getDataCopier()]);
 }
Exemple #27
0
 public function renderAjaxForm()
 {
     $this->assignDefaultViewArguments();
     $this->component->setShouldRenderLayout(false);
     return $this->view->render('edit-fields-for-ajax.phtml');
 }
Exemple #28
0
 /**
  * Provide the component for which the pages will be created.
  *
  * @param ComponentAbstract $component
  */
 public function __construct(ComponentAbstract $component)
 {
     $this->component = $component;
     $this->inflector = $component->getInflector();
 }
 /**
  * Add a Crud page factory to the component so that all the stock CRUD
  * pages are available.
  *
  * @param Pimple $pimple
  * @param null $componentName
  */
 public function __construct(Pimple $pimple = null, $componentName = null)
 {
     parent::__construct($pimple, $componentName);
     $this->addPageFactory(new CrudFactory($this));
 }
Exemple #30
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();
 }