Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace common\models;
- use yii\mongodb\ActiveRecord;
- use yii\web\IdentityInterface;
- use common\models\Discipline;
- use common\models\Lections;
- use common\models\Cultusers;
- use yii\helpers;
- use Yii;
- class Programs extends ActiveRecord
- {
- public $file;
- public function attributes()
- {
- return ['_id' ,
- 'program',
- 'icon',
- 'subtitle',
- 'enddate',
- 'about',
- 'bibliography',
- 'file'
- ];
- }
- public function rules()
- {
- return [
- [['program'], 'required'],
- [[ 'subtitle', 'enddate', 'about', 'bibliography', ],'safe'],
- [['file'], 'file','extensions' => 'gif, jpg, png, jpeg',]
- ];
- }
- public static function findIdentity($id)
- {
- if(!($id instanceof \MongoId)){
- $id = new \MongoId($id);
- }
- return static::findOne(['_id'=>$id]);
- }
- public function getDisciplines()
- {
- $disciolines = Discipline::find()
- ->where(['program' => $this->program])->all();
- return $disciolines;
- }
- public function getLections()
- {
- $lections = Lections::find()->where(['program' => $this->program])->all();
- return $lections;
- }
- public function getLecionsDates()
- {
- $lectionsDates=array();
- foreach($this->getLections() as $value) {
- $lectionsDates[] = $value->begindate;}
- return $lectionsDates;
- }
- public function getBeginDate()
- {
- $beginDate = min($this->getLecionsDates())->sec;
- return $beginDate;
- }
- public function dateToView($sec)
- {
- return date('d-m-Y', $sec);
- }
- public function getLastLecDate()
- {
- $lastLecDate = array_filter($this->getLecionsDates(),
- function($var)
- {
- $now = new \DateTime();
- if($var->sec < $now->getTimestamp()){
- return true;
- }
- }) ;
- return max($lastLecDate);
- }
- public function getNextLecDate()
- {
- $nextLecDate = array_filter($this->getLecionsDates(),
- function($var)
- {
- $now = new \DateTime();
- if($var->sec > $now->getTimestamp()){
- return true;
- }
- }) ;
- if($nextLecDate != false) {
- return min($nextLecDate);
- }else{
- return $this->getLastLecDate();
- }
- }
- public function getLastLec()
- {
- $getLastLec = null;
- foreach($this->getLections() as $lection) {
- if($lection->begindate->sec === $this->getLastLecDate()->sec){
- $getLastLec = $lection;
- }
- }
- return $getLastLec;
- }
- public function getNextLec()
- {
- $getLastLec = null;
- foreach($this->getLections() as $lection) {
- if($lection->begindate->sec === $this->getNextLecDate()->sec){
- $getLastLec = $lection;
- }
- }
- return $getLastLec;
- }
- public function getLectors()
- {
- $lections = $this->getLections();
- $lectorIds = array_map(function($lection){
- return $lection->lectorId;
- }, $lections);
- $lectors = Cultusers::find()->where(['role'=>Cultusers::ROLE_LECTOR, '_id' => $lectorIds])->all();
- return $lectors;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement