/**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndexing()
 {
     ini_set('max_execution_time', 0);
     ob_start();
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias($this->_indexFilesPath), true);
     $criteria = new CDbCriteria();
     $criteria->compare('t.publish', 1);
     $criteria->order = 'album_id DESC';
     //$criteria->limit = 10;
     $model = Albums::model()->findAll($criteria);
     foreach ($model as $key => $item) {
         if ($item->media_id != 0) {
             $images = Yii::app()->request->baseUrl . '/public/album/' . $item->album_id . '/' . $item->cover->media;
         } else {
             $images = '';
         }
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', CHtml::encode($item->album_id), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('media', CHtml::encode($images), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('title', CHtml::encode($item->title), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('body', CHtml::encode(Utility::hardDecode(Utility::softDecode($item->body))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('url', CHtml::encode(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('album/site/view', array('id' => $item->album_id, 't' => Utility::getUrlTitle($item->title)))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('date', CHtml::encode(Utility::dateFormat($item->creation_date, true) . ' WIB'), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('creation', CHtml::encode($item->user->displayname), 'utf-8'));
         $index->addDocument($doc);
     }
     echo 'Album Lucene index created';
     $index->commit();
     $this->redirect(Yii::app()->createUrl('article/search/indexing'));
     ob_end_flush();
 }
 public function actionShow($id, $mid)
 {
     Yii::app()->clientScript->registerScript('global_user_id', 'var glUserId = ' . $id . ';', CClientScript::POS_HEAD);
     $user = UserProfile::model()->getUserProfile($id);
     $myPage = Yii::app()->user->id == $id;
     if ($album = Albums::model()->find('user_id=:user_id AND id = :album_id', array('user_id' => $id, 'album_id' => $mid))) {
         $model = Photos::model();
         $photos = $model->LoadLimited($mid, 0);
         $list = $this->renderPartial('//profile/aphotos/photos_list', array('photos' => $photos, 'user_id' => $id), true);
         $this->render('photos', array('model' => $model, 'profile' => $user, 'myPage' => $myPage, 'album' => $album, 'photos_count' => count($photos), 'list' => $list));
     } else {
         echo 'Альбом не существует.';
     }
 }
 protected function renderContent()
 {
     $controller = strtolower(Yii::app()->controller->id);
     //import model
     Yii::import('application.modules.album.models.AlbumPhoto');
     Yii::import('application.modules.album.models.Albums');
     $criteria = new CDbCriteria();
     $criteria->condition = 'publish = :publish';
     $criteria->params = array(':publish' => 1);
     $criteria->order = 'creation_date DESC';
     $criteria->limit = 3;
     $model = Albums::model()->findAll($criteria);
     $this->render('album_recents', array('model' => $model));
 }
Exemple #4
0
 public function getDetailAlbumByUser($user_id)
 {
     $returnArr = array();
     $data = Albums::model()->findAllByAttributes(array('user_id' => $user_id));
     foreach ($data as $item) {
         $itemArr = array();
         $itemArr['album_id'] = $item->album_id;
         $itemArr['album_name'] = $item->album_name;
         $itemArr['updated_at'] = date('d/m/Y', $item->created_at);
         $itemArr['number_posts'] = $this->countNumberPostAlbum($item->album_id);
         $itemArr['images_preview'] = $this->getRandomPostOfAlbum($item->album_id);
         $itemArr['description'] = $item->description;
         $returnArr[] = $itemArr;
     }
     return $returnArr;
 }
 public function actionIndex()
 {
     if (!empty($_POST)) {
         $images = CUploadedFile::getInstancesByName('images');
         if (isset($images) && count($images) > 0) {
             // go through each uploaded image
             foreach ($images as $image => $pic) {
                 $model = new Images();
                 $model->scenario = 'image';
                 $imageName = $this->getFileName($pic);
                 $model->image = $imageName;
                 if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName)) {
                     $model->link = $imageName;
                     $model->name = $pic->name;
                     $model->created = time();
                     $model->album_id = Images::$IMAGE_PHOTO;
                     //dump($model);
                     if ($model->save()) {
                         Yii::app()->user->setFlash('success', translate('Thêm thành công.'));
                     } else {
                         dump($model->errors);
                     }
                 }
                 // handle the errors here, if you want
             }
         }
         $this->redirect(PIUrl::createUrl('admin/images/index'));
     }
     $criteria = new CDbCriteria();
     $criteria->condition = 'album_id=:album_id';
     $criteria->order = 'id DESC';
     $criteria->params = array(':album_id' => Images::$IMAGE_PHOTO);
     $count = Images::model()->count($criteria);
     $pages = new CPagination($count);
     // results per page
     $pages->pageSize = 18;
     $pages->applyLimit($criteria);
     $listImage = Images::model()->findAll($criteria);
     //dump($model);
     $dataAlbums = Albums::model()->getAlbums();
     $this->render('index', compact('pages', 'dataAlbums', 'listImage'));
 }
 protected function renderContent()
 {
     $controller = strtolower(Yii::app()->controller->id);
     //import model
     Yii::import('application.modules.album.models.AlbumPhoto');
     Yii::import('application.modules.album.models.Albums');
     Yii::import('application.modules.album.models.AlbumTag');
     $criteria = new CDbCriteria();
     if ($this->hastag != null) {
         $criteria->with = array('tag_ONE' => array('alias' => 'a'), 'tag_ONE.tag_TO' => array('alias' => 'b'));
         $criteria->condition = 't.publish = :publish AND b.body = :body';
         $criteria->params = array(':publish' => 1, ':body' => $this->hastag);
     } else {
         $criteria->condition = 't.ublish = :publish';
         $criteria->params = array(':publish' => 1);
     }
     $criteria->order = 't.creation_date DESC';
     $criteria->limit = 6;
     $model = Albums::model()->findAll($criteria);
     $this->render('album_main_recents', array('model' => $model));
 }
 public function deletePhotosInAlbum($album_id, $album = null)
 {
     $photos = $this->findAll(array('select' => 'file', 'condition' => 'album_id = :album_id', 'params' => array(':album_id' => $album_id)));
     if ($album == null) {
         $album = Albums::model()->findByPk($album_id);
     }
     foreach ($photos as $photo) {
         $this->deleteItem($photo, $album, null, false);
     }
 }
 public function actionUpdate($id = null)
 {
     $model = Albums::model()->findByPk($id);
     $flag = 0;
     $image_old = $model->attributes['image'];
     if (!empty($_POST['Albums'])) {
         if (!empty(CUploadedFile::getInstance($model, 'image')->name)) {
             $image_old = $model->attributes['image'];
             $path = realpath(Yii::app()->basePath . '/../upload/images/' . $image_old);
             if (file_exists($path) && !empty($image_old)) {
                 unlink($path);
             }
             $model->attributes = $_POST['Albums'];
             $model->image = CUploadedFile::getInstance($model, 'image');
             $image = $model->image;
             $imageType = explode('.', $model->image->name);
             $imageType = $imageType[count($imageType) - 1];
             $imageName = md5(uniqid()) . '.' . $imageType;
             $model->image = $imageName;
             $images_path = Yii::getPathOfAlias('webroot') . '/upload/images/' . $imageName;
             $flag = 1;
         } else {
             $model->attributes = $_POST['Albums'];
             $model->image = $image_old;
         }
         $model->created = time();
         $model->alias = alias($_POST['Albums']['name']);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', translate('Cập nhật thành công.'));
             if ($flag == 1) {
                 $image->saveAs($images_path);
             }
             $this->redirect(PIUrl::createUrl('/admin/albums/'));
         }
     }
     $this->render('update', array('model' => $model));
 }
 public function actionSet_poster_photo($mid)
 {
     $photo = Photos::model()->findByPk($mid);
     if ($album = Albums::model()->find('user_id = :my_id AND id = :album_id', array(':my_id' => Yii::app()->user->id, ':album_id' => $photo['album_id']))) {
         $album->current_photo = $mid;
         $album->save();
         $status = 'ok';
     } else {
         $status = 'no_album';
     }
     echo json_encode(array('status' => $status));
 }
Exemple #10
0
 public function actionGetAlbumByUser()
 {
     $albums = Albums::model()->getAlbumByUser(Yii::app()->session['user_id']);
     //ResponseHelper::JsonReturnSuccess($albums, 'Success');
     $html = $this->renderPartial('listAlbums', array('albums' => $albums), true);
     echo $html;
 }
 /**
  * Albums get information
  */
 public function searchIndexing($index)
 {
     Yii::import('application.modules.album.models.*');
     $criteria = new CDbCriteria();
     $criteria->compare('t.publish', 1);
     $criteria->order = 'album_id DESC';
     //$criteria->limit = 10;
     $model = Albums::model()->findAll($criteria);
     foreach ($model as $key => $item) {
         if ($item->media_id != 0) {
             $images = Yii::app()->request->baseUrl . '/public/album/' . $item->album_id . '/' . $item->cover->media;
         } else {
             $images = '';
         }
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', CHtml::encode($item->album_id), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('media', CHtml::encode($images), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('title', CHtml::encode($item->title), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('body', CHtml::encode(Utility::hardDecode(Utility::softDecode($item->body))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('url', CHtml::encode(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('album/site/view', array('id' => $item->album_id, 't' => Utility::getUrlTitle($item->title)))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('date', CHtml::encode(Utility::dateFormat($item->creation_date, true) . ' WIB'), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('creation', CHtml::encode($item->user->displayname), 'utf-8'));
         $index->addDocument($doc);
     }
     return true;
 }
 /**
  * Get Album
  */
 public static function getAlbum($id, $type = null)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('cat_id', $id);
     if ($type == null) {
         //$criteria->select = '';
         $model = Albums::model()->findAll($criteria);
     } else {
         $model = Albums::model()->count($criteria);
     }
     return $model;
 }
