示例#1
0
 private function _add($ds)
 {
     $data = $this->request->post();
     try {
         $type = $data['type'];
         unset($data['type']);
         $field = DataSource_Hybrid_Field::factory($type, $data);
         $field_id = DataSource_Hybrid_Field_Factory::create_field($ds->record(), $field);
     } catch (Validation_Exception $e) {
         Session::instance()->set('post_data', $this->request->post());
         Messages::errors($e->errors('validation'));
         $this->go_back();
     } catch (Kohana_Exception $e) {
         Messages::errors($e->getMessage());
         $this->go_back();
     }
     if (!$field_id) {
         $this->go_back();
     }
     Session::instance()->delete('post_data');
     if ($this->request->post('save_and_create') !== NULL) {
         $this->go(Route::get('datasources')->uri(array('controller' => 'field', 'directory' => 'hybrid', 'action' => 'add', 'id' => $ds->id())));
     } else {
         $this->go(Route::get('datasources')->uri(array('directory' => 'hybrid', 'controller' => 'field', 'action' => 'edit', 'id' => $field_id)));
     }
 }
示例#2
0
 /**
  * Получение списка объектов доступных в системе полей.
  * Используется в момент создания поля.
  * 
  * @return array array([TYPE] => [DataSource_Hybrid_Field], ... )
  */
 public static function get_empty_fields()
 {
     $filed_types = self::types();
     $fields = array();
     foreach ($filed_types as $type => $title) {
         if (is_array($title)) {
             foreach ($title as $type => $title) {
                 $fields[$type] = DataSource_Hybrid_Field::factory($type);
             }
         } else {
             $fields[$type] = DataSource_Hybrid_Field::factory($type);
         }
     }
     return $fields;
 }
示例#3
0
 public function onValidateDocument(Validation $validation, DataSource_Hybrid_Document $doc)
 {
     if ($this->min !== NULL or $this->max !== NULL) {
         $min = $this->min !== NULL ? $this->min : -99999999999;
         $max = $this->max !== NULL ? $this->max : 99999999999;
         $validation->rule($this->name, 'range', array(':value', $min, $max));
     }
     if (!empty($this->_props['regexp'])) {
         if (strpos($this->regexp, '::') !== FALSE) {
             list($class, $method) = explode('::', $this->regexp);
         } else {
             $class = 'Valid';
             $method = $this->regexp;
         }
         if (method_exists($class, $method)) {
             $validation->rule($this->name, array($class, $method));
         } else {
             $validation->rule($this->name, 'regex', array(':value', $this->regexp));
         }
     }
     return parent::onValidateDocument($validation, $doc);
 }
示例#4
0
文件: source.php 项目: ortodesign/cms
 public function __construct(array $data = NULL)
 {
     parent::__construct($data);
     $this->family = DataSource_Hybrid_Field::FAMILY_SOURCE;
 }
示例#5
0
文件: add.php 项目: ZerGabriel/cms-1
echo Form::select('type', DataSource_Hybrid_Field::types(), Arr::get($post_data, 'type'), array('id' => 'select-field-type'));
?>
			</div>
		</div>
	</div>
		
	<div class="panel-heading">
		<span class="panel-title"><?php 
echo __('Field settings');
?>
</span>
	</div>
	<div class="panel-body">
		<div id="field-options">
		<?php 
foreach (DataSource_Hybrid_Field::get_empty_fields() as $type => $field) {
    ?>
		<fieldset id="f-<?php 
    echo $type;
    ?>
" disabled="disabled">
		
		<?php 
    try {
        $field->set($post_data);
        echo View::factory('datasource/hybrid/field/edit/' . $type, array('field' => $field, 'sections' => $sections));
    } catch (Exception $exc) {
    }
    ?>
			<hr class="panel-wide" />
			
示例#6
0
<?php

$fields = DataSource_Hybrid_Field_Factory::get_section_fields($ds_id);
$order_fields = array();
foreach ($doc_order as $data) {
    $order_fields[key($data)] = $data[key($data)];
}
$selected_fields = array();
$available_fields = array();
$fields[] = DataSource_Hybrid_Field::factory('primitive_string', array('family' => DataSource_Hybrid_Field::FAMILY_PRIMITIVE, 'name' => 'header', 'id' => 'header', 'header' => __('Header')));
$fields[] = DataSource_Hybrid_Field::factory('primitive_integer', array('family' => DataSource_Hybrid_Field::FAMILY_PRIMITIVE, 'name' => 'id', 'id' => 'id', 'header' => __('ID')));
$fields[] = DataSource_Hybrid_Field::factory('primitive_datetime', array('family' => DataSource_Hybrid_Field::FAMILY_PRIMITIVE, 'name' => 'created_on', 'id' => 'created_on', 'header' => __('Created on')));
foreach ($fields as $field) {
    if (!$field->is_sortable()) {
        continue;
    }
    if (!isset($order_fields[$field->id])) {
        $available_fields[$field->id] = $field->header;
    } else {
        $ids[$field->id] = $field->header;
    }
}
foreach ($doc_order as $data) {
    if (isset($ids[key($data)])) {
        $selected_fields[key($data)] = ($data[key($data)] == Model_Widget_Decorator::ORDER_ASC ? '+' : '-') . ' ' . $ids[key($data)];
    }
}
?>
<script>
$(function() {
	var sf = $('#sf'),
示例#7
0
 /**
  * Обновление поля в таблице раздела
  * 
  * @param DataSource_Hybrid_Field $old
  * @param DataSource_Hybrid_Field $field
  * @return boolean
  */
 public static function alter_table_update_field(DataSource_Hybrid_Field $old, DataSource_Hybrid_Field $field)
 {
     $db = Database::instance();
     $params = array(':table' => DB::expr($db->quote_table($field->ds_table)), ':old_key' => DB::expr($db->quote_column($old->name)), ':new_key' => DB::expr($db->quote_column($field->name)), ':type' => DB::expr($field->get_type()), ':default' => DB::expr('DEFAULT ""'));
     if (isset($field->default)) {
         $params[':default'] = DB::expr('DEFAULT "' . $field->default_value() . '"');
     }
     return (bool) DB::query(NULL, 'ALTER TABLE :table CHANGE :old_key :new_key :type :default')->parameters($params)->execute();
 }