/** * create templates defined in config * By default this method is not colled in this base class * Call it in descendant classes if needed * @return void */ protected function addCustomTemplates() { $o = new \CB\Objects\Template(); $tf = new \CB\Objects\TemplateField(); foreach ($this->cfg['templates'] as $k => $v) { echo "creating template '{$k}' .. "; $v['id'] = null; $v['pid'] = BBM::$cfg['templatesFolderId']; $v['template_id'] = BBM::$cfg['templatesTemplateId']; //create correct data if (empty($v['name'])) { $v['name'] = $k; } $type = empty($v['type']) ? 'object' : $v['type']; $data = array('_title' => $k, 'en' => $v['name'], 'type' => $type, 'visible' => 1); if (!empty($v['iconCls'])) { $data['iconCls'] = $v['iconCls']; } if (!empty($v['cfg'])) { $data['cfg'] = $v['cfg']; } if (!empty($v['title_template'])) { $data['title_template'] = $v['title_template']; } $v['data'] = $data; $fields = empty($v['fields']) ? array() : $v['fields']; unset($v['fields']); $id = $o->create($v); $this->templateIds[$k] = $id; // analize fields // ,'country' => array( // 'en' => 'Country' // ,'type' => '_objects' // ,'cfg' => array( // 'source' => 'tree' // ,'scope' => '/Country' // ) // ) $i = 1; foreach ($fields as $fn => $fv) { //check if we have field reference if (is_scalar($fv)) { $fn = $fv; $fv = $this->cfg['templateFields'][$fn]; } $fv['id'] = null; $fv['pid'] = $id; $fv['template_id'] = BBM::$cfg['fieldTemplateId']; $name = empty($fv['en']) ? $fn : $fv['en']; $type = empty($fv['type']) ? 'varchar' : $fv['type']; $order = empty($fv['order']) ? $i++ : $fv['order']; $data = array('name' => $fn, 'en' => $name, 'type' => $type, 'order' => $order); if (!empty($fv['solr_column_name'])) { $data['solr_column_name'] = $fv['solr_column_name']; } $cfg = empty($fv['cfg']) ? array() : $fv['cfg']; if (!empty($cfg['scope']) && substr($cfg['scope'], 0, 1) == '/') { $cfg['scope'] = $this->thesauriIds[$cfg['scope']]['id']; } if (!empty($cfg)) { $data['cfg'] = Util\jsonEncode($cfg); } $fv['name'] = $fn; $fv['type'] = $type; $fv['order'] = $order; $fv['data'] = $data; $tf->create($fv); } /* {"_title":"assigned" ,"en":"Assigned" ,"type":"_objects" ,"order":7 ,"cfg":"{ \"editor\": \"form\" ,\"source\": \"users\" ,\"renderer\": \"listObjIcons\" ,\"autoLoad\": true ,\"multiValued\": true ,\"hidePreview\": true\n}" } */ echo "Ok\n"; } }
/** * @dataProvider fieldsTeplateProvider */ public function testFieldsTemplateCRUD($data_field) { $tpl_obj = new \CB\Objects\Template(); $TPL_SQL = 'select id from tree where `name` like "Test fields CRUD" and pid = 3 and template_id = 11 limit 1'; $tpl_r = \CB\DB\dbQuery($TPL_SQL); if ($tpl = $tpl_r->fetch_assoc()) { $data_template['id'] = $tpl['id']; $this->assertTrue($data_template['id'] > 0, ' Error on load Template'); } else { // first add empty template $data_template = ["pid" => 3, "template_id" => 11, "type" => "object", "name" => "Test fields CRUD", "title" => "Test fields CRUD", 'l1' => "Test fields CRUD", 'l2' => "Test fields CRUD", 'l3' => "Test fields CRUD", 'l4' => "Test fields CRUD", 'order' => '1', 'visible' => '1', 'iconCls' => "icon-bell", "cfg" => ['createMethod' => 'inline', 'object_plugins' => ['objectProperties', 'comments', 'systemProperties']], "title_template" => "{name}"]; $data_template['id'] = $tpl_obj->create($data_template); $this->assertTrue($data_template['id'] > 0, ' Error on create Template'); } // CREATE FIELDS if (isset($data_template['id']) && $data_template['id'] > 0) { $data_field['pid'] = $data_template['id']; $obj_field = new \CB\Objects\TemplateField(); $data_field['id'] = $obj_field->create($data_field); $this->assertTrue($data_field['id'] > 0, ' Error on create Field'); } }