Exemple #13
0
 public function getTitleById($id)
 {
     return Albums::model()->find(array('select' => 'title', 'condition' => 'id=:id', 'params' => array(':id' => $id)));
 }
 /**
  * After save attributes
  */
 protected function afterSave()
 {
     parent::afterSave();
     //set flex cover in album
     //if($this->cover == 1 || count(self::getPhoto($this->album_id)) == 1) {
     if ($this->cover == 1) {
         $cover = Albums::model()->findByPk($this->album_id);
         $cover->media_id = $this->media_id;
         $cover->update();
     }
     $setting = AlbumSetting::getInfo('photo_limit, photo_resize, photo_resize_size', 'many');
     $photo_limit = $setting->photo_limit;
     $photo_resize = $setting->photo_resize;
     $photo_resize_size = $setting->photo_resize_size;
     if ($this->album->cat->default_setting == 0) {
         $photo_limit = $this->album->cat->photo_limit;
         $photo_resize = $this->album->cat->photo_resize;
         $photo_resize_size = $this->album->cat->photo_resize_size;
     }
     //create thumb image
     if ($photo_resize == 1) {
         Yii::import('ext.phpthumb.PhpThumbFactory');
         $album_path = 'public/album/' . $this->album_id;
         $albumImg = PhpThumbFactory::create($album_path . '/' . $this->media, array('jpegQuality' => 90, 'correctPermissions' => true));
         $resizeSize = unserialize($photo_resize_size);
         if ($resizeSize['height'] == 0) {
             $albumImg->resize($resizeSize['width']);
         } else {
             $albumImg->adaptiveResize($resizeSize['width'], $resizeSize['height']);
         }
         $albumImg->save($album_path . '/' . $this->media);
     }
     //delete other photo (if photo_limit = 1)
     if ($photo_limit == 1) {
         self::model()->deleteAll(array('condition' => 'album_id = :id AND cover = :cover', 'params' => array(':id' => $this->album_id, ':cover' => 0)));
     }
 }
 /**
  * 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 = Albums::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.'));
     }
     return $model;
 }
Exemple #16
0
 public function actionAddAlbum()
 {
     $post = StringHelper::filterArrayString($_POST);
     if (Albums::model()->add($post)) {
         ResponseHelper::JsonReturnSuccess('', 'Success');
     } else {
         ResponseHelper::JsonReturnError('', 'Error');
     }
 }
 /**
  * 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 = Albums::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Phrase::trans(193, 0));
     }
     return $model;
 }
Exemple #18
0
 public static function getCategoryByUser($user_id)
 {
     $albums = Albums::model()->findAllByAttributes(array('user_id' => $user_id));
     return $albums;
 }
Exemple #19
0
			</div>
			<div class="box">
			<?php 
if (!empty($arrImage)) {
    ?>
				<ul class="list-img">
					<?php 
    foreach ($arrImage as $image) {
        ?>
					<li>
						<a href="<?php 
        echo PIUrl::createUrl('/home/image/', array("id" => $image->id));
        ?>
">
							<img src="<?php 
        echo Albums::model()->getImagePrimary($image->id, 262, 121);
        ?>
" alt="img" width="265" height="122">
							<p title="<?php 
        echo $image->name;
        ?>
"><?php 
        echo word_limiter($image->name, 15);
        ?>
</p>
						</a>
					</li>
					<?php 
    }
    ?>
				</ul>