public function edit($id = 0, $objectID = 0) { $this->set('category', $this->CategoryProduct->findById($objectID)); if ($this->request->is('post') || $this->request->is('put')) { if ($id) { $this->request->data('PMFormField.id', $id); } else { $this->request->data('PMFormField.object_type', 'CategoryParam'); $this->request->data('PMFormField.object_id', $objectID); } if ($this->PMFormField->save($this->request->data)) { $id = $this->PMFormField->id; if ($this->request->is('post')) { $this->PMFormKey->save(array('form_id' => 1, 'field_id' => $id)); } $baseRoute = array('action' => 'index', $objectID); return $this->redirect($this->request->data('apply') ? $baseRoute : array($id, $objectID)); } } elseif ($id) { $field = $this->PMFormField->findById($id); $this->request->data = $field; } if (!$id) { $this->request->data('PMFormField.sort_order', '1'); } $this->set('aFieldTypes', FieldTypes::getTypes()); $this->set('PMFormField__SELECT', FieldTypes::SELECT); $this->set('PMFormField__MULTISELECT', FieldTypes::MULTISELECT); $this->set('PMFormField__FORMULA', FieldTypes::FORMULA); }
public function beforeRender() { parent::beforeRender(); // $this->set('objectType', 'Param'); $this->set('aFieldTypes', FieldTypes::getTypes()); $category = $this->Category->findById($this->parentArticle['ParamGroup']['parent_id']); $this->set('category', $category); }
public function afterSave($created, $options = array()) { $this->loadModel('Form.PMFormData'); $sql_field = sprintf(FieldTypes::getSqlTypes($this->data['PMFormField']['field_type']), $this->id); $created = $created || isset($options['forceCreate']) && $options['forceCreate']; $sql = 'ALTER TABLE ' . $this->PMFormData->getTableName() . ($created ? ' ADD ' : ' MODIFY ') . $sql_field; fdebug($sql . "\r\n", 'form_field.log'); $this->query($sql); }
public function update4() { $this->loadModel('Form.FormField'); $this->loadModel('Form.PMFormValue'); $this->loadModel('Form.PMFormField'); $this->loadModel('Form.PMFormData'); $this->loadModel('SiteArticle'); // пересохраняем поля, чтобы создать form_data $aRowset = Hash::combine($this->FormField->find('all'), '{n}.FormField.id', '{n}.FormField'); foreach ($aRowset as $formField) { if (!FieldTypes::getSqlTypes($formField['field_type'])) { echo 'Error! Unexisted field type: ' . $formField['id'] . ' - ' . $formField['field_type'] . '<br>'; $formField['field_type'] = FieldTypes::STRING; } $this->PMFormField->save($formField, array('forceCreate' => true)); } echo 'Processed ' . count($aRowset) . ' form fields<br>'; $conditions = array('object_type' => 'Product'); $page = 1; $limit = 10; $order = 'SiteArticle.id'; $count = array('Product' => 0, 'Param' => 0); while ($articles = $this->SiteArticle->find('all', compact('conditions', 'page', 'limit', 'order'))) { $page++; foreach ($articles as $article) { $count['Product']++; $id = $article['SiteArticle']['id']; $formValues = $this->PMFormValue->getValues('ProductParam', $id); $formData = Hash::combine($formValues, '{n}.PMFormValue.field_id', '{n}.PMFormValue.value'); $data = array('object_type' => 'ProductParam', 'object_id' => $id); foreach ($aRowset as $id => $field) { $count['Param']++; if (isset($formData[$id])) { $data['fk_' . $id] = $formData[$id]; $data['fk_' . $id] = str_replace(' ', '', $data['fk_' . $id]); if ($field['field_type'] == FieldTypes::INT) { $data['fk_' . $id] = intval($data['fk_' . $id]); } elseif ($field['field_type'] == FieldTypes::FLOAT) { if ($id == 10) { if (trim($data['fk_' . $id]) === '') { $data['fk_' . $id] = 0.01; } } $data['fk_' . $id] = floatval(str_replace(',', '.', $data['fk_' . $id])); } } } $this->PMFormData->clear(); $this->PMFormData->save(array('PMFormData' => $data)); } } echo 'Processed ' . $count['Product'] . ' products, ' . $count['Param'] . ' params <br>'; }
<?php $this->load->model('form'); $types = FieldTypes::getArray(); $fld_name = 'fields[' . $index . ']'; ?> <li id="field<?php echo $index; ?> " class="field"> <?php echo form_hidden($fld_name . '[id]', set_value($fld_name . '[id]', 0)); ?> <span class="form_index"><?php echo form_hidden($fld_name . '[index]', set_value($fld_name . '[index]', $index)); ?> </span> <?php echo form_label('Field Name', 'name' . $index, array('class' => 'field_label')); echo form_error('fields[' . $index . '][name]'); echo form_input($fld_name . '[name]', set_value($fld_name . '[name]'), 'id="name' . $index . '" size="50"'); ?> <div class="field_arrows"> <a class="up_arrow" href="#">↑</a> <a class="down_arrow" href="#">↓</a> </div> <a class="delete_btn delete_field" href="#">Delete Field</a> <?php echo form_label('Help Text', 'description' . $index, array('class' => 'field_label'));
/** * values for types dropdowan * @param integer $keyValue key * @return array */ public function getTypeIdOptions($keyValue = 1) { return FieldTypes::lists('name', 'id'); }
public function _fieldTypeCheck($type) { $this->load->model('form'); $this->form_validation->set_message('_fieldTypeCheck', 'Invalid field type.'); return FieldTypes::isValid($type); }