/** * Time Board. */ public function actionTimeboard($id = null, $day = null, $hour = null, $minute = null) { if (Yii::app()->user->checkAccess('subject_manage')) { $utc_time = SiteLibrary::utc_time(); //If there are any position changes update the timeboard first if ($id and $day and isset($hour) and isset($minute)) { //hour and minute can be 0 thats why we use isset instead of simple if //if day is less than today then set month as next future month, if ($day < (int) date("j", $utc_time)) { $month = date("m", $utc_time) == '12' ? 1 : (int) date("m", $utc_time) + 1; $year = (int) date("Y", $utc_time) + 1; } else { $month = date("m", $utc_time); $year = date("Y", $utc_time); } $position = strtotime($year . "-" . $month . "-" . $day . " " . $hour . ":" . $minute . ":00", $utc_time); //$position = strtotime("2012-06-10 14:28"); //echo $position. $year."-".$month."-".$day." ".$hour.":".$minute.":00"; //die($position); Subject::set_position($id, $position); } $this->model = new Subject('manage'); $this->model->unsetAttributes(); // clear any default values $this->model->authorized = 1; $this->model->approved = 1; $this->model->disabled = 0; $this->model->deleted = 0; $this->model->position = ">=" . SiteLibrary::utc_time_interval(); if (isset($_GET['Subject'])) { $this->model->attributes = $_GET['Subject']; } $live_subject = Yii::app()->db->createCommand()->select('*')->from('live_subject')->queryRow(); //if(! isset($this->model->disabled)) $this->model->disabled = 0;//Set to view only NOT disabled subjects by default(notice isset insted of a simple if) $this->render('timeboard', array('model' => $this->model, 'live_subject' => $live_subject)); } else { throw new CHttpException(403, Yii::t('subject', 'You are not allowed to manage subjects.')); } }
/** * Do some things after save * */ public function afterSave() { //Update the tag table if there are new tags and only in the case of an update or create action if ($this->tag and (Yii::app()->controller->action->id == 'add' or Yii::app()->controller->action->id == 'update' or Yii::app()->controller->action->id == 'moderate' or Yii::app()->controller->action->id == 'authorize')) { $tags_ids = array(); $tags_old = Yii::app()->db->createCommand()->select('*')->from('tag')->queryAll(); foreach ($tags_old as $tag_old) { $tags[$tag_old['id']] = $tag_old['name']; } $sub_tags = Yii::app()->db->createCommand()->select('tag_id')->from('subject_tag')->where('subject_id=:subject_id', array(':subject_id' => $this->id))->queryAll(); foreach ($sub_tags as $sub_tag) { $current_tags[] = $sub_tag['tag_id']; } $new_tags = explode(",", strtolower($this->tag)); foreach ($new_tags as $new_tag) { $new_tag = trim($new_tag); if (!in_array($new_tag, $tags)) { //If there is a new tag name add it to the list of tags $tag = new Tag(); $tag->name = $new_tag; if ($tag->save()) { $tag_id = $tag->id; $tags[$tag_id] = $tag->name; } else { $tag_id = 0; } } else { $tag_id = array_search($new_tag, $tags); } if ($tag_id) { $tags_ids[] = $tag_id; if ($current_tags) { if (!in_array($tag_id, $current_tags)) { Yii::app()->db->createCommand()->insert('subject_tag', array('subject_id' => $this->id, 'tag_id' => $tag_id)); } } else { Yii::app()->db->createCommand()->insert('subject_tag', array('subject_id' => $this->id, 'tag_id' => $tag_id)); } $current_tags[] = $tag_id; } } if (count($tags_ids) > 0) { Yii::app()->db->createCommand()->delete('subject_tag', array('and', array('subject_id=:subject_id', array(':subject_id' => $this->id)), array('not in', 'tag_id', $tags_ids))); } } //Set position for the time board if not set and if it is authorized only if ($this->authorized and !$this->position and ($this->user_position or $this->manager_position)) { $position = $this->manager_position ? $this->manager_position : $this->user_position; $type = $this->manager_position ? 'manager' : 'user'; Subject::set_position($this->id, $position, $type); } if ($this->authorized and !$this->position and (!$this->user_position and !$this->manager_position)) { Subject::model()->reschedule_positions(); } //Unset position if it has been unauthorized, disabled, or deleted if ((!$this->authorized or $this->disabled or $this->deleted) and $this->position) { Subject::model()->updateByPk($this->id, array('position' => '0')); Subject::model()->reschedule_positions(); } }