示例#1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Albums();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Albums'])) {
         $model->attributes = $_POST['Albums'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'id' => Yii::app()->user->id));
 }
示例#2
0
 public function add($post)
 {
     $model = new Albums();
     $model->setAttributes($post);
     $model->created_at = time();
     $model->status = 1;
     $model->user_id = Yii::app()->session['user_id'];
     $model->updated_at = time();
     if ($model->save(FALSE)) {
         return TRUE;
     }
     return FALSE;
 }
示例#3
0
文件: User.php 项目: huynt57/fashion
 public function processLoginWithFacebook($facebook_id, $age, $gender, $facebook_access_token, $photo, $username, $device_id)
 {
     $check = User::model()->findByAttributes(array('facebook_id' => $facebook_id));
     if ($check) {
         $check->updated_at = time();
         if ($check->save(FALSE)) {
             Yii::app()->session['user_id'] = $check->id;
             Yii::app()->session['user_avatar'] = $check->photo;
             ResponseHelper::JsonReturnSuccess($check, "Success");
         } else {
             ResponseHelper::JsonReturnError("", "Server Error");
         }
     } else {
         $model = new User();
         $model->facebook_id = $facebook_id;
         $model->age = $age;
         $model->gender = $gender;
         $model->facebook_access_token = $facebook_access_token;
         $model->photo = $photo;
         $model->username = $username;
         $model->device_id = $device_id;
         $model->created_at = time();
         $model->updated_at = time();
         $model->status = 1;
         if ($model->save(FALSE)) {
             Yii::app()->session['user_id'] = $model->id;
             Yii::app()->session['user_avatar'] = $model->photo;
             $album = new Albums();
             $album->user_id = $model->id;
             $album->album_name = 'Album chưa phân loại';
             $album->created_at = time();
             $album->updated_at = time();
             $album->status = 1;
             if ($album->save(FALSE)) {
                 ResponseHelper::JsonReturnSuccess($model, "Success");
             } else {
                 ResponseHelper::JsonReturnError("", "Server Error");
             }
         } else {
             ResponseHelper::JsonReturnError("", "Server Error");
         }
     }
 }
示例#4
0
<?php

// Get an existing artist
$artist = Artists::findFirst('name = "Shinichi Osawa"');
// Create an album
$album = new Albums();
$album->name = 'The One';
$album->artist = $artist;
$songs = array();
// Create a first song
$songs[0] = new Songs();
$songs[0]->name = 'Star Guitar';
$songs[0]->duration = '5:54';
// Create a second song
$songs[1] = new Songs();
$songs[1]->name = 'Last Days';
$songs[1]->duration = '4:29';
// Assign the songs array
$album->songs = $songs;
// Save the album + its songs
$album->save();
 public function actionSave($id)
 {
     $my_id = Yii::app()->user->id;
     $albums = new Albums();
     if ($_POST['album_set'] == '1') {
         $albums->title = $_POST['album_create'];
         $albums->create_date = time();
         $albums->current_photo = 0;
         $albums->user_id = $my_id;
         $albums->save();
     } else {
         $albums = $albums->find('user_id = :user_id AND id = :album_id', array(':user_id' => $my_id, ':album_id' => $_POST['albom_sel']));
     }
     $photos = new Photos();
     $temp = new Files();
     $photos_ids = explode(',', $_POST['photo_ids']);
     foreach ($photos_ids as $photo_id) {
         if ($photo_id != '') {
             if ($temp_file = $temp->findByPk($photo_id)) {
                 $photos->isNewRecord = true;
                 $photos->id = 0;
                 $photos->album_id = $albums->id;
                 $photos->file = $temp_file->id;
                 $photos->description = $_POST['photo_description'][$temp_file->id];
                 $photos->upload_date = time();
                 $photos->place_id = 0;
                 $photos->save();
             }
         }
     }
     $this->redirect(Yii::app()->createUrl('/id' . $id . '/photos/show/' . $albums->id));
 }
示例#6
0
 public function actionAddCategoryForUser()
 {
     $users = User::model()->findAll();
     foreach ($users as $user) {
         $album = new Albums();
         $album->user_id = $user->id;
         $album->album_name = 'Album chưa phân loại';
         $album->created_at = time();
         $album->updated_at = time();
         $album->status = 1;
         if ($album->save(FALSE)) {
             $posts = Posts::model()->findAllByAttributes(array('user_id' => $user->id));
             foreach ($posts as $post) {
                 $post->album_id = $album->album_id;
                 $post->save(FALSE);
             }
         }
     }
 }