Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new App();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['App'])) {
         $model->attributes = $_POST['App'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     try {
         $model = new App();
         $association = new AppUsers();
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['App'])) {
             $model->attributes = $_POST['App'];
             //  $association->attributes=$_POST['AppUsers'];
             //$model->setAttribute('id_users', Yii::app()->user->id);
             $usuario = Yii::app()->user->id;
             //salvando a relacao com a tabela Platforms
             $model->setRelationRecords('platforms', is_array(@$_POST['Platforms']) ? $_POST['Platforms'] : array());
             //salvando a relacao com a tabela Languages
             $model->setRelationRecords('languages', is_array(@$_POST['Languages']) ? $_POST['Languages'] : array());
             //salvando a relacao com a tabela category
             $model->setRelationRecords('category', is_array(@$_POST['Category']) ? $_POST['Category'] : array());
             //salvando a relacao com a tabela share
             //   $model->setRelationRecords('users', is_array($usuario) ? $usuario : array());
             $model->setRelationRecords('users', is_array(array($usuario)) ? array($usuario) : array());
             // $association->save(false);
             if ($model->save()) {
                 //  $association->setAttribute('id_app', $model->id);
                 //$association->setAttribute('id_users', $usuario);
                 //$association->save(false);
                 Yii::app()->user->setFlash('success', "App saved with sucess!");
                 //  echo 'alert("AVISO!\nUma mensagekfkm foi enviada para o email cadastrado.")';
                 //$this->redirect(array('view','id'=>$model->id));
                 // $this->redirect(array('runs/create', 'id' => $model->id));
                 Yii::app()->controller->refresh();
             }
         }
     } catch (Exception $e) {
         Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, '<strong>Ops!</strong> ERROR!');
         Yii::app()->controller->refresh();
     }
     $this->render('create', array('model' => $model));
 }
 protected function icons_in_post($full_post)
 {
     $post = $full_post['.postmsg'][0];
     if (strpos($post->html(), '<img') === false) {
         return array();
     }
     $post_text = self::clean_up_post($post);
     $artist_name = $full_post['.postleft dt'][0]->text();
     $post_imgs = $post['img.postimg'];
     if (empty($post_imgs)) {
         return array();
     }
     $icons = self::find_icon_names_in_post($post_imgs, $post_text);
     $post_icons = array();
     foreach ($icons as $img_src => $name) {
         $icon = Make::an('Icon')->like('src', $img_src)->first();
         $changed = false;
         if (!$icon) {
             $icon = new Icon();
             $icon->src = $img_src;
             $icon->theme_id = $this->theme->id;
             // TODO: make this DRYer too
             if ($artist_name) {
                 $artist = Make::an('Artist')->like('name', $artist_name)->first();
                 if (!$artist) {
                     $artist = new Artist();
                     $artist->name = $artist_name;
                     $artist->save();
                 }
                 $icon->setArtist($artist);
             }
             $changed = true;
         }
         if ($name && !$icon->app()) {
             $app = Make::an('App')->like('name', $name)->first();
             if (!$app) {
                 $app = new App();
                 $app->name = $name;
                 $app->save();
             }
             $icon->setApp($app);
             $changed = true;
         }
         if ($changed) {
             $icon->save();
         }
         $post_icons[] = $icon;
     }
     /*
     		$matches = array();
     		$maybe_names = array();
     
     		if (preg_match('/(([a-z0-9\-]{2,}), )+([a-z0-9\- ]{2,})/i', $post_text, $matches)) {
     			$maybe_names = explode(',', $matches[0]); # [0] == entire match
     			$maybe_names = array_map('trim', $maybe_names);
     		} else {
     			$w = self::WORD_REGEXP;
     			$and_match = array();
     			if (preg_match('/'.$w.' and '.$w.'/iu', $post_text, $and_match)) {
     				$maybe_names = explode(' and ', $and_match[0]);
     				$maybe_names = array_map('trim', $maybe_names);
     			}
     		}
     
     		if ($maybe_names) {
     			foreach ($post_icons as &$post_icon) {
     				$post_icon->maybe_names = array_merge($post_icon->maybe_names, $maybe_names);
     			}
     		}
     */
     return $post_icons;
 }