Esempio n. 1
0
 /**
  * Initialize class and filter
  * 
  * @param array $options 
  */
 public function __construct($options = array())
 {
     if (isset($options['mode'])) {
         $this->mode = $options['mode'];
     }
     if (Config::FORM_MODE_CUSTOM == $this->mode) {
         $this->items = isset($options['elements']) ? $options['elements'] : array();
     } elseif (!empty($options['elements'])) {
         $this->items = $options['elements'];
     } else {
         $this->items = DraftEditForm::getDefaultElements($this->mode);
     }
     $filterParams = $this->getFilterParameters();
     foreach (array_keys($filterParams) as $name) {
         if (in_array($name, $this->items)) {
             $this->add($filterParams[$name]);
         }
     }
     $this->add($filterParams['id']);
     $this->add($filterParams['fake_id']);
     $this->add($filterParams['uid']);
     $this->add($filterParams['time_publish']);
     $this->add($filterParams['time_update']);
     $this->add($filterParams['time_submit']);
     $this->add($filterParams['article']);
     $this->add($filterParams['jump']);
 }
Esempio n. 2
0
 /**
  * Get draft form instance
  * 
  * @param string  $action   The action to request when forms are submitted
  * @param array   $options  Optional parameters
  * @return \Module\Article\Form\DraftEditForm 
  */
 protected function getDraftForm($action, $options = array())
 {
     $form = new DraftEditForm('draft', $options);
     $form->setAttributes(array('action' => $this->url('', array('action' => $action)), 'method' => 'post', 'enctype' => 'multipart/form-data'));
     return $form;
 }
Esempio n. 3
0
 /**
  * Preview draft edit page
  * 
  * @return ViewModel 
  */
 public function previewAction()
 {
     // Get elements
     $options = array();
     $mode = $this->params('mode', '');
     if (empty($mode)) {
         return $this->jumpTo404(_a('Invalid mode!'));
     }
     $options['mode'] = $mode;
     if ('custom' == $mode) {
         $elements = $this->params('elements', '');
         $options['elements'] = explode(',', $elements);
     } else {
         $options['elements'] = DraftEditForm::getDefaultElements($mode);
     }
     $form = new DraftEditForm('add', $options);
     // Get allowed categories
     $rules = Rule::getPermission();
     $listCategory = array();
     $approve = array();
     $delete = array();
     foreach ($rules as $key => $rule) {
         if (isset($rule['compose']) and $rule['compose']) {
             $listCategory[$key] = true;
         }
         if (isset($rule['approve']) and $rule['approve']) {
             $approve[] = $key;
         }
         if (isset($rule['approve-delete']) and $rule['approve-delete']) {
             $delete[] = $key;
         }
     }
     $categories = $form->get('category')->getValueOptions();
     $form->get('category')->setValueOptions(array_intersect_key($categories, $listCategory));
     $form->setData(array('category' => $this->config('default_category'), 'source' => $this->config('default_source'), 'fake_id' => uniqid(), 'uid' => Pi::user()->getId()));
     $module = $this->getModule();
     $this->view()->assign(array('form' => $form, 'config' => Pi::config('', $module), 'elements' => $options['elements'], 'rules' => $rules, 'approve' => $approve, 'delete' => $delete, 'status' => \Module\Article\Model\Draft::FIELD_STATUS_DRAFT, 'currentDelete' => true));
     $this->view()->setTemplate('draft-edit', $this->getModule(), 'front');
 }