public static function trans($id, $type, $other = null)
 {
     if ($type == 1) {
         $model = OmmuPluginPhrase::model()->findByPk($id);
     } else {
         if ($type == 2) {
             $model = OmmuSystemPhrase::model()->findByPk($id);
         }
     }
     if (isset(Yii::app()->session['language'])) {
         $language = Yii::app()->session['language'];
         $language = 'en_us';
         if ($model->{$language} == '') {
             $language = 'en_us';
         }
     } else {
         $language = 'en_us';
     }
     if (!empty($other)) {
         $replace = array();
         $search = array();
         $i = 0;
         foreach ($other as $label => $url) {
             $i++;
             if (is_string($label) || is_array($url)) {
                 //$replace[] = CHtml::link($this->getEncodeLabel() ? CHtml::encode($label) : $label, $url, array('title'=>$label));
                 $replace[] = CHtml::link($label, $url, array('title' => $label));
             } else {
                 //$replace[] = $this->getEncodeLabel() ? CHtml::encode($url) : $url;
                 $replace[] = $url;
             }
             $search[] = '$' . $i . '';
         }
         $phrase = str_replace($search, $replace, $model->{$language});
     } else {
         $phrase = $model->{$language};
     }
     return $phrase;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = OmmuSystemPhrase::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.'));
     }
     return $model;
 }
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         //Media Name and Description
         if ($this->isNewRecord) {
             $location = strtolower(Yii::app()->controller->module->id . '/' . Yii::app()->controller->id);
             $title = new OmmuSystemPhrase();
             $title->location = $location . '_title';
             $title->en_us = $this->title;
             if ($title->save()) {
                 $this->name = $title->phrase_id;
             }
             $desc = new OmmuSystemPhrase();
             $desc->location = $location . '_description';
             $desc->en_us = $this->description;
             if ($desc->save()) {
                 $this->desc = $desc->phrase_id;
             }
         } else {
             $title = OmmuSystemPhrase::model()->findByPk($this->name);
             $title->en_us = $this->title;
             $title->save();
             $desc = OmmuSystemPhrase::model()->findByPk($this->desc);
             $desc->en_us = $this->description;
             $desc->save();
         }
         //Media Size
         $this->media_size = $this->media_size_width . ',' . $this->media_size_height;
     }
     return true;
 }
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $action = strtolower(Yii::app()->controller->action->id);
         $location = strtolower(Yii::app()->controller->id);
         if ($this->isNewRecord) {
             $title = new OmmuSystemPhrase();
             $title->location = $location . '_title';
             $title->en_us = $this->title;
             if ($title->save()) {
                 $this->name = $title->phrase_id;
             }
             $desc = new OmmuSystemPhrase();
             $desc->location = $location . '_description';
             $desc->en_us = $this->description;
             if ($desc->save()) {
                 $this->desc = $desc->phrase_id;
             }
             $quote = new OmmuSystemPhrase();
             $quote->location = $location . '_quotes';
             $quote->en_us = $this->quotes;
             if ($quote->save()) {
                 $this->quote = $quote->phrase_id;
             }
         } else {
             $title = OmmuSystemPhrase::model()->findByPk($this->name);
             $title->en_us = $this->title;
             $title->save();
             $desc = OmmuSystemPhrase::model()->findByPk($this->desc);
             $desc->en_us = $this->description;
             $desc->save();
             if ($this->quote != 0) {
                 $quote = OmmuSystemPhrase::model()->findByPk($this->quote);
                 $quote->en_us = $this->quotes;
                 $quote->save();
             } else {
                 $quote = new OmmuSystemPhrase();
                 $quote->location = $location . '_quotes';
                 $quote->en_us = $this->quotes;
                 if ($quote->save()) {
                     $this->quote = $quote->phrase_id;
                 }
             }
         }
         //upload new photo
         if (in_array($action, array('add', 'edit'))) {
             $page_path = "public/page";
             $this->media = CUploadedFile::getInstance($this, 'media');
             if ($this->media instanceof CUploadedFile) {
                 $fileName = time() . '_' . Utility::getUrlTitle(Phrase::trans($this->name, 2)) . '.' . strtolower($this->media->extensionName);
                 if ($this->media->saveAs($page_path . '/' . $fileName)) {
                     //create thumb image
                     Yii::import('ext.phpthumb.PhpThumbFactory');
                     $pageImg = PhpThumbFactory::create($page_path . '/' . $fileName, array('jpegQuality' => 90, 'correctPermissions' => true));
                     $pageImg->resize(700);
                     if ($pageImg->save($page_path . '/' . $fileName)) {
                         $this->media_show = 1;
                         $this->media_type = 1;
                     }
                     if (!$this->isNewRecord && $this->old_media != '' && file_exists($page_path . '/' . $this->old_media)) {
                         rename($page_path . '/' . $this->old_media, 'public/page/verwijderen/' . $this->page_id . '_' . $this->old_media);
                     }
                     $this->media = $fileName;
                 }
             }
             if (!$this->isNewRecord && $this->media == '') {
                 $this->media = $this->old_media;
             }
         }
     }
     return true;
 }
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $action = strtolower(Yii::app()->controller->action->id);
         if ($this->isNewRecord) {
             $location = strtolower(Yii::app()->controller->module->id . '/' . Yii::app()->controller->id);
             $title = new OmmuSystemPhrase();
             $title->location = $location . '_title';
             $title->en_us = $this->title;
             if ($title->save()) {
                 $this->name = $title->phrase_id;
             }
         } else {
             $title = OmmuSystemPhrase::model()->findByPk($this->name);
             $title->en_us = $this->title;
             $title->save();
         }
         //upload proposal
         if (in_array($action, array('add', 'edit'))) {
             $support_path = "public/support";
             $this->icons = CUploadedFile::getInstance($this, 'icons');
             if ($this->icons instanceof CUploadedFile) {
                 $fileName = Utility::getUrlTitle($this->title) . '_' . time() . '.' . strtolower($this->icons->extensionName);
                 if ($this->icons->saveAs($support_path . '/' . $fileName)) {
                     if (!$this->isNewRecord && $this->old_icon != '' && file_exists($support_path . '/' . $this->old_icon)) {
                         rename($support_path . '/' . $this->old_icon, 'public/support/verwijderen/' . $this->cat_id . '_' . $this->old_icon);
                     }
                     $this->icons = $fileName;
                 }
             }
             if (!$this->isNewRecord && $this->icons == '') {
                 $this->icons = $this->old_icon;
             }
         }
     }
     return true;
 }
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $action = strtolower(Yii::app()->controller->action->id);
         if ($this->isNewRecord) {
             $currentAction = strtolower(Yii::app()->controller->module->id . '/' . Yii::app()->controller->id);
             $title = new OmmuSystemPhrase();
             $title->location = $currentAction;
             $title->en_us = $this->title;
             if ($title->save()) {
                 $this->name = $title->phrase_id;
             }
             $desc = new OmmuSystemPhrase();
             $desc->location = $currentAction;
             $desc->en_us = $this->description;
             if ($desc->save()) {
                 $this->desc = $desc->phrase_id;
             }
         } else {
             if ($action == 'edit') {
                 $title = OmmuSystemPhrase::model()->findByPk($this->name);
                 $title->en_us = $this->title;
                 $title->save();
                 $desc = OmmuSystemPhrase::model()->findByPk($this->desc);
                 $desc->en_us = $this->description;
                 $desc->save();
             }
             // set to default modules
             if ($this->defaults == 1) {
                 self::model()->updateAll(array('defaults' => 0));
                 $this->defaults = 1;
             }
         }
     }
     return true;
 }
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $location = strtolower(Yii::app()->controller->id);
             $title = new OmmuSystemPhrase();
             $title->location = $location . '_title';
             $title->en_us = $this->title;
             if ($title->save()) {
                 $this->name = $title->phrase_id;
             }
         } else {
             $title = OmmuSystemPhrase::model()->findByPk($this->name);
             $title->en_us = $this->title;
             $title->save();
         }
     }
     return true;
 }
 /**
  * before save attributes
  */
 protected function beforeSave()
 {
     $controller = strtolower(Yii::app()->controller->id);
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $location = strtolower(Yii::app()->controller->module->id . '/' . Yii::app()->controller->id);
             $title = new OmmuSystemPhrase();
             $title->location = $location . '_title';
             $title->en_us = $this->title;
             if ($title->save()) {
                 $this->name = $title->phrase_id;
             }
             $desc = new OmmuSystemPhrase();
             $desc->location = $location . '_description';
             $desc->en_us = $this->description;
             if ($desc->save()) {
                 $this->desc = $desc->phrase_id;
             }
         } else {
             $title = OmmuSystemPhrase::model()->findByPk($this->name);
             $title->en_us = $this->title;
             $title->save();
             $desc = OmmuSystemPhrase::model()->findByPk($this->desc);
             $desc->en_us = $this->description;
             $desc->save();
             // category set to default
             if ($this->default == 1) {
                 self::model()->updateAll(array('default' => 0));
                 $this->default = 1;
             }
         }
         $this->photo_resize_size = serialize($this->photo_resize_size);
         $this->photo_view_size = serialize($this->photo_view_size);
     }
     return true;
 }