[icinga-checkins] icinga.org: icinga-web/mhein/extlayout: * Restored old model relations

git at icinga.org git at icinga.org
Tue May 18 17:00:12 CEST 2010


Module: icinga-web
Branch: mhein/extlayout
Commit: aed5c70d574ea2da050ebd68f0f0eaa09638e6e5
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=aed5c70d574ea2da050ebd68f0f0eaa09638e6e5

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue May 18 15:03:59 2010 +0200

* Restored old model relations
* Added base implementation for models

---

 app/lib/model/IcingaBaseModel.class.php            |   11 +--
 .../AppKit/lib/model/AppKitBaseModel.class.php     |   94 +++++++++++++++++++-
 lib/appkit/database/models/NsmSession.php          |    7 ++
 lib/appkit/database/models/NsmUserPreference.php   |    7 ++
 .../database/models/generated/BaseNsmRole.php      |    4 +-
 .../database/models/generated/BaseNsmUser.php      |   15 +++-
 6 files changed, 122 insertions(+), 16 deletions(-)

diff --git a/app/lib/model/IcingaBaseModel.class.php b/app/lib/model/IcingaBaseModel.class.php
index fa544b6..9b7cb16 100755
--- a/app/lib/model/IcingaBaseModel.class.php
+++ b/app/lib/model/IcingaBaseModel.class.php
@@ -3,15 +3,8 @@
 /**
  * The base model from which all project models inherit.
  */
