コード例 #1
0
ファイル: Table.php プロジェクト: expenect/cms_app_field
 /**
  * @param Pager $pager
  * @param int   $navID
  */
 public function __construct(Pager &$pager = null, $navID = 0)
 {
     // Prepare db query
     $this->query = dbQuery('\\samson\\cms\\CMSField')->join('\\samson\\cms\\CMSNavField')->join('\\samson\\cms\\Navigation')->order_by('FieldID', 'ASC');
     if (dbQuery('structure')->id($navID)->first($structure)) {
         $this->query = $this->query->cond('StructureID', $structure->id);
     }
     // Constructor tree
     parent::__construct($this->query, $pager);
 }
コード例 #2
0
ファイル: Table.php プロジェクト: samsonos/cms_app_export
 /**
  * Constructor
  * @var $structures
  */
 public function __construct($structures = '')
 {
     // Try to find structure in DB
     $dbStructures = array();
     if (dbQuery('structure')->exec($dbStructures)) {
         // Get material ids by structure
         $materialIDs = dbQuery('structurematerial')->StructureID($structures)->fieldsNew('MaterialID');
         // Create DB query object
         $this->query = cmsquery()->id($materialIDs);
         //->own_limit(0);
         // Get all fields for structures(explode if they are splitted with comma)
         $fields = array();
         if (dbQuery('structurefield')->StructureID(explode(',', $structures))->group_by('FieldID')->fieldsNew('FieldID', $fields)) {
             // Get all field objects
             if (dbQuery('field')->id($fields)->exec($this->fields)) {
                 // Render all fields as table headers
                 $num = 0;
                 foreach ($this->fields as $field) {
                     $this->headerRows .= m()->view('www/table/thead/th')->num($num++)->field($field)->output();
                 }
             }
         }
         // TODO: Create SQL request for this it will be usefull in Navigation
         $this->structureCount = 0;
         // Find all other structures that is connected with current materials
         $sms = array();
         if (dbQuery('structurematerial')->MaterialID($materialIDs)->exec($sms)) {
             foreach ($sms as $sm) {
                 // Set pointer to material record or create new array for it
                 $pointer =& $this->materialStructures[$sm->MaterialID];
                 if (!isset($pointer)) {
                     $pointer = array();
                 }
                 // Store material relation to a structure in array
                 if (!isset($pointer[$sm->StructureID]) && isset($dbStructures[$sm->StructureID])) {
                     $pointer[$sm->StructureID] = $dbStructures[$sm->StructureID]->Name;
                     // Analyze this material structures count
                     if (sizeof($pointer) > $this->structureCount) {
                         // Store maximum depth
                         $this->structureCount = sizeof($pointer);
                     }
                 }
             }
             // Sort all categories to be the same
             foreach ($this->materialStructures as &$sm) {
                 ksort($sm, SORT_NUMERIC);
             }
         }
     }
     // Call parent constructor
     parent::__construct($this->query);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: Table.php プロジェクト: samsonos/cms_app_material
 /**
  * Constructor
  * @param Navigation $nav Parent CMSNav to filter materials
  * @param string $search Keywords to search in materials
  * @param string $page Current table page number
  * @param \samson\core\IViewable $renderer Table renderer
  */
 public function __construct(Navigation &$nav = null, $search = null, $page = null, $renderer = null)
 {
     // Save parent cmsnav
     $this->nav =& $nav;
     // Set current module or use passed renderer
     $this->renderer = isset($renderer) ? $renderer : m();
     // Save search keywords
     $this->search = $search;
     $prefix = $this->setPagerPrefix();
     // Create pager
     $this->pager = new \samson\pager\Pager($page, self::ROWS_COUNT, $prefix);
     // Collection of filtered material identifiers
     $filteredIDs = array();
     $searchOrStructureFlag = false;
     // If search filter is set - add search condition to query
     if (isset($this->search[0]) && $this->search != '0') {
         // Create additional fields query
         $searchQuery = dbQuery('materialfield')->join('material');
         // Create or condition
         $searchCondition = new Condition('OR');
         // Iterate all possible material fields
         foreach (cms()->material_fields as $f) {
             // Create special condition for additional field
             $cg = new Condition('AND');
             $cg->add(new Argument('FieldID', $f->FieldID))->add(new Argument('Value', '%' . $search . '%', dbRelation::LIKE));
             // Add new condition to group
             $searchCondition->add($cg);
         }
         // Add all search conditions from material table
         foreach ($this->search_fields as $item) {
             $searchCondition->add(new Argument('material_' . $item, '%' . $search . '%', dbRelation::LIKE));
         }
         // Set condition
         $searchQuery->cond($searchCondition);
         // Get filtered identifiers
         $filteredIDs = $searchQuery->fieldsNew('MaterialID');
         $searchOrStructureFlag = true;
     }
     // Create DB query object
     $this->query = dbQuery('\\samson\\activerecord\\material')->cond('parent_id', 0)->cond('Draft', 0)->cond('Active', 1)->own_order_by('Modyfied', 'DESC');
     // Perform query by structure-material and get material ids
     $ids = array();
     if (isset($nav) && dbQuery('samson\\cms\\CMSNavMaterial')->cond('StructureID', $nav->id)->cond('Active', 1)->fields('MaterialID', $ids)) {
         // Set corresponding material ids related to specified navigation
         if (sizeof($filteredIDs)) {
             $filteredIDs = array_intersect($filteredIDs, $ids);
         } else {
             $filteredIDs = $ids;
         }
         $searchOrStructureFlag = true;
     }
     // If we have filtration identifiers
     if (sizeof($filteredIDs)) {
         // Add the, to query
         $this->query->id($filteredIDs);
     } elseif ($searchOrStructureFlag) {
         $this->query->id(0);
     }
     $this->queryHandler();
     // Call parent constructor
     parent::__construct($this->query, $this->pager, $this->renderer);
 }
コード例 #5
0
 /**
  * Constructor
  * @param CMSMaterial $db_material CMSMaterial pointer
  * @param string $locale Field table locale
  */
 public function __construct(\samson\cms\CMSMaterial &$db_material, Form &$form, $locale = SamsonLocale::DEF)
 {
     $this->locale = $locale;
     $this->dbQuery = new dbQuery();
     // Save pointer to Form
     $this->form =& $form;
     // Save pointer to CMSMaterial
     $this->db_material =& $db_material;
     // Prepare db query for all related material fields to structures
     $this->query = dbQuery('samson\\cms\\CMSNavField')->cond(dbMySQLConnector::$prefix . 'field_Type', array('8', '5'), dbRelation::NOT_EQUAL)->join('samson\\cms\\CMSField')->group_by(dbMySQLConnector::$prefix . 'field_FieldID')->order_by('FieldID', 'ASC')->Active(1);
     // Get all related structures and remove them from request
     $relatedStructureIDs = dbQuery('structure')->cond('type', 1)->fields('StructureID');
     if ($db_material->type != 0 && sizeof($relatedStructureIDs)) {
         $fieldsIDs = dbQuery('structurefield')->cond('StructureID', $relatedStructureIDs)->fields('FieldID');
         if (sizeof($fieldsIDs)) {
             // Remove related structure fields from field table
             $this->query->cond('FieldID', $fieldsIDs, dbRelation::NOT_EQUAL);
         }
     }
     // Delete table structures from query
     $navs = $form->navs;
     foreach ($navs as $key => $nav) {
         if ($nav->type == 2) {
             unset($navs[$key]);
         }
     }
     // If material has related structures add them to query
     $structureIDs = array_keys($navs);
     if (sizeof($structureIDs)) {
         $this->query->StructureID($structureIDs);
     }
     // Create materialfield db query
     $mfQuery = dbQuery('materialfield')->locale($locale)->MaterialID($db_material->id)->Active(1);
     // Add localization condition if necessary
     if ($locale != '') {
         // Show only localizable fields
         $this->query->cond(dbMySQLConnector::$prefix . 'field_local', 1);
     } else {
         // Show only not localizable fields
         $this->query->cond(dbMySQLConnector::$prefix . 'field_local', 0);
     }
     // Perform DB request to find existing materialfields
     //db()->debug(true);
     if ($mfQuery->exec($db_materialfields)) {
         // Recollect materialfields by their identifiers
         foreach ($db_materialfields as $db_materialfield) {
             // Save materialfields object by field identifier
             $this->materialfields[$db_materialfield->FieldID] = $db_materialfield;
         }
     }
     //db()->debug(false);
     //trace('Locale:'.$locale);
     //trace('Fields:'.implode(',', array_keys($this->materialfields)));
     // Constructor treed
     parent::__construct($this->query);
 }
コード例 #6
0
 /**
  * Constructor
  * @param \samsoncms\api\Material $material Current material object
  * @param Pager $pager Pager object
  * @param \samsoncms\api\Navigation Current table structure object
  * @param string $locale Locale string
  */
 public function __construct(\samsoncms\api\Material &$material, Pager $pager = null, $structure, $locale = 'ru')
 {
     $this->dbQuery = new dbQuery();
     // Retrieve pointer to current module for rendering
     $this->renderModule =& s()->module($this->renderModule);
     // Set input locale as current
     $this->locale = $locale;
     // Save pointer to CMSMaterial
     $this->material =& $material;
     // Set current table structure as input structure
     $this->structure = $structure;
     // Get all table materials identifiers from current form material
     $tableMaterialIds = dbQuery('material')->cond('parent_id', $this->material->id)->cond('type', 3)->cond('Active', 1)->cond('Draft', 0)->join('structurematerial')->cond('structurematerial.StructureID', $structure->StructureID)->fields('MaterialID');
     // Get all fields of table structure
     dbQuery('field')->join('structurefield')->cond('StructureID', $structure->StructureID)->exec($structureFields);
     /** @var \samson\cms\CMSField $field Field object */
     foreach ($structureFields as $field) {
         // Add field to fields collection
         $this->fields[$field->id] = $field;
         /** @var int $materialId Table material identifier */
         foreach ($tableMaterialIds as $materialId) {
             // Create query
             $query = dbQuery('materialfield')->cond('MaterialID', $materialId)->cond('FieldID', $field->id);
             /**
              * Fields may be on this step as localized and not localized
              * And if this is the localized field then add condition to check if this field is exists
              * with this condition, else not execute simple checking on material and field id
              */
             if ($field->local) {
                 $query->cond('locale', $this->locale);
             }
             $mf = null;
             // If such materialfield (Table cell) doesn't exist then create new field of table
             if (!$query->first($mf)) {
                 /** @var \samson\activerecord\materialfield $materialField Create material field record */
                 $materialField = new \samson\activerecord\materialfield(false);
                 $materialField->MaterialID = $materialId;
                 $materialField->FieldID = $field->id;
                 $materialField->Active = 1;
                 // If this field not localized then set not local to this field
                 $materialField->locale = empty($field->local) ? '' : $this->locale;
                 $materialField->save();
             }
         }
     }
     // $this->addEmptyRow();
     // Get all table materials
     $this->query = dbQuery('material')->cond('parent_id', $this->material->id)->cond('type', 3)->cond('Active', 1)->order_by('priority')->join('materialfield');
     // With specified fields if they exist
     if (!empty($this->fields)) {
         $this->query->cond('materialfield.FieldID', array_keys($this->fields));
     }
     // Constructor treed
     parent::__construct($this->query);
 }