Location: PHPKode > projects > Recess PHP Framework > recess/recess/apps/tools/models/RecessReflectorPackage.class.php
<?php
Library::import('recess.database.orm.Model');

/**
 * !HasMany classes, Class: RecessReflectorClass, Key: packageId
 * !HasMany children, Class: RecessReflectorPackage, Key: parentId
 * !BelongsTo parent, Class: RecessReflectorPackage, Key: parentId
 * !Table recess_tools_packages
 */
class RecessReflectorPackage extends Model {
	
	/** !Column PrimaryKey, Integer, AutoIncrement */
	public $id;
	
	/** !Column String */
	public $name;
	
	/** !Column Integer */
	public $parentId;
	
	function childrenAlphabetically() {
		return $this->children()->orderBy('name ASC');
	}
	
	function insert() {		
		parent::insert();
		$dotPosition = strrpos($this->name, Library::dotSeparator);
		
		if($dotPosition !== false) { 
			$parentName = substr($this->name, 0, $dotPosition);
			
			$parent = new RecessReflectorPackage();
			$parent->name = $parentName;
			
			if(!$parent->exists()) {
				$parent->insert();
			}
			
			$this->setParent($parent);
		}
	}
	
}

?>
Return current item: Recess PHP Framework