summaryrefslogtreecommitdiff
path: root/protected/models
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2012-05-20 16:58:26 +0200
committerPatrick Seeger <pseeger@ccwn.org>2012-05-20 16:58:26 +0200
commit4f959ffc80e64dc9ee8383826a546723d97305d9 (patch)
tree3a0704c0e3a9f44746739ccffa0d64acc5ab172d /protected/models
parentacec2b5dc35302147f9a9c73d837dce2f3f9958e (diff)
parent9aad228e1af661b9b39df83700d27e71697dc66f (diff)
Merge branch 'master' of ssh://proxy.ccwn.org:9044/home/ccwn/git-repos/admin.astaf.de
Diffstat (limited to 'protected/models')
-rw-r--r--protected/models/AngebotVerein.php30
-rw-r--r--protected/models/User.php30
-rw-r--r--protected/models/Veranstaltung.php6
3 files changed, 59 insertions, 7 deletions
diff --git a/protected/models/AngebotVerein.php b/protected/models/AngebotVerein.php
index 26c6dab..183baef 100644
--- a/protected/models/AngebotVerein.php
+++ b/protected/models/AngebotVerein.php
@@ -4,12 +4,17 @@
* This is the model class for table "angebot_verein".
*
* The followings are the available columns in table 'angebot_verein':
+ * @property integer $id
* @property integer $angebot_id
* @property integer $verein_id
* @property double $menge
* @property string $einheit
* @property double $preis
* @property integer $published
+ *
+ * The followings are the available model relations:
+ * @property Angebot $angebot
+ * @property Verein $verein
*/
class AngebotVerein extends CActiveRecord
{
@@ -41,14 +46,27 @@ class AngebotVerein extends CActiveRecord
return array(
array('angebot_id, verein_id, menge, einheit, preis', 'required'),
array('angebot_id, verein_id, published', 'numerical', 'integerOnly'=>true),
- array('menge, preis', 'numerical'),
+ array('menge, preis', 'numerical', "numberPattern"=>"/^\s*[-+]?[0-9]*(,|\.)?[0-9]+([eE][-+]?[0-9]+)?\s*$/"),
array('einheit', 'length', 'max'=>20),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
- array('angebot_id, verein_id, menge, einheit, preis, published', 'safe', 'on'=>'search'),
+ array('id, angebot_id, verein_id, menge, einheit, preis, published', 'safe', 'on'=>'search'),
);
}
+ public function afterFind() {
+ parent::afterFind();
+ $this->preis = Format::decimal($this->preis, "00.00");
+ $this->menge = Format::decimal($this->menge);
+ }
+
+ public function beforeSave() {
+ $return = parent::beforeSave();
+ $this->preis = str_replace(",", ".", $this->preis);
+ $this->menge = str_replace(",", ".", $this->menge);
+ return $return;
+ }
+
/**
* @return array relational rules.
*/
@@ -57,8 +75,8 @@ class AngebotVerein extends CActiveRecord
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
- "angebot"=>array(self::HAS_ONE, "Angebot", array('id'=>'angebot_id')),
- "verein"=>array(self::HAS_ONE, "Verein", array('id'=>'verein_id'))
+ 'angebot' => array(self::BELONGS_TO, 'Angebot', 'angebot_id'),
+ 'verein' => array(self::BELONGS_TO, 'Verein', 'verein_id'),
);
}
@@ -68,11 +86,12 @@ class AngebotVerein extends CActiveRecord
public function attributeLabels()
{
return array(
+ 'id' => 'ID',
'angebot_id' => 'Angebot',
'verein_id' => 'Verein',
'menge' => 'Menge',
'einheit' => 'Einheit',
- 'preis' => 'Preis',
+ 'preis' => 'Preis (in €)',
'published' => 'Öffentlich',
);
}
@@ -88,6 +107,7 @@ class AngebotVerein extends CActiveRecord
$criteria=new CDbCriteria;
+ $criteria->compare('id',$this->id);
$criteria->compare('angebot_id',$this->angebot_id);
$criteria->compare('verein_id',$this->verein_id);
$criteria->compare('menge',$this->menge);
diff --git a/protected/models/User.php b/protected/models/User.php
index b6a1609..e0a5eeb 100644
--- a/protected/models/User.php
+++ b/protected/models/User.php
@@ -79,6 +79,19 @@ class User extends CActiveRecord
);
}
+ protected function beforeSave() {
+ if ($this->isNewRecord) {
+ $this->created_at = new CDbExpression("NOW()");
+ $this->salt = $this->generateRandomKey();
+ }
+
+ if (!$this->checkPassword($this->password)) {
+ $this->password = $this->encryptPassword($this->password);
+ }
+
+ return parent::beforeSave();
+ }
+
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
@@ -104,6 +117,21 @@ class User extends CActiveRecord
}
public function checkPassword($password) {
- return sha1($this->salt.$password) == $this->password;
+ return $this->encryptPassword($password) == $this->password;
}
+
+ protected function encryptPassword($password) {
+ return sha1($this->salt.$password);
+ }
+
+ protected function generateRandomKey($len = 20) {
+ $string = '';
+ $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+ for ($i = 1; $i <= $len; $i++) {
+ $string .= substr($pool, rand(0, 61), 1);
+ }
+
+ return md5($string);
+ }
+
} \ No newline at end of file
diff --git a/protected/models/Veranstaltung.php b/protected/models/Veranstaltung.php
index 64c7854..496cf30 100644
--- a/protected/models/Veranstaltung.php
+++ b/protected/models/Veranstaltung.php
@@ -113,7 +113,7 @@ class Veranstaltung extends CActiveRecord
));
}
- public function beforeSave() {
+ protected function beforeSave() {
$isValid = parent::beforeSave();
if ($isValid) {
$this->startzeit = Format::dbDateTime($this->startzeit);
@@ -122,6 +122,10 @@ class Veranstaltung extends CActiveRecord
return $isValid;
}
+ protected function afterFind() {
+ parent::afterFind();
+ }
+
public function behaviors() {
return array(
'LoggableBehavior'=>'application.modules.auditTrail.behaviors.LoggableBehavior',