-class IcingaBaseModel extends AgaviModel {
-	
-	protected $parameters = array ();
-	
-	public function initialize(AgaviContext $context, array $parameters = array()) {
-		parent::initialize($context, $parameters);
-		$this->parameters = $parameters;
-	}
-	
+class IcingaBaseModel extends AppKitBaseModel {
+
 }
 
 ?>
\ No newline at end of file
diff --git a/app/modules/AppKit/lib/model/AppKitBaseModel.class.php b/app/modules/AppKit/lib/model/AppKitBaseModel.class.php
index 3f52dd8..bdcd203 100755
--- a/app/modules/AppKit/lib/model/AppKitBaseModel.class.php
+++ b/app/modules/AppKit/lib/model/AppKitBaseModel.class.php
@@ -3,9 +3,99 @@
 /**
  * The base model from which all AppKit module models inherit.
  */
-class AppKitBaseModel extends IcingaBaseModel
-{
+class AppKitBaseModel extends AgaviModel {
 
+	protected $parameters = array ();
+	
+	public function initialize(AgaviContext $context, array $parameters = array()) {
+		parent::initialize($context, $parameters);
+		$this->clearParameters();
+		$this->setParameters($parameters);
+	}
+	
+	// -------------------
+	// Parameter interface
+	
+	/**
+	 * Clears the parameter array
+	 * @return boolean
+	 */
+	protected function clearParameters() {
+		$this->parameters = array ();
+		return true;
+	}
+	
+	/**
+	 * Returns the whole struct of parameters
+	 * @return array
+	 */
+	protected function &getParameters() {
+		return $this->parameters;
+	}
+	
+	/**
+	 * Returns an parameter or the default
+	 * value if not exist
+	 * @param string $name
+	 * @param mixed $default
+	 */
+	protected function &getParameter($name, $default=null) {
+		
+		if (isset($this->parameters[$name]) || array_key_exists($name, $this->parameters)) {
+			return $this->parameters[$name];
+		}
+		
+		try {
+			return AgaviArrayPathDefinition::getValue($name, $this->parameters, $default);
+		} catch(InvalidArgumentException $e) {
+			return $default;
+		}
+	}
+	
+	/**
+	 * Checks if a parameter exists
+	 * in the array
+	 * @param string $name
+	 * @return mixed
+	 */
+	protected function hasParameter($name) {
+		
+		if(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters)) {
+			return true;
+		}
+		
+		try {
+			return AgaviArrayPathDefinition::hasValue($name, $this->parameters);
+		} catch(InvalidArgumentException $e) {
+			return false;
+		}
+	}
+	
+	/**
+	 * Sets a value for a named parameter
+	 * @param string $name
+	 * @param mixed $value
+	 */
+	protected function setParameter($name, $value) {
+		$this->parameters[$name] = $value;
+	}
+	
+	/**
+	 * Sets a reference to a named parameter
+	 * @param string $name
+	 * @param mixed $value
+	 */
+	protected function setParameterByRef($name, &$value) {
+		$this->parameters[$name] =& $value;
+	}
+	
+	/**
+	 * Resets the parameter array to new values
+	 * @param array $parameters
+	 */
+	protected function setParameters(array $parameters) {
+		$this->parameters = $parameters + $this->parameters;
+	}
 }
 
 ?>
diff --git a/lib/appkit/database/models/NsmSession.php b/lib/appkit/database/models/NsmSession.php
index 1b152c0..c6d6325 100644
--- a/lib/appkit/database/models/NsmSession.php
+++ b/lib/appkit/database/models/NsmSession.php
@@ -13,6 +13,13 @@
 class NsmSession extends BaseNsmSession
 {
 
+	public function get($val) {
+		$val = parent::get($val);
+		if(is_resource($val))
+			return stream_get_contents($val);
+		return $val;
+	}
+	
 	public function setUp () {
 
 		parent::setUp();
diff --git a/lib/appkit/database/models/NsmUserPreference.php b/lib/appkit/database/models/NsmUserPreference.php
index b9eed7e..5a7ead2 100644
--- a/lib/appkit/database/models/NsmUserPreference.php
+++ b/lib/appkit/database/models/NsmUserPreference.php
@@ -13,6 +13,13 @@
 class NsmUserPreference extends BaseNsmUserPreference
 {
 
+	public function get($val) {
+		$val = parent::get($val);
+		if(is_resource($val))
+			return stream_get_contents($val);
+		return $val;
+	}
+	
 	public function setUp() {
 		parent::setUp();
 		
diff --git a/lib/appkit/database/models/generated/BaseNsmRole.php b/lib/appkit/database/models/generated/BaseNsmRole.php
index be05bfc..5508d70 100755
--- a/lib/appkit/database/models/generated/BaseNsmRole.php
+++ b/lib/appkit/database/models/generated/BaseNsmRole.php
@@ -91,11 +91,11 @@ abstract class BaseNsmRole extends Doctrine_Record
     public function setUp()
     {
         parent::setUp();
-        $this->hasMany('NsmRole', array(
+        $this->hasOne('NsmRole', array(
              'local' => 'role_id',
              'foreign' => 'role_parent'));
 
-        $this->hasMany('NsmPrincipal', array(
+        $this->hasOne('NsmPrincipal', array(
              'local' => 'role_id',
              'foreign' => 'principal_role_id'));
 
diff --git a/lib/appkit/database/models/generated/BaseNsmUser.php b/lib/appkit/database/models/generated/BaseNsmUser.php
index c07f734..8e353d7 100755
--- a/lib/appkit/database/models/generated/BaseNsmUser.php
+++ b/lib/appkit/database/models/generated/BaseNsmUser.php
@@ -93,7 +93,7 @@ abstract class BaseNsmUser extends Doctrine_Record
              'notnull' => true,
              'autoincrement' => false,
              ));
-        $this->hasColumn('user_provider', 'string', 45, array(
+        $this->hasColumn('user_authsrc', 'string', 45, array(
              'type' => 'string',
              'length' => 45,
              'fixed' => false,
@@ -102,7 +102,16 @@ abstract class BaseNsmUser extends Doctrine_Record
              'notnull' => true,
              'autoincrement' => false,
              ));
-        $this->hasColumn('user_apikey', 'string', 64, array(
+        $this->hasColumn('user_authid', 'string', 127, array(
+             'type' => 'string',
+             'length' => 127,
+             'fixed' => false,
+             'unsigned' => false,
+             'primary' => false,
+             'notnull' => true,
+             'autoincrement' => false,
+             ));
+        $this->hasColumn('user_authkey', 'string', 64, array(
              'type' => 'string',
              'length' => 64,
              'fixed' => false,
@@ -151,7 +160,7 @@ abstract class BaseNsmUser extends Doctrine_Record
     public function setUp()
     {
         parent::setUp();
-        $this->hasMany('NsmPrincipal', array(
+        $this->hasOne('NsmPrincipal', array(
              'local' => 'user_id',
              'foreign' => 'principal_user_id'));
 





More information about the icinga-checkins mailing list