Example #1
0
 public function get($key)
 {
     if ($key == 'id') {
         return 0;
     }
     if ($key == 'name') {
         return '';
     }
     return parent::get($key);
 }
Example #2
0
 /**
  * Check that the file matches the validator as specified by the field
  *
  * @param Field $field
  * @param string $destination
  * @return boolean
  */
 public function isValid(Field $field, $destination = NULL)
 {
     $this->valid = true;
     // Check if file name length will not exceed maximum allowed by Upload field's database column.
     // Upload field does not check that, so we have to do that here.
     if (!empty($destination)) {
         $this->valid = strlen($destination) < 255 ? true : false;
         if (!$this->valid) {
             $this->errors[] = __("Length of file name chosen in '%s' exceeds maximum allowed for that field.", array($field->get('label')));
         }
     }
     return $this->valid;
 }
 /**
  * Generates the html code of a checkbox/radio field
  *
  * @param Field $field
  *
  * @return string
  */
 private static function getRadioCheckHtml($field)
 {
     //Errors
     if ($field->error()) {
         $field->errorLabel->addClass('text-danger');
     }
     $html = $field->input->toHtml();
     $html = $field->label->toHtml($html . ' ') . $field->errorLabel;
     $html = Element::div(true)->class($field->input->attr('type'))->toHtml($html);
     //Help block
     if ($help = $field->get('help')) {
         $html .= Element::span(true)->class('help-block')->toHtml($help);
     }
     return $html;
 }
 /**
  * Given a Field and Entry object, this function will wrap
  * the Field's displayPublishPanel result with a div that
  * contains some contextual information such as the Field ID,
  * the Field handle and whether it is required or not.
  *
  * @param Field $field
  * @param Entry $entry
  * @return XMLElement
  */
 private function __wrapFieldWithDiv(Field $field, Entry $entry)
 {
     $div = new XMLElement('div', NULL, array('id' => 'field-' . $field->get('id'), 'class' => 'field field-' . $field->handle() . ($field->get('required') == 'yes' ? ' required' : '')));
     $field->displayPublishPanel($div, $entry->getData($field->get('id')), isset($this->_errors[$field->get('id')]) ? $this->_errors[$field->get('id')] : NULL, null, null, is_numeric($entry->get('id')) ? $entry->get('id') : NULL);
     return $div;
 }
 private function __wrapFieldWithDiv(Field $field, Entry $entry, $prefix = null, $postfix = null, $css = null)
 {
     $div = new XMLElement('div', NULL, array('class' => 'field field-' . $field->handle() . ($field->get('required') == 'yes' ? ' required' : '')));
     if ($css != null) {
         $div->setAttribute('style', $css);
     }
     $field->displayPublishPanel($div, $_POST['fields'][$field->get('element_name')], isset($this->_errors[$field->get('id')]) ? $this->_errors[$field->get('id')] : NULL, $prefix ? '[' . $prefix . ']' : null, null, is_numeric($entry->get('id')) ? $entry->get('id') : NULL);
     return $div;
 }
 public function registerField(Field $field)
 {
     self::$fields[$field->get('id')] = $field;
 }
 /**
  * Check whether the given `$field` will be hidden because it's been
  * prepopulated.
  *
  * @param  Field  $field
  * @return boolean
  */
 public function isFieldHidden(Field $field)
 {
     if ($field->get('hide_when_prepopulated') == 'yes') {
         if (isset($_REQUEST['prepopulate'])) {
             foreach ($_REQUEST['prepopulate'] as $field_id => $value) {
                 if ($field_id == $field->get('id')) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 public static function getRows($db, $filters = null, $page = 1, $sort = null)
 {
     //grab the model instance
     $model = $config->model;
     //update the config sort options
     $config->setSort($sort);
     $sort = $config->sort;
     //get things going by grouping the set
     $query = $model::group_by($model->table() . '.' . $model::$key);
     //set up initial array states for the selects
     //*************
     // the problem originated here
     // according to PostgreSQL if you want to select something you have to group your result by it (only if you using gruop by statement)
     // you can either get id and then get the rest of fields using id or you can put all columns of table in group_by statement
     // I chose the first approach
     // so i'm selecting just the id and then i will get the rest of row using id
     $selects = array(DB::raw($model->table() . '.' . $model::$key));
     //**************
     //then we set the filters
     if ($filters && is_array($filters)) {
         foreach ($filters as $filter) {
             if (!($fieldObject = Field::get($filter['field'], $filter, $config))) {
                 continue;
             }
             $fieldObject->filterQuery($query, $model);
         }
     }
     //determines if the sort should have the table prefixed to it
     $sortOnTable = true;
     //iterate over the columns to check if we need to join any values or add any extra columns
     foreach ($config->columns['columns'] as $field => $column) {
         //if this is a related column, we'll need to add some joins
         $column->filterQuery($query, $selects, $model);
         //if this is a related field or
         if (($column->isRelated || $column->select) && $column->field === $sort['field']) {
             $sortOnTable = false;
         }
     }
     //if the sort is on the model's table, prefix the table name to it
     if ($sortOnTable) {
         $sort['field'] = $model->table() . '.' . $sort['field'];
     }
     /**
      * We need to do our own pagination since there is a bug in the L3 paginator when using groupings :(
      * When L4 is released, this problem will go away and we'll be able to use the paginator again
      */
     //first get the sql sans selects
     $sql = $query->table->grammar->select($query->table);
     //then we need to round out the inner select
     $sql = "SELECT {$model->table()}.{$model::$key} " . $sql;
     //then wrap the inner table and perform the count
     $sql = "SELECT COUNT({$model::$key}) AS aggregate FROM ({$sql}) AS agg";
     //then perform the count query
     $results = $query->table->connection->query($sql, $query->table->bindings);
     $num_rows = $results[0]->aggregate;
     $page = (int) \Input::get('page', 1);
     $last = (int) ceil($num_rows / $config->rowsPerPage);
     //if the current page is greater than the last page, set the current page to the last page
     $page = $page > $last ? $last : $page;
     //now we need to limit and offset the rows in remembrance of our dear lost friend paginate()
     $query->take($config->rowsPerPage);
     $query->skip($config->rowsPerPage * ($page === 0 ? $page : $page - 1));
     //order the set by the model table's id
     $query->order_by($sort['field'], $sort['direction']);
     //then retrieve the rows
     $rows = $query->distinct()->get($selects);
     //*********
     // I also added this
     // here i got the rest of fields
     // I know you probebly asking why i didn't just join the query with table and be done with that
     // But that way it whoud not match the rest of code and I didn't want to mess with the rest of code
     for ($i = 0; $i < count($rows); $i++) {
         $rows[$i] = $model::find($rows[$i]->key);
     }
     //*********
     $results = array();
     //convert the resulting set into arrays
     foreach ($rows as $item) {
         //iterate over the included and related columns
         $onTableColumns = array_merge($config->columns['includedColumns'], $config->columns['relatedColumns']);
         $arr = array();
         foreach ($onTableColumns as $field => $col) {
             //if this column is in our objects array, render the output with the given value
             if (isset($config->columns['columnObjects'][$field])) {
                 $arr[$field] = $config->columns['columnObjects'][$field]->renderOutput($item->get_attribute($field));
             } else {
                 $arr[$field] = $item->get_attribute($field);
             }
         }
         //then grab the computed, unsortable columns
         foreach ($config->columns['computedColumns'] as $col) {
             $arr[$col] = $config->columns['columnObjects'][$col]->renderOutput($item->{$col});
         }
         $results[] = $arr;
     }
     return array('page' => $page, 'last' => $last, 'total' => $num_rows, 'results' => $results);
 }
 /**
  * Given a Field instance, the type of error, and the message, this function
  * creates an XMLElement node so that it can be added to the `?debug` for the
  * Event
  *
  * @since Symphony 2.5.0
  * @param Field $field
  * @param string $type
  *  At the moment 'missing' or 'invalid' accepted
  * @param string $message
  * @return XMLElement
  */
 public static function createError(Field $field, $type, $message = null)
 {
     $error = new XMLElement($field->get('element_name'), null, array('label' => General::sanitize($field->get('label')), 'type' => $type, 'message-id' => $type === 'missing' ? EventMessages::FIELD_MISSING : EventMessages::FIELD_INVALID, 'message' => General::sanitize($message)));
     return $error;
 }