/**
  * Constructor
  * @param Form $form
  * @param \samson\activerecord\field $db_field
  * @param string $locale
  */
 public function __construct(Form &$form, &$db_field, $field_type)
 {
     // Set field header name
     $this->name = !empty($db_field->Description) ? $db_field->Description : $db_field->Name;
     // Save pointers to database field object
     $this->db_field =& $db_field;
     // Call parent
     parent::__construct($form);
     // Prepare locales array with one default locale by default
     $locales = array('');
     // If field supports localization - set full locales array
     if ($db_field->local == 1) {
         $locales = SamsonLocale::$locales;
     }
     // Iterate defined locales
     if (sizeof(SamsonLocale::$locales)) {
         foreach ($locales as $locale) {
             // Try to find existing CMSMaterialField record
             if (!dbQuery('\\samson\\cms\\CMSMaterialField')->MaterialID($form->material->id)->FieldID($db_field->id)->locale($locale)->first($db_mf)) {
                 // Create CMSMaterialField record
                 $db_mf = new \samson\cms\CMSMaterialField(false);
                 $db_mf->Active = 1;
                 $db_mf->MaterialID = $this->form->material->id;
                 $db_mf->FieldID = $db_field->id;
                 $db_mf->locale = $locale;
                 $db_mf->save();
             }
             //elapsed($this->name.'-'.$locale.'-'.$db_mf->Value.'-'.$db_mf->id);
             // Add child tab
             $this->tabs[] = new MaterialFieldTab($form, $this, $db_mf, $locale, $field_type);
         }
     }
 }
Пример #2
0
 /** @inheritdoc */
 public function __construct(RenderInterface $renderer, QueryInterface $query, Record $entity, \samson\activerecord\field $field)
 {
     $this->name = $field->Description != '' ? $field->Description : $field->Name;
     $this->id .= '_' . $field->Name;
     // Prepare locales array with one default locale by default
     $locales = array(null);
     // If field supports localization - set full locales array
     if ($field->local == 1) {
         $locales = SamsonLocale::$locales;
     }
     /** @var CMSMaterialField $materialField */
     $materialField = null;
     // Iterate defined locales
     if (sizeof(SamsonLocale::$locales)) {
         foreach ($locales as $locale) {
             // Try to find existing CMSMaterialField record
             if (!dbQuery('\\samson\\cms\\CMSMaterialField')->MaterialID($entity->id)->FieldID($field->id)->locale($locale)->first($materialField)) {
                 // Create CMSMaterialField record
                 $materialField = new \samson\cms\CMSMaterialField(false);
                 $materialField->Active = 1;
                 $materialField->MaterialID = $entity->id;
                 $materialField->FieldID = $field->id;
                 $materialField->locale = $locale;
                 $materialField->save();
             }
             // Add child tab
             $this->subTabs[] = new MaterialFieldLocalized($renderer, $query, $entity, $materialField, $locale);
         }
     }
     // Call parent constructor to define all class fields
     parent::__construct($renderer, $query, $entity);
     Event::fire('samsoncms.material.materialfieldtab.created', array(&$this, $field));
 }