public function testBulkSetAndGetWithRelatedModels() { $account = new Account(); //creates ok. Yii::app()->user->userModel = User::getByUsername('super'); RuntimeUtil::getClassHierarchy('Account', 'Item'); $account = new Account(); //Has problems creating after we do getClassHierarchy up to Item. //If we do RuntimeUtil::getClassHierarchy('Account', 'RedBeanModel'); than it is fine. }
/** * Renders a div element with a id or class attribute set to the type * of the view, (depending on the value returned by isUniqueToAPage()), * and containing the content of any matching template found * in the themes/<themename>/ directory if it exists, marked by * begin/end comments, and the content of the view rendered by * renderContent(). All are correctly indented by indent(). * * If the template does not exist in the active theme folder, it will attempt * to locate the file in the themes/default/templates folder and include it if * it exists. */ public function render() { $theme = Yii::app()->theme->name; $name = get_class($this); $templateName = "themes/{$theme}/templates/{$name}.xhtml"; $content = $this->renderContent(); if (!file_exists($templateName)) { $templateName = "themes/default/templates/{$name}.xhtml"; } if (file_exists($templateName)) { $span = "<span class=\"{$name}\" />"; $templateSource = file_get_contents($templateName); if (strpos($templateSource, $span)) { $content = str_replace($span, $content, $templateSource); } $content = "<!-- Start of {$templateName} -->{$content}<!-- End of {$templateName} -->"; } $classes = RuntimeUtil::getClassHierarchy(get_class($this), 'View'); if ($this->isUniqueToAPage()) { $id = " id=\"{$name}\""; unset($classes[0]); } else { $id = $this->getId(); if ($id != null) { $id = " id=\"{$id}\""; } } $classes = join(' ', array_merge($this->getCssClasses(), $classes)); if ($classes != '') { $classes = " class=\"{$classes}\""; } $calledClass = get_called_class(); if (YII_DEBUG) { $reflection = new ReflectionClass($calledClass); $classFile = $reflection->getFileName(); return "<!--Called in: {$classFile}--><div" . $id . $classes . $this->getViewStyle() . ">{$content}</div>"; } else { return "<div" . $id . $classes . $this->getViewStyle() . ">{$content}</div>"; } }
protected function resolveDefaultClasses() { if ($this->makeDefaultClassesFromClassHeirarchy) { return RuntimeUtil::getClassHierarchy(get_class($this), 'View'); } return array(); }
/** * Maps metadata for the class and all of the classes in the heirarchy up to the BeanModel */ private static function mapMetadataForAllClassesInHeirarchy() { self::$attributeNamesToClassNames[get_called_class()] = array(); self::$relationNameToRelationTypeModelClassNameAndOwns[get_called_class()] = array(); self::$derivedRelationNameToTypeModelClassNameAndOppposingRelation[get_called_class()] = array(); self::$attributeNamesNotBelongsToOrManyMany[get_called_class()] = array(); foreach (array_reverse(RuntimeUtil::getClassHierarchy(get_called_class(), static::$lastClassInBeanHeirarchy)) as $modelClassName) { if ($modelClassName::getCanHaveBean()) { self::mapMetadataByModelClassName($modelClassName); } } foreach (static::getMixedInModelClassNames() as $modelClassName) { if ($modelClassName::getCanHaveBean()) { self::mapMetadataByModelClassName($modelClassName); } } }
protected function unrestrictedDelete() { $this->forget(); // RedBeanModel only supports cascaded deletes on associations, // not on links. So for now at least they are done the slow way. foreach (RuntimeUtil::getClassHierarchy(get_class($this), static::$lastClassInBeanHeirarchy) as $modelClassName) { if ($modelClassName::getCanHaveBean()) { $this->deleteOwnedRelatedModels($modelClassName); $this->deleteForeignRelatedModels($modelClassName); $this->deleteManyManyRelations($modelClassName); } } foreach ($this->modelClassNameToBean as $modelClassName => $bean) { R::trash($bean); } // The model cannot be used anymore. $this->deleted = true; return true; }
/** * @param RedBeanModel $model * @return array */ public function getDerivedAttributeTypesData(RedBeanModel $model) { $derivedAttributeTypesData = array(); $metadata = static::getMetadata(); foreach (array_reverse(RuntimeUtil::getClassHierarchy(get_class($model), $model::getLastClassInBeanHeirarchy())) as $modelClassName) { if (isset($metadata[$modelClassName]) && isset($metadata[$modelClassName]['derivedAttributeTypes'])) { foreach ($metadata[$modelClassName]['derivedAttributeTypes'] as $derivedAttributeType) { $elementClassName = $derivedAttributeType . 'Element'; $derivedAttributeTypesData[$derivedAttributeType] = array('label' => $elementClassName::getDisplayName(), 'derivedAttributeType' => $derivedAttributeType); } } } return $derivedAttributeTypesData; }