예제 #1
0
/**
 * Фунцкция принимает список инфоблоков \Cpeople\Classes\Block\Object,
 * делает выборку разделов и возвращает список разделов \Cpeople\Classes\Section\Object
 * с полем elements, содержащим инфорблоки
 *
 * @param $iblocks
 * @return array
 */
function cp_group_by_section($iblocks, $level = 0)
{
    if (empty($iblocks) || !is_array($iblocks)) {
        return false;
    }
    $sectionsIds = array();
    $list = new \Cpeople\Classes\Block\Collection($iblocks);
    foreach ($list as $item) {
        $sectionsIds[] = $item->iblock_section_id;
    }
    if (empty_array($sectionsIds)) {
        return false;
    }
    $sections = \Cpeople\Classes\Section\Getter::instance()->setFilter(array('ID' => $sectionsIds))->checkPermissions(false)->get();
    foreach ($sections as $section) {
        $section->elements = $list->getBy('iblock_section_id', $section->id);
    }
    return $sections;
}
예제 #2
0
 /**
  * @return \Cpeople\Classes\Section\Object
  */
 public function getParentSection()
 {
     return \Cpeople\Classes\Section\Getter::instance()->getById($this->iblock_section_id);
 }
예제 #3
0
 /**
  * @return \Cpeople\Classes\Block\Object|\Cpeople\Classes\Section\Object
  */
 public function getElement()
 {
     if ($this->element === null) {
         $itemId = $this->getItemID();
         $isSection = !is_numeric($itemId);
         if ($isSection) {
             $itemId = substr($itemId, 1);
             $instance = \Cpeople\Classes\Section\Getter::instance();
         } else {
             $instance = \Cpeople\Classes\Block\Getter::instance();
         }
         $this->element = $instance->getById($itemId);
     }
     return $this->element;
 }