示例#1
0
 /**
  * Get all related materials
  * @return \samson\cms\CMSMaterial[] Collection of related materials
  */
 public function &materials()
 {
     /** @var \samson\cms\Material[] $materials Get related materials collection */
     $materials = array();
     // Perform generic material retrieval
     if (CMS::getMaterialsByStructures(array($this->id), $materials, 'samson\\cms\\CMSMaterial', null, array(), array($this, 'materialsHandlers'))) {
         // Handle
     }
     return $materials;
 }
示例#2
0
 public function __async_movestructure($childID, $parentID)
 {
     $child = $this->query->entity('\\samson\\cms\\Navigation')->id($childID)->first();
     $child->ParentID = $parentID;
     $child->save();
     $strIds = array();
     $cmsnav = $child->parent();
     while ($cmsnav) {
         $strIds[] = $cmsnav->id;
         if ($cmsnav->id == $this->catalogID) {
             break;
         }
         $cmsnav = $cmsnav->parent();
     }
     if ($this->query->entity('\\samson\\activerecord\\structure_relation')->where('child_id', $childID)->exec($strRelations)) {
         foreach ($strRelations as $strRelation) {
             $strRelation->delete();
         }
     }
     // Create new relation with new parent
     $strRelation = new \samson\activerecord\structure_relation(false);
     $strRelation->child_id = $childID;
     $strRelation->parent_id = $parentID;
     $strRelation->save();
     // Create array of structure ids which we need to use to create structurematerial relations
     $relIds = array($parentID);
     // Get relations of new parent
     $stRel = $this->query->entity('\\samson\\activerecord\\structure_relation')->child_id($parentID)->exec();
     while ($stRel) {
         // Break flag
         $break = false;
         foreach ($stRel as $strR) {
             // Save parent
             $relIds[] = $strR->parent_id;
             if ($strR->parent_id == $this->catalogID) {
                 $break = true;
                 break;
             }
         }
         if ($break) {
             break;
         } else {
             // Get next relations
             $stRel = $this->query->entity('\\samson\\activerecord\\structure_relation')->child_id($relIds)->exec();
         }
     }
     // Get materials of current category
     if (\samson\cms\CMS::getMaterialsByStructures($childID, $materials)) {
         // Create new structurematerial relations
         foreach ($materials as $material) {
             // Delete old structurematerial relations
             foreach ($this->query->entity('\\samson\\activerecord\\structurematerial')->where('MaterialID', $material->id)->where('StructureID', $strIds)->exec() as $relation) {
                 $relation->delete();
             }
             // Create new relations
             foreach ($relIds as $relId) {
                 $strMat = new \samson\activerecord\structurematerial(false);
                 $strMat->Active = 1;
                 $strMat->StructureID = $relId;
                 $strMat->MaterialID = $material->id;
                 $strMat->save();
             }
         }
     }
     return array('status' => 1);
 }