public function __construct(\samson\cms\CMSMaterial &$parent, $locale = 'ru')
 {
     $this->dbQuery = new dbQuery();
     // Retrieve pointer to current module for rendering
     $this->renderModule =& s()->module($this->renderModule);
     $this->locale = $locale;
     // Save pointer to CMSMaterial
     $this->parent =& $parent;
     // Get all child materials identifiers from parent
     $materialIDs = dbQuery('material')->cond('material.parent_id', $this->parent->id)->cond('material.Active', 1)->cond('material.Draft', 0)->fields('MaterialID');
     // Iterate all parent material structures
     foreach ($parent->cmsnavs() as $structure) {
         // Use only special structures
         if (isset($structure->type) && $structure->type == 1) {
             //$this->structures[$structure->id] = $structure;
             // Iterate all fields
             foreach ($structure->fields() as $field) {
                 // Use only localizable fields
                 if ($locale != '' && $field->local == 1 && !isset($this->fields[$field->id])) {
                     // Gather key => value fields collection
                     $this->fields[$field->id] = $field;
                     // Iterate all child materials
                     foreach ($materialIDs as $materialID) {
                         // Check if they already have this material field
                         if (!dbQuery('materialfield')->MaterialID($materialID)->locale($this->locale)->FieldID($field->id)->first()) {
                             // Create material field record
                             $mf = new \samson\activerecord\materialfield(false);
                             $mf->MaterialID = $materialID;
                             $mf->FieldID = $field->id;
                             $mf->Active = 1;
                             $mf->locale = $this->locale;
                             $mf->save();
                         }
                     }
                 } else {
                     if ($locale == '' && $field->local == 0 && !isset($this->fields[$field->id])) {
                         // Gather key => value fields collection
                         $this->fields[$field->id] = $field;
                         // Iterate all child materials
                         foreach ($materialIDs as $materialID) {
                             // Check if they already have this material field
                             if (!dbQuery('materialfield')->MaterialID($materialID)->locale($this->locale)->FieldID($field->id)->first()) {
                                 // Create material field record
                                 $mf = new \samson\activerecord\materialfield(false);
                                 $mf->MaterialID = $materialID;
                                 $mf->FieldID = $field->id;
                                 $mf->Active = 1;
                                 $mf->save();
                             }
                         }
                     }
                 }
             }
         }
     }
     // Get all child materials material fields for this locale
     $this->query = dbQuery('material')->parent_id($this->parent->id)->join('materialfield')->cond('materialfield_FieldID', array_keys($this->fields))->cond('materialfield_locale', $this->locale);
     // Constructor treed
     parent::__construct($this->query);
 }
