Skip to content
Browse files

u procesu user_group

  • Loading branch information...
1 parent 3a0b3fb commit d48b122a74e6092f79b447231eba4a61fcc1dfe4 @ManInTheBox committed Jan 23, 2012
Showing with 78 additions and 1 deletion.
  1. +10 −1 protected/controllers/GroupController.php
  2. +68 −0 protected/models/UserGroup.php
View
11 protected/controllers/GroupController.php
@@ -65,6 +65,11 @@ public function actionNew()
if ($group->save())
{
+ // TODO: sta sa user_grup ???
+ $userGroup = new UserGroup();
+ $userGroup->user_id = u()->id;
+ $userGroup->group_id = $group->id;
+
$this->setFlashSuccess(t('Group succesfully created.'));
$this->redirect(array('/group/list'));
}
@@ -75,7 +80,11 @@ public function actionNew()
public function actionDelete($gid)
{
-
+ if (Group::model()->deleteByPk($gid, 'owner = :owner'))
+ {
+ $this->setFlashSuccess(t('group deleted...'));
+ $this->redirect(array('/group/list'));
+ }
}
public function actionInvite()
View
68 protected/models/UserGroup.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * This is the model class for table "user_group".
+ *
+ * The followings are the available columns in table 'user_group':
+ * @property integer $user_id
+ * @property integer $group_id
+ * @property integer $created_at
+ * @property integer $status
+ * @property integer $list_role_id
+ *
+ * @property User $user
+ * @property Group $group
+ * @property ListRole $listRole
+ */
+class UserGroup extends ActiveRecord
+{
+
+ const STATUS_ACCEPTED = 0;
+ const STATUS_DECLINED = 1;
+
+ /**
+ * Returns the static model of the specified AR class.
+ * @return UserGroup the static model class
+ */
+ public static function model($className=__CLASS__)
+ {
+ return parent::model($className);
+ }
+
+ /**
+ * @return string the associated database table name
+ */
+ public function tableName()
+ {
+ return 'user_group';
+ }
+
+ /**
+ * @return array validation rules for model attributes.
+ */
+ public function rules()
+ {
+ return array(
+ array('user_id, group_id, created_at, status, list_role_id', 'required'),
+ array('user_id, group_id, created_at, status, list_role_id', 'numerical', 'integerOnly'=>true),
+ );
+ }
+
+ /**
+ * @return array relational rules.
+ */
+ public function relations()
+ {
+ return array(
+ 'user' => array(self::BELONGS_TO, 'User', 'user_id'),
+ 'group' => array(self::BELONGS_TO, 'Group', 'group_id'),
+ 'listRole' => array(self::BELONGS_TO, 'ListRole', 'list_role_id'),
+ );
+ }
+
+ protected function beforeSave()
+ {
+ $this->created_at = time();
+ return parent::beforeSave();
+ }
+}

0 comments on commit d48b122

Please sign in to comment.
Something went wrong with that request. Please try again.