/** * Returns all sections. * * @param string|null $indexBy * @return array */ public function getAllSections($indexBy = null) { if (!$this->_fetchedAllSections) { $criteria = new \CDbCriteria(); if (!Craft::hasPackage(CraftPackage::PublishPro)) { $criteria->limit = 1; } $sectionRecords = SectionRecord::model()->ordered()->findAll($criteria); $this->_sectionsById = SectionModel::populateModels($sectionRecords, 'id'); $this->_fetchedAllSections = true; } if ($indexBy == 'id') { $sections = $this->_sectionsById; } else { if (!$indexBy) { $sections = array_values($this->_sectionsById); } else { $sections = array(); foreach ($this->_sectionsById as $section) { $sections[$section->{$indexBy}] = $section; } } } return $sections; }