Esempio n. 1
0
 public function deleteAlbum($user_id, $album_id)
 {
     if ($album = $this->find('user_id = :my_id AND id = :album_id', array(':my_id' => $user_id, ':album_id' => $album_id))) {
         Photos::model()->deletePhotosInAlbum($album_id);
         $album->delete();
     }
 }
Esempio n. 2
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     try {
         $model = $this->loadModel($id);
         $content = $model->content;
         $pattern = '/[{]G[0-9]{3,6}[}]/';
         preg_match_all($pattern, $content, $matches);
         if (!empty($matches)) {
             for ($i = 0; $i < count($matches[0]); $i++) {
                 if (!empty($matches[0][$i])) {
                     $code = $matches[0][$i];
                     $gallery_id = Galleries::model()->find(array('condition' => 'code = "' . $code . '"'))->id;
                     if (!empty($gallery_id)) {
                         $photos = Photos::model()->findAll(array('condition' => 'gallery_id =' . $gallery_id));
                         $htmlReplace = ActiveRecord::getHtmlGalleryBox($photos);
                     }
                 }
                 $content = str_replace($code, $htmlReplace, $content);
             }
         }
         $this->render('view', array('model' => $model, 'content' => $content, 'actions' => $this->listActionsCanAccess));
     } catch (Exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }
 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 'Альбом не существует.';
     }
 }
Esempio n. 4
0
 public function actionDeletePhotoHandler()
 {
     if ($model = Photos::model()->findByPk(getParam('id'))) {
         $model->delete();
         $this->successfulAjaxResponse();
     } else {
         $this->unsuccessfulAjaxResponse();
     }
 }
 public function actionDelete_photo($mid)
 {
     $photos = Photos::model();
     $photo = $photos->findByPk($mid);
     $album_id = $photo['album_id'];
     $status = $photos->deleteItem($photo);
     $count = $photos->count('album_id = :album_id', array('album_id' => $album_id));
     echo json_encode(array('status' => $status, 'count' => $count));
 }
Esempio n. 6
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 = Photos::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Esempio n. 7
0
 public function addFiles($post_id)
 {
     $folder = Yii::getPathOfAlias('webroot') . '/upload';
     foreach ($_POST['files'] as $files) {
         foreach ($files as $object_id => $type) {
             $this->isNewRecord = true;
             $this->id = 0;
             $this->posts_id = $post_id;
             $this->upload_date = time();
             if ($type == 'album') {
                 if ($photo = Photos::model()->findByPk($object_id)) {
                     if (file_exists($folder . '/photos/' . $photo['filename'])) {
                         $this->filename = $photo['filename'];
                         $this->type = 'photos';
                         $this->description = $photo['description'];
                         $this->save();
                     }
                 }
             } elseif ($type == 'uploaded') {
                 if ($temp = TemporaryFiles::model()->findByPk($object_id)) {
                     if (file_exists($folder . '/photos/' . $temp['filename'])) {
                         $this->filename = $temp['filename'];
                         $this->type = 'photos';
                         $this->description = $temp['description'];
                         $this->save();
                     }
                     $temp->delete();
                 }
             }
         }
     }
 }
 public function actionMore($id)
 {
     $photo_id_list = Bookmarks::model()->content_id_list($id, 1);
     $idcond = empty($photo_id_list) ? '0' : implode(' OR `id`=', $photo_id_list);
     $cond = '`id`=' . $idcond;
     $photos = Photos::model()->ParametrizedLoadLimited($cond, $_POST['offset']);
     $list = $this->renderPartial('_photos_list', array('photos' => $photos, 'user_id' => $id), true);
     echo json_encode(array('photos_count' => count($photos), 'data' => $list));
 }