示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * Find all materials that current material relates to
  * @param function $handler External DB request handler
  * @return \samson\cms\CMSMaterial[] Collection of materials that current material relates to
  */
 public function &relates($handler = null)
 {
     $db_materials = array();
     //$GLOBALS['show_sql'] = true;
     // Create DB query
     $q = dbQuery('samson\\cms\\cmsrelatedmaterial');
     // If external query handler is passed
     if (isset($handler)) {
         $q->handler($handler);
     }
     // If we have found related materials
     if ($q->second_material($this->id)->fields('first_material', $ids)) {
         // Get related CMSMaterials by ids
         $db_materials = array_merge($db_materials, cmsquery()->MaterialID($ids)->published());
     }
     return $db_materials;
 }
示例#3
0
文件: CMS.php 项目: samsonos/cms_api
 /**
  * Perform request to get CNSMaterials by CMSNav
  * @param mixed $selector CMSNav selector
  * @param string $field CMSNav field name for searching
  * @param string $handler External handler
  * @return array
  */
 public function &navmaterials($selector, $field = 'Url', $handler = null)
 {
     $result = array();
     // Find CMSNav
     if (null !== ($db_nav = $this->navigation($selector, $field))) {
         // Get material ids from structure materials records
         $ids = array();
         if (dbQuery('samson\\cms\\CMSNavMaterial')->cond('StructureID', $db_nav->id)->fields('MaterialID', $ids)) {
             // Create material db query
             $q = cmsquery()->id($ids);
             // Set ecternal query handler
             if (isset($handler)) {
                 $q->handler($handler);
             }
             // Perform DB request and get materials
             $result = $q->exec();
         }
     }
     return $result;
 }