Ejemplo n.º 2
0
 /** @see \samson\core\CompressableExternalModule::afterCompress() */
 public function afterCompress(&$obj = null, array &$code = null)
 {
     // Fill additional fields data to material db request data for automatic altering material request
     self::$fields = array();
     $t_name = '_mf';
     // Save original material attributes
     self::$materialAttributes =& Material::$_attributes;
     // Copy original material table attributes
     CMSMaterial::$_attributes = \samson\activerecord\Material::$_attributes;
     CMSMaterial::$_sql_select = \samson\activerecord\Material::$_sql_select;
     CMSMaterial::$_sql_from = \samson\activerecord\Material::$_sql_from;
     CMSMaterial::$_own_group = \samson\activerecord\Material::$_own_group;
     CMSMaterial::$_map = \samson\activerecord\Material::$_map;
     // Perform db query to get all possible material fields
     if (dbQuery('field')->cond('Active', 1)->cond('Name', '', dbRelation::NOT_EQUAL)->exec($this->material_fields)) {
         foreach ($this->material_fields as $db_field) {
             // Add additional field localization condition
             if ($db_field->local == 1) {
                 $equal = '((' . $t_name . '.FieldID = ' . $db_field->id . ')&&(' . $t_name . ".locale = '" . locale() . "'))";
             } else {
                 $equal = '((' . $t_name . '.FieldID = ' . $db_field->id . ')&&(' . $t_name . ".locale is NULL))";
             }
             // Define field value DB column for storing data
             $v_col = 'Value';
             // We must get data from other column for this type of field
             if ($db_field->Type == 7 || $db_field->Type == 3 || $db_field->Type == 10) {
                 $v_col = 'numeric_value';
             } else {
                 if ($db_field->Type == 6) {
                     $v_col = 'key_value';
                 }
             }
             // Save additional field
             self::$fields[$db_field->Name] = "\n" . ' MAX(IF(' . $equal . ',' . $t_name . '.`' . $v_col . '`, NULL)) as `' . $db_field->Name . '`';
             // Set additional object metadata
             CMSMaterial::$_attributes[$db_field->Name] = $db_field->Name;
             CMSMaterial::$_map[$db_field->Name] = dbMySQLConnector::$prefix . 'material.' . $db_field->Name;
         }
     }
     // Set additional object metadata
     CMSMaterial::$_sql_select['this'] = ' STRAIGHT_JOIN ' . Material::$_sql_select['this'];
     if (sizeof(self::$fields)) {
         CMSMaterial::$_sql_select['this'] .= ',' . implode(',', self::$fields);
     }
     CMSMaterial::$_sql_from['this'] .= "\n" . 'LEFT JOIN ' . dbMySQLConnector::$prefix . 'materialfield as ' . $t_name . ' on ' . dbMySQLConnector::$prefix . 'material.MaterialID = ' . $t_name . '.MaterialID';
     CMSMaterial::$_own_group[] = dbMySQLConnector::$prefix . 'material.MaterialID';
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  * @param string $material_id CMSMaterial identifier
  */
 public function __construct($material_id = null, $parentStructure = null)
 {
     // Variable to store navigation ids to get fields by them from structurefields
     $navigationForFields = array();
     // Add structure material condition
     $scg = new dbConditionGroup('or');
     $scg->arguments[] = new dbConditionArgument(dbMySQLConnector::$prefix . 'structurematerial_Active', 1);
     $scg->arguments[] = new dbConditionArgument(dbMySQLConnector::$prefix . 'structurematerial_Active', NULL, dbRelation::ISNULL);
     // Perform CMSMaterial request with related CMSNavs
     if (dbQuery(ns_classname('CMSMaterial', 'samson\\cms'))->MaterialID($material_id)->join('structurematerial')->join('structure')->join('user')->Active(1)->cond($scg)->first($this->material)) {
         // Existing material handling
         // If material has relations with cmsnav
         $cmsnavs =& $this->material->onetomany['_structure'];
         if (isset($cmsnavs)) {
             // WYSIWYG query
             $fields_query = dbQuery('\\samson\\cms\\CMSNavField')->join('\\samson\\cms\\CMSField')->order_by('FieldID', 'ASC')->Active(1);
             // If material has related cmsnavs - gather material related cmsnavs info
             foreach ($cmsnavs as $structure) {
                 $this->navs[$structure->id] = $structure;
                 if ($structure->type != 2) {
                     $navigationForFields[] = $structure->id;
                 }
             }
             // Add cmsnavs ids to query
             $fields_query->StructureID($navigationForFields);
             // Perform DB request
             if ($fields_query->exec($fields)) {
                 foreach ($fields as $data) {
                     // Pointer to field object
                     $db_field =& $data->onetoone['_field'];
                     // Add field data to collection
                     $this->fields[] = $db_field;
                     if (isset($db_field->Type) && $db_field->Type == '8') {
                         $this->tabs[] = new MaterialFieldLocalizedTab($this, $db_field, 'WYSIWYG');
                     }
                 }
             }
         }
     } else {
         // Material empty draft creation
         $this->material = new CMSMaterial();
         $this->material->Draft = $this->material->id;
         $this->material->Name = 'Новый материал';
         $this->material->Created = date('h:m:i d.m.y');
         //			$this->material->UserID = auth()->user->id;
         $this->material->UserID = m('social')->user()->UserID;
         $this->material->Active = 1;
         $this->material->save();
         if (isset($parentStructure)) {
             /** @var \samson\cms\web\navigation\CMSNav $str */
             $str = null;
             if (dbQuery('\\samson\\cms\\web\\navigation\\CMSNav')->id($parentStructure)->first($str)) {
                 while (isset($str)) {
                     $this->navs[$str->id] = $str;
                     $str = $str->parent();
                 }
             }
         }
     }
     // Autoload base tab classes
     class_exists('samsoncms\\app\\material\\MainTab');
     class_exists('samsoncms\\app\\material\\FieldLocalizedTab');
     // Iterate declared classes to find other FormTab children to load to form
     foreach (get_declared_classes() as $class) {
         // If class if samson\cms\web\material\FormTab child
         if (is_subclass_of($class, ns_classname('FormTab', 'samsoncms\\app\\material'))) {
             // Tab supports automatic rendering flag
             eval('$ar = ' . $class . '::$AUTO_RENDER;');
             // PHP 5.2 support
             if ($ar === true) {
                 // Create and add FormTab instance to form tabs collection
                 $this->tabs[] = new $class($this);
             }
         }
     }
     // Sort tabs by their index
     usort($this->tabs, array($this, 'tabs_sorter'));
 }