Exemplo n.º 1
0
 /**
  * Builds the correct view form for either adding or editing
  * a menu item, can also add in default values.
  *
  * @param int $cid
  * @param string $name
  * @param string $parentHeading
  * @param string $url
  * @param string $attrTitle
  * @param string $itemId
  * @return object
  */
 protected function buildItemForm($cid, $name = null, $parentHeading = 0, $url = null, $attrTitle = null, $itemId = null)
 {
     if (is_null($itemId)) {
         $op = 'add';
         $aclResource = 'menu-item';
     } else {
         $op = 'edit';
         $aclResource = 'menu-item-' . $itemId;
     }
     // Build form and validation
     $form = new View_Form('config/form_item.html', 'menu', is_null($itemId));
     $form->addElement('menu/id', $itemId, 'ID', new Validator_Int(), $op == 'edit');
     $form->addElement('menu/cat_id', $cid, 'Cat ID', new Validator_Int(), $op == 'add');
     $form->addElement('menu/name', $name, t('Name'), new Validator_Length(1, 64));
     $form->addElement('menu/parent', $parentHeading, t('Parent'), new Validator_Numeric());
     $form->addElement('menu/url', $url, 'URL', new Validator_Length(0, 255));
     $form->addElement('menu/attr_title', $attrTitle, t('Attribute Text'), new Validator_Length(0, 255));
     // Add additional vars
     $form->assign(array('OP' => $op, 'HEADINGS' => zula_array_flatten($this->_model()->getAllItems($cid), 'children')));
     $form->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View menu item') => $aclResource))));
     return $form;
 }
Exemplo n.º 2
0
 /**
  * Builds a form that allows users to add or edit a category
  * and can fill the values with default values
  *
  * @param string $title
  * @param string $desc
  * @param int $id
  * @return string
  */
 protected function buildCategoryForm($title = null, $desc = null, $id = null)
 {
     $op = is_null($id) ? 'add' : 'edit';
     $form = new View_Form('config/form_category.html', 'article', is_null($id));
     $form->action($this->_router->makeUrl('article', 'config', $op . 'cat', null, array('id' => $id)));
     $form->addElement('article/title', $title, t('Title'), new Validator_Length(1, 255));
     $form->addElement('article/description', $desc, t('Description'), new Validator_Length(0, 255));
     // Set op and other tags
     $form->assign(array('OP' => $op, 'ID' => $id));
     $resource = $op == 'edit' ? 'article-cat-' . $id : 'article-cat';
     $form->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View category') => $resource))));
     return $form;
 }
Exemplo n.º 3
0
 /**
  * Builds the form view that will allow users to add or edit a page.
  *
  * @param int $parent
  * @param int $id
  * @param string $title
  * @param string $body
  * @param bool $isQuickEdit
  * @return object
  */
 protected function buildForm($parent = null, $id = null, $title = null, $body = null, $isQuickEdit = false)
 {
     $parent = abs($parent);
     $validParents = array(0, $parent);
     if ($id === null) {
         $op = 'add';
     } else {
         $op = 'edit';
         /**
          * Gather all children and find out all possible parents that this page
          * can be part of, not including sub-children of its self.
          */
         $children = $this->_model()->getChildren($id);
         if ($parent) {
             $treePath = $this->_model()->findPath($id);
             $possibleParents = $this->_model()->getChildren($treePath[0]['id'], true, array($id));
             array_unshift($possibleParents, $treePath[0]);
         } else {
             $possibleParents = $this->_model()->getAllPages(0, 0, $parent);
         }
         foreach ($possibleParents as $key => $tmpParent) {
             if ($this->_acl->check('page-manage_' . $tmpParent['id']) && $tmpParent['id'] != $id) {
                 if (!isset($tmpParent['depth'])) {
                     $possibleParents[$key]['depth'] = 0;
                 }
                 $validParents[] = $tmpParent['id'];
             } else {
                 unset($possibleParents[$key]);
             }
         }
     }
     // Setup the correct ACL resources
     if ($id === null || $this->_acl->check('page-manage_' . $id)) {
         $aclForm = $this->_acl->buildForm(array(t('View page') => 'page-view_' . $id, t('Edit page') => array('page-edit_' . $id, 'group_admin'), t('Delete, edit, add subpages & manage permissions') => array('page-manage_' . $id, 'group_admin')));
     } else {
         $aclForm = null;
     }
     // Build up the form
     $form = new View_Form('config/form_page.html', 'page', $op == 'add');
     $form->addElement('page/id', $id, 'ID', new Validator_Int(), $op == 'edit');
     $form->addElement('page/title', $title, t('Title'), new Validator_Length(2, 255));
     $form->addElement('page/parent', $parent, t('Parent'), new Validator_InArray($validParents), !empty($parent));
     $form->addElement('page/body', $body, t('Body'), new Validator_Length(1, 50000));
     $form->assign(array('OP' => $op, 'PARENTS' => isset($possibleParents) ? $possibleParents : null, 'QUICK_EDIT' => $isQuickEdit));
     $form->assignHtml(array('ACL_FORM' => $aclForm, 'CHILDREN' => empty($children) ? null : $this->createChildRows($children)));
     return $form;
 }
Exemplo n.º 4
0
 /**
  * Builds form for adding or editing a media category
  *
  * @param int $cid
  * @param string $name
  * @param string $desc
  * @return object
  */
 protected function buildCatForm($cid = null, $name = null, $desc = null)
 {
     $form = new View_Form('config/form_cat.html', 'media', is_null($cid));
     $form->addElement('media/name', $name, t('Name'), new Validator_Length(1, 255));
     $form->addElement('media/desc', $desc, t('Description'), new Validator_Length(0, 255));
     // Add additional data on
     $form->assign(array('OP' => is_null($cid) ? 'add' : 'edit'));
     $aclForm = $this->_acl->buildForm(array(t('View Media Category') => 'media-cat_view_' . $cid, t('Upload media items') => array('media-cat_upload_' . $cid, 'group_admin'), t('Edit/Delete media items') => array('media-cat_moderate_' . $cid, 'group_admin')));
     $form->assignHtml(array('ACL_FORM' => $aclForm));
     return $form;
 }