См. также: MetaModelFactory::byId() to instantiate a MetaModel by its ID.
См. также: MetaModelFactory::byTableName() to instantiate a MetaModel by its table name. This class handles all attribute definition instantiation and can be queried for a view instance to certain entries.
Наследование: implements metamodels\IMetaModel
Пример #1
0
 /**
  * Mock a MetaModel instance.
  *
  * @return IMetaModel
  */
 private function mockMetaModel()
 {
     $dataBase = Database::getNewTestInstance();
     $serviceContainer = new MetaModelsServiceContainer();
     $serviceContainer->setDatabase($dataBase);
     $metaModel = new MetaModel(array('id' => '1', 'sorting' => '1', 'tstamp' => '0', 'name' => 'MetaModel', 'tableName' => 'mm_test', 'mode' => '', 'translated' => '1', 'languages' => array('en' => array('isfallback' => '1'), 'de' => array('isfallback' => '')), 'varsupport' => '1'));
     $metaModel->setServiceContainer($serviceContainer);
     return $metaModel;
 }
 /**
  * Instantiate the field an set all values
  *
  * @param array     $data
  * @param MetaModel $objMM
  */
 public function __construct(array $data, MetaModel $objMM)
 {
     $this->mmAttribute = $objMM->getAttributeById($data['attr_id']);
     $this->colName = $this->mmAttribute->get('colname');
     $dcaArray = $this->mmAttribute->getFieldDefinition($data);
     $this->eval = $dcaArray['eval'];
     unset($dcaArray['eval']);
     $this->data = $dcaArray;
     if ($data['tl_class']) {
         $this->addEval('class', $data['tl_class']);
     }
     /**
      * Check for inputType and convert if necessary
      */
     switch ($this->get('inputType')) {
         case 'fileTree':
             $this->set('inputType', 'upload');
             $this->fieldType = 'upload';
             break;
     }
     if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Url\\Url')) {
         $this->set('inputType', 'beUrl');
         $this->fieldType = 'complex';
     }
     if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\IComplex')) {
         $this->fieldType = 'complex';
     }
     /**
      * Check for RTE support on longtext fields
      */
     if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Longtext\\Longtext')) {
         if (isset($data['rte']) && !empty($data['rte'])) {
             $this->rte = $data['rte'];
             $class = $this->getEval('class') . ' ' . $data['rte'];
             if (!$this->modifyEval('class', $class)) {
                 $this->addEval('class', $class);
             }
         }
     }
     /**
      * Get option values from select attributes
      */
     if (is_a($this->mmAttribute, '\\MetaModels\\Attribute\\Select\\AbstractSelect')) {
         $this->set('options', $this->mmAttribute->getFilterOptions(null, false));
     }
     /**
      * Add Save Handler
      */
     switch ($this->fieldType) {
         case 'upload':
             $this->setSaveHandler(new UploadSaveHandler($this));
             break;
         default:
             $this->setSaveHandler(new SaveHandler($this));
             break;
     }
 }
Пример #3
0
 /**
  * Test the build process.
  *
  * @return void
  */
 public function testBuild()
 {
     $metaModel = new MetaModel(array('id' => '1', 'sorting' => '1', 'tstamp' => '0', 'name' => 'MetaModel', 'tableName' => 'mm_test', 'mode' => '', 'translated' => '1', 'languages' => array('en' => array('isfallback' => '1'), 'de' => array('isfallback' => '')), 'varsupport' => '1'));
     /** @var \MetaModels\Attribute\Base $attribute */
     $attribute = $this->getMockForAbstractClass('MetaModels\\Attribute\\Base', array($metaModel, array('colname' => 'test1')));
     $metaModel->addAttribute($attribute);
     $config = DefaultConfig::init();
     $config->setFilter(array(array('operation' => '=', 'property' => 'foo', 'value' => 0)));
     $dataBase = Database::getNewTestInstance();
     $builder = new FilterBuilderSql($metaModel->getTableName(), 'AND', $dataBase);
     $dataBase->getQueryCollection()->theQuery('SELECT id FROM mm_test WHERE ((test = ?))')->with(0)->result()->addRows(array(array('id' => 0), array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)));
     $this->assertTrue($builder->isEmpty());
     $this->assertEquals($builder, $builder->addChild(array('operation' => '=', 'property' => 'test', 'value' => 0)));
     $this->assertEquals(array(0, 1, 2, 3, 4, 5), $builder->build()->getMatchingIds());
 }
Пример #4
0
 /**
  * Create a MetaModel instance with the given information.
  *
  * @param CreateMetaModelEvent $event   The event.
  *
  * @param array                $arrData The meta information for the MetaModel.
  *
  * @return void
  */
 protected function createInstance(CreateMetaModelEvent $event, $arrData)
 {
     if (!$this->createInstanceViaLegacyFactory($event, $arrData)) {
         $metaModel = new MetaModel($arrData);
         $metaModel->setServiceContainer($this->getServiceContainer());
         $event->setMetaModel($metaModel);
     }
     if ($event->getMetaModel()) {
         self::$instancesByTable[$event->getMetaModelName()] = $event->getMetaModel();
         self::$instancesById[$event->getMetaModel()->get('id')] = $event->getMetaModel();
     }
 }
Пример #5
0
 /**
  * Ensure the system columns are present. See issue #196.
  *
  * @return void
  */
 public function testRetrieveSystemColumns()
 {
     $metaModel = new MetaModel(array('id' => '1', 'sorting' => '256', 'tstamp' => '1367274071', 'name' => 'Test RetrieveSystemColumns', 'tableName' => 'mm_test_retrieve', 'translated' => '1', 'languages' => serialize(array('en' => array('isfallback' => '1'), 'de' => array('isfallback' => '0'))), 'varsupport' => ''));
     $rows = array(1 => array('id' => 1, 'pid' => 0, 'sorting' => 1, 'tstamp' => 343094400));
     $database = Database::getNewTestInstance();
     $metaModel->setServiceContainer($this->mockServiceContainer($database));
     $database->getQueryCollection()->theQuery('SELECT * FROM mm_test_retrieve WHERE id IN (?) ORDER BY FIELD(id,?)')->with(1, 1)->result()->addRows($rows);
     $this->assertEquals($metaModel->getName(), 'Test RetrieveSystemColumns');
     $item = $metaModel->findById(1);
     $this->assertEquals(1, $item->get('id'));
     $this->assertEquals(0, $item->get('pid'));
     $this->assertEquals(1, $item->get('sorting'));
     $this->assertEquals(343094400, $item->get('tstamp'));
     $this->assertNull($item->get('varbase'));
     $this->assertNull($item->get('vargroup'));
 }