diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..29e3fa8 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +swomaha \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..189b36e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + HTML + + + + + HtmlUnknownTag + + + + + + + http://www.w3.org/1999/xhtml + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..926d0d6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/swomaha.iml b/.idea/swomaha.iml new file mode 100644 index 0000000..6b8184f --- /dev/null +++ b/.idea/swomaha.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c80f219 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4607683 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,571 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1316274349381 + 1316274349381 + + + + dfc5dfc3dfc4dfc1df9edf92df9cdf99 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/protected/DEV/ER-diagram.mwb b/protected/DEV/ER-diagram.mwb index 7bfb194..a61b2dc 100644 Binary files a/protected/DEV/ER-diagram.mwb and b/protected/DEV/ER-diagram.mwb differ diff --git a/protected/DEV/ER-diagram.mwb.bak b/protected/DEV/ER-diagram.mwb.bak index 75b8482..7bfb194 100644 Binary files a/protected/DEV/ER-diagram.mwb.bak and b/protected/DEV/ER-diagram.mwb.bak differ diff --git a/protected/DEV/swomaha.sql b/protected/DEV/swomaha.sql new file mode 100644 index 0000000..88c2b0e --- /dev/null +++ b/protected/DEV/swomaha.sql @@ -0,0 +1,418 @@ +-- phpMyAdmin SQL Dump +-- version 3.3.9 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Generation Time: Sep 17, 2011 at 01:48 PM +-- Server version: 5.1.53 +-- PHP Version: 5.3.4 + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `swomaha` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `answer` +-- + +CREATE TABLE IF NOT EXISTS `answer` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `question_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_answer_question1` (`question_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `answer` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `app` +-- + +CREATE TABLE IF NOT EXISTS `app` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Course module' AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `app` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `assessment` +-- + +CREATE TABLE IF NOT EXISTS `assessment` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `task_id` int(10) unsigned NOT NULL, + `name` varchar(255) NOT NULL, + `type` enum('quiz','freeform') NOT NULL, + `assessment_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_task_assessment_task1` (`task_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `assessment` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `assessment_freeform` +-- + +CREATE TABLE IF NOT EXISTS `assessment_freeform` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `assessment_freeform` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `assessment_question` +-- + +CREATE TABLE IF NOT EXISTS `assessment_question` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `task_assessment_quiz_id` int(10) unsigned NOT NULL, + `points` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `assessment_question` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `award` +-- + +CREATE TABLE IF NOT EXISTS `award` ( + `id` int(11) NOT NULL, + `app_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_award_app1` (`app_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `award` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `award_has_student` +-- + +CREATE TABLE IF NOT EXISTS `award_has_student` ( + `award_id` int(11) NOT NULL, + `student_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`award_id`,`student_id`), + KEY `fk_award_has_student_student1` (`student_id`), + KEY `fk_award_has_student_award1` (`award_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `award_has_student` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `challenge` +-- + +CREATE TABLE IF NOT EXISTS `challenge` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `app_id` int(10) unsigned NOT NULL, + `challenge_id` int(10) unsigned NOT NULL, + `name` varchar(255) NOT NULL, + `description` text, + `type` enum('video','reading','link','lecture') DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_challenge_app1` (`app_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `challenge` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `criteria` +-- + +CREATE TABLE IF NOT EXISTS `criteria` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(45) DEFAULT NULL, + `description` text, + `points` int(11) DEFAULT NULL, + `task_assessment_freeform_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_criteria_task_assessment_freeform1` (`task_assessment_freeform_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `criteria` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `group` +-- + +CREATE TABLE IF NOT EXISTS `group` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Group of students' AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `group` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `student` +-- + +CREATE TABLE IF NOT EXISTS `student` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(10) unsigned NOT NULL, + `first_name` varchar(45) NOT NULL, + `last_name` varchar(45) NOT NULL, + `avatar` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_student_user1` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `student` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `student_app` +-- + +CREATE TABLE IF NOT EXISTS `student_app` ( + `student_id` int(10) unsigned NOT NULL, + `app_id` int(10) unsigned NOT NULL, + `points` varchar(45) DEFAULT NULL, + PRIMARY KEY (`student_id`,`app_id`), + KEY `fk_student_has_app_app1` (`app_id`), + KEY `fk_student_has_app_student1` (`student_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `student_app` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `student_group` +-- + +CREATE TABLE IF NOT EXISTS `student_group` ( + `student_id` int(10) unsigned NOT NULL, + `group_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`student_id`,`group_id`), + KEY `fk_student_has_group_group1` (`group_id`), + KEY `fk_student_has_group_student1` (`student_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `student_group` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `teacher` +-- + +CREATE TABLE IF NOT EXISTS `teacher` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(10) unsigned NOT NULL, + `first_name` varchar(45) NOT NULL, + `last_name` varchar(45) NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_teacher_user1` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `teacher` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `teacher_app` +-- + +CREATE TABLE IF NOT EXISTS `teacher_app` ( + `teacher_id` int(10) unsigned NOT NULL, + `app_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`teacher_id`,`app_id`), + KEY `fk_teacher_has_app_app1` (`app_id`), + KEY `fk_teacher_has_app_teacher` (`teacher_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `teacher_app` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `teacher_group` +-- + +CREATE TABLE IF NOT EXISTS `teacher_group` ( + `teacher_id` int(10) unsigned NOT NULL, + `group_id` int(10) unsigned NOT NULL, + PRIMARY KEY (`teacher_id`,`group_id`), + KEY `fk_teacher_has_group_group1` (`group_id`), + KEY `fk_teacher_has_group_teacher1` (`teacher_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `teacher_group` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `user` +-- + +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `email` varchar(255) NOT NULL, + `type` enum('teacher','student') NOT NULL, + `password` varchar(64) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `user` +-- + + +-- +-- Constraints for dumped tables +-- + +-- +-- Constraints for table `answer` +-- +ALTER TABLE `answer` + ADD CONSTRAINT `fk_answer_question1` FOREIGN KEY (`question_id`) REFERENCES `assessment_question` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `assessment` +-- +ALTER TABLE `assessment` + ADD CONSTRAINT `fk_task_assessment_task1` FOREIGN KEY (`task_id`) REFERENCES `challenge` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `award` +-- +ALTER TABLE `award` + ADD CONSTRAINT `fk_award_app1` FOREIGN KEY (`app_id`) REFERENCES `app` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `award_has_student` +-- +ALTER TABLE `award_has_student` + ADD CONSTRAINT `fk_award_has_student_award1` FOREIGN KEY (`award_id`) REFERENCES `award` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + ADD CONSTRAINT `fk_award_has_student_student1` FOREIGN KEY (`student_id`) REFERENCES `student` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `challenge` +-- +ALTER TABLE `challenge` + ADD CONSTRAINT `fk_challenge_app1` FOREIGN KEY (`app_id`) REFERENCES `app` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `criteria` +-- +ALTER TABLE `criteria` + ADD CONSTRAINT `fk_criteria_task_assessment_freeform1` FOREIGN KEY (`task_assessment_freeform_id`) REFERENCES `assessment_freeform` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `student` +-- +ALTER TABLE `student` + ADD CONSTRAINT `fk_student_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `student_app` +-- +ALTER TABLE `student_app` + ADD CONSTRAINT `fk_student_has_app_app1` FOREIGN KEY (`app_id`) REFERENCES `app` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + ADD CONSTRAINT `fk_student_has_app_student1` FOREIGN KEY (`student_id`) REFERENCES `student` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `teacher` +-- +ALTER TABLE `teacher` + ADD CONSTRAINT `fk_teacher_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `teacher_app` +-- +ALTER TABLE `teacher_app` + ADD CONSTRAINT `fk_teacher_has_app_app1` FOREIGN KEY (`app_id`) REFERENCES `app` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + ADD CONSTRAINT `fk_teacher_has_app_teacher` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- +-- Constraints for table `teacher_group` +-- +ALTER TABLE `teacher_group` + ADD CONSTRAINT `fk_teacher_has_group_group1` FOREIGN KEY (`group_id`) REFERENCES `group` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + ADD CONSTRAINT `fk_teacher_has_group_teacher1` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; diff --git a/protected/models/User.php b/protected/models/User.php index 8125134..c612333 100644 --- a/protected/models/User.php +++ b/protected/models/User.php @@ -2,68 +2,95 @@ class User extends CActiveRecord { - public static function model($className=__CLASS__) - { - return parent::model($className); - } + public $oldPassword; - public function tableName() - { - return 'user'; - } + public static function model($className=__CLASS__) + { + return parent::model($className); + } - public function rules() - { - return array( - array('email, type', 'required'), - array('email', 'length', 'max'=>255), - array('type', 'length', 'max'=>7), - array('password', 'length', 'max'=>45), - array('id, email, type, password', 'safe', 'on'=>'search'), - ); - } + public function tableName() + { + return 'user'; + } - public function relations() - { - return array( - 'students' => array(self::HAS_MANY, 'Student', 'user_id'), - 'teachers' => array(self::HAS_MANY, 'Teacher', 'user_id'), - ); - } + public function rules() + { + return array( + array('email, type', 'required'), + array('email', 'length', 'max'=>255), + array('type', 'length', 'max'=>7), + array('password', 'length', 'max'=>64), + array('id, email, type, password', 'safe', 'on'=>'search'), + ); + } - public function behaviors() - { - return array( - 'CAdvancedArBehavior' => array( - 'class' => 'ext.CAdvancedArBehavior' - ) - ); - } + public function relations() + { + return array( + 'students' => array(self::HAS_MANY, 'Student', 'user_id'), + 'teachers' => array(self::HAS_MANY, 'Teacher', 'user_id'), + ); + } - public function attributeLabels() - { - return array( - 'id' => Yii::t('app', 'ID'), - 'email' => Yii::t('app', 'Email'), - 'type' => Yii::t('app', 'Type'), - 'password' => Yii::t('app', 'Password'), - ); - } + public function behaviors() + { + return array( + 'CAdvancedArBehavior' => array( + 'class' => 'ext.CAdvancedArBehavior' + ) + ); + } - public function search() - { - $criteria=new CDbCriteria; + public function attributeLabels() + { + return array( + 'id' => Yii::t('app', 'ID'), + 'email' => Yii::t('app', 'Email'), + 'type' => Yii::t('app', 'Type'), + 'password' => Yii::t('app', 'Password'), + ); + } - $criteria->compare('id',$this->id,true); + public function search() + { + $criteria=new CDbCriteria; - $criteria->compare('email',$this->email,true); + $criteria->compare('id',$this->id,true); - $criteria->compare('type',$this->type,true); + $criteria->compare('email',$this->email,true); - $criteria->compare('password',$this->password,true); + $criteria->compare('type',$this->type,true); - return new CActiveDataProvider(get_class($this), array( - 'criteria'=>$criteria, - )); - } + $criteria->compare('password',$this->password,true); + + return new CActiveDataProvider(get_class($this), array( + 'criteria'=>$criteria, + )); + } + + protected function beforeSave() + { + if(parent::beforeSave()) + { + if ($this->password != '' && $this->oldPassword != $this->password) + $this->password=md5($this->password); + if($this->isNewRecord) + { + /*$this->joined = date('Y-m-d H:i:s'); + if ($this->accountType->trial_days) { + $this->first_billed = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d")+$this->accountType->trial_days, date("Y"))); + }*/ + } + return true; + } + else + return false; + } + + protected function afterFind() + { + $this->oldPassword = $this->password; + parent::afterFind(); + } }