Пример #1
0
 public function actionIndex()
 {
     $prefixs = Prefix::model()->findAll();
     foreach ($prefixs as $prefix) {
         $this->updateSource($prefix);
     }
 }
Пример #2
0
 public function actionCreate1()
 {
     $model = new Link();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $model->dataset_id = 1;
     $link_database = array();
     //retrieve the database
     if (!isset($_SESSION['link_database'])) {
         $models = Prefix::model()->findAll();
         $database = array();
         foreach ($models as $m) {
             $value = $m->prefix;
             array_push($database, $value);
         }
         sort($database);
         $_SESSION['link_database'] = $database;
     }
     $link_database = $_SESSION['link_database'];
     //update
     if (!isset($_SESSION['links'])) {
         $_SESSION['links'] = array();
     }
     $links = $_SESSION['links'];
     if (isset($_POST['Link'])) {
         $link = $link_database[$_POST['Link']['database']] . ":" . $_POST['Link']['acc_num'];
         $is_primary = 1;
         $model->attributes = $_POST['Link'];
         $model->link = $link;
         $model->is_primary = $is_primary;
         $id = 0;
         if ($this->storeLink($model, $id)) {
             $link_type = "ext_acc_mirror";
             if ($is_primary == 0) {
                 $link_type = "ext_acc_link";
             }
             $newItem = array('id' => $id, 'link' => $link, 'link_type' => $link_type);
             array_push($links, $newItem);
             $_SESSION['links'] = $links;
             $vars = array('links');
             //Dataset::storeSession($vars);
             $model = new Link();
         }
     }
     $link_model = new CArrayDataProvider($links);
     $this->render('create1', array('model' => $model, 'link_model' => $link_model, 'link_database' => $link_database));
 }
Пример #3
0
 public function getFullUrl($source = '')
 {
     $temp = explode(":", trim($this->link));
     $prefix = $temp[0];
     $value = $temp[1];
     $model = Prefix::model()->find("lower(prefix) = :p and source = :s", array(':p' => strtolower($prefix), ':s' => $source));
     // find url with preferred source
     if ($model) {
         return $model->url . $value;
     }
     // if not get available url
     $model = Prefix::model()->find("lower(prefix) = :p", array(':p' => strtolower($prefix)));
     if ($model) {
         return $model->url . $value;
     }
     return "#";
 }
 /**
  * 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 = Prefix::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Пример #5
0
 public function getLinkName()
 {
     $prefix = "SAMPLE:";
     $len = strlen($prefix);
     $name = $this->name;
     $prefer = 'EBI';
     if (!Yii::app()->user->isGuest) {
         $user = User::model()->findByPk(Yii::app()->user->_id);
         if ($user) {
             $prefer = $user->preferred_link;
         }
     }
     if (substr($name, 0, $len) == $prefix) {
         $linkName = substr($name, $len, strlen($name));
         $prefix_text = 'sample';
         $criteria = new CDbCriteria();
         $criteria->compare('lower(prefix)', $prefix_text);
         $criteria->compare('source', $prefer);
         $criteria->limit = 1;
         $prefix_models = Prefix::model()->findAll($criteria);
         if (!$prefix_models) {
             $criteria = new CDbCriteria();
         }
         $criteria->compare('lower(prefix)', $prefix_text);
         $criteria->limit = 1;
         $prefix_models = Prefix::model()->findAll($criteria);
         $link = '';
         if ($prefix_models) {
             $link = $prefix_models[0]->url . $linkName;
         }
         return CHtml::link($linkName, $link, array('target' => '_blank'));
     }
     return $name;
 }