Exemplo n.º 1
0
 /**
  * Construct a new field
  *
  * @param Rabbit_Form $form
  * @param array $attributes
  */
 public function __construct(Rabbit_Form $form, array $attributes = array())
 {
     $this->form = $form;
     $this->form->addField($this);
     $this->setAttributes($attributes);
 }
Exemplo n.º 2
0
 /**
  * Prepare retrive data
  * 
  * This method generate retrive data based on config data
  *
  * @param array $config
  * @return array
  */
 public function prepare_retrieve(array $config, $page = 0)
 {
     //get code igniter
     $this->ci->load->database();
     $this->ci->load->helper('url');
     //initialize data
     $data = array();
     //base data
     $data['manage'] = $config['retrieve']['manage'];
     $data['delete'] = $config['retrieve']['delete'];
     $data['kfields'] = $config['retrieve']['fields'];
     //order
     $orderby = $config['retrieve']['orderby'];
     if ($orderby) {
         $orderby = sprintf('order by `%s`', $orderby);
     }
     //filters
     if (isset($config['retrieve']['filters'])) {
         $filters = 'where ' . implode(' and ', $config['retrieve']['filters']);
     } else {
         $filters = '';
     }
     //pagination
     if (isset($config['retrieve']['pagination']) && isset($config['retrieve']['pagination']['base_url'])) {
         $this->ci->load->library('pagination');
         $ptotal = $this->ci->db->query(sprintf('select count(*) as total from `%s` %s', $config['table'], $filters))->row_array();
         if (!isset($config['retrieve']['pagination']['per_page'])) {
             show_error("Rabbit forms: you need to configure per_page of pagination");
         }
         $config['retrieve']['pagination']['base_url'] = site_url($config['retrieve']['pagination']['base_url']);
         $config['retrieve']['pagination']['total_rows'] = $ptotal['total'];
         $this->ci->pagination->initialize($config['retrieve']['pagination']);
         $data['pagination'] = $this->ci->pagination->create_links();
         $pagination = sprintf('limit %s, %s', $page, $config['retrieve']['pagination']['per_page']);
     } else {
         $pagination = '';
     }
     //create form
     $form = new Rabbit_Form($config['table']);
     $form->setGenerateAssets($config['form']['automatic_assets']);
     $form->setPrimaryKey($config['primary_key']);
     //load field headers
     $fields = $config['retrieve']['fields'];
     $data['fields'] = array();
     foreach ($fields as $field) {
         $data['fields'][$field] = $config['fields'][$field]['label'];
     }
     //load fields skeleton
     $skeletons = array();
     foreach ($fields as $field) {
         $skeletons[$field] = Rabbit_Field_Factory::factory($config['fields'][$field]['type'], $form, isset($config['fields'][$field]['params']) ? $config['fields'][$field]['params'] : array());
         $skeletons[$field]->initialize();
     }
     //load rows of data
     $data['rows'] = array();
     $rows = $this->ci->db->query(sprintf('select `%s`, `%s` from `%s` %s %s %s', $config['primary_key'], implode('`,`', $fields), $config['table'], $filters, $orderby, $pagination))->result_array();
     foreach ($rows as $row) {
         $form->setEditId($row[$config['primary_key']]);
         $line = array();
         $line['rabbit_row_id'] = $row[$config['primary_key']];
         foreach ($skeletons as $field => $skeleton) {
             $skeleton->setRawValue($row[$field]);
             $line[$field] = $skeleton->getDisplayValue();
         }
         $data['rows'][] = $line;
     }
     return $data;
 }
Exemplo n.º 3
0
 /**
  * @see Rabbit_Form::addAsset()
  *
  * @param string $path
  */
 public function addAsset($path)
 {
     $this->parentForm->addAsset($path);
 }