public function getEntryTypeIds()
 {
     if ($entryTypeRecords = EntryTypeRecord::model()->ordered()->findAll()) {
         $entryTypes = EntryTypeModel::populateModels($entryTypeRecords);
         $sectionsWithEntryTypeIds = array();
         foreach ($entryTypes as $entryType) {
             if (!isset($sectionsWithEntryTypeIds[$entryType->sectionId])) {
                 $sectionsWithEntryTypeIds[$entryType->sectionId] = array();
             }
             $sectionsWithEntryTypeIds[$entryType->sectionId][] = $entryType->id;
         }
         return !empty($sectionsWithEntryTypeIds) ? $sectionsWithEntryTypeIds : false;
     }
     return false;
 }
 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     /*
      *	Craft 2.5+ required – abort migration if not, making it possible to roll back to 2.3 or 2.4
      *
      */
     if (!version_compare(craft()->getVersion(), '2.5', '>=')) {
         throw new Exception(Craft::t('Reasons 1.0 requires Craft 2.5 or newer and is unable to complete this update. Please restore Reasons to v. 0.2.2 or older, or update your Craft install.'));
         return false;
     }
     $table = 'reasons';
     /*
      *	Add FK fieldLayoutId column
      *
      */
     $this->addColumnAfter($table, 'fieldLayoutId', ColumnType::Int, 'id');
     $this->addForeignKey($table, 'fieldLayoutId', 'fieldlayouts', 'id', 'CASCADE', 'CASCADE');
     /*
      *	Set fieldLayoutId for existing rows
      *
      */
     $entryTypeRecords = EntryTypeRecord::model()->findAll();
     if ($entryTypeRecords) {
         $entryTypes = EntryTypeModel::populateModels($entryTypeRecords);
         foreach ($entryTypes as $entryType) {
             if (!isset($entryType->fieldLayoutId) || !$entryType->fieldLayoutId) {
                 continue;
             }
             $this->update($table, array('fieldLayoutId' => $entryType->fieldLayoutId), 'typeId=:typeId', array(':typeId' => $entryType->id));
         }
     }
     /*
      *	Delete typeId column
      *
      */
     $this->dropForeignKey($table, 'typeId');
     $this->dropColumn($table, 'typeId');
     /*
      *	Delete sectionId column
      *
      */
     $this->dropForeignKey($table, 'sectionId');
     $this->dropColumn($table, 'sectionId');
     return true;
 }
示例#3
0
 /**
  * Returns entry types that have a given handle.
  *
  * @param int $entryTypeHandle
  *
  * @return array
  */
 public function getEntryTypesByHandle($entryTypeHandle)
 {
     $entryTypeRecords = EntryTypeRecord::model()->findAllByAttributes(array('handle' => $entryTypeHandle));
     return EntryTypeModel::populateModels($entryTypeRecords);
 }
示例#4
0
 private function _getLayouts()
 {
     $assetSources = craft()->assetSources->getAllSources();
     $categoryGroups = craft()->categories->getAllGroups();
     $globalSets = craft()->globals->getAllSets();
     $entryTypes = EntryTypeModel::populateModels(EntryTypeRecord::model()->ordered()->findAll());
     $tagGroups = craft()->tags->getAllTagGroups();
     //$userFields = FieldLayoutModel::populateModel(FieldLayoutRecord::model()->findByAttributes('type', ElementType::User));
     $sections = craft()->sections->getAllSections();
     $singleSections = array();
     foreach ($sections as $section) {
         $entryType = $section->getEntryTypes()[0];
         $singleSections[$section->id] = (int) $entryType->fieldLayoutId;
     }
     return array('assetSource' => $this->_mapLayouts($assetSources), 'categoryGroup' => $this->_mapLayouts($categoryGroups), 'globalSet' => $this->_mapLayouts($globalSets), 'entryType' => $this->_mapLayouts($entryTypes), 'tagGroup' => $this->_mapLayouts($tagGroups), 'singleSection' => $singleSections);
 }