本文整理汇总了PHP中Photo::getMaxIdPhoto方法的典型用法代码示例。如果您正苦于以下问题:PHP Photo::getMaxIdPhoto方法的具体用法?PHP Photo::getMaxIdPhoto怎么用?PHP Photo::getMaxIdPhoto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Photo
的用法示例。
在下文中一共展示了Photo::getMaxIdPhoto方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionPhoto
public function actionPhoto()
{
$model = new Photo('upload');
if (isset($_POST['Photo'])) {
$model->attributes = $_POST['Photo'];
if ($model->validate()) {
$model->id_user = Yii::app()->user->id;
$model->id_photo = Photo::getMaxIdPhoto();
//max(id_photo) where current user
if (!$model->save()) {
throw new CHttpException('500', 'Ошибка записи в БД');
}
$model->file = CUploadedFile::getInstance($model, 'file');
if ($model->file != NULL) {
/** @var $model->file CUploadedFile */
// $model->file->
$model->file->saveAs(Yii::getPathOfAlias('webroot') . '/' . $model->getFullImagePath());
$model->path = $model->getLargeImagePath();
$model->saveSmallPictures();
$model->save(false);
//not validate (WHY???)
// if it's first photo, make it mainphoto
if ($model->id_photo == 1) {
$user = Anketa::model()->findByPk(Yii::app()->user->id);
$user->mainphoto = $model->id_photo;
// not const, for next changing
$user->saveAttributes(array('mainphoto'));
}
/*
$file_name = '/p/9000/'.Yii::app()->user->id.'_'.$model->id_photo.'_l.JPG';
$imginfo = getimagesize($_SERVER['DOCUMENT_ROOT'].$file_name);
$image = Yii::app()->image->load($_SERVER['DOCUMENT_ROOT'].$file_name);
if ($imginfo[0]>Photo::$sizes['full'][0] || $imginfo[1]>Photo::$sizes['full'][1] )
$image->resize(Photo::$sizes['full'][0], Photo::$sizes['full'][1]);
$image->quality(100)->save();
$file_name = '/p/6000/'.Yii::app()->user->id.'_'.$model->id_photo.'_l.JPG';
if ($imginfo[0]>Photo::$sizes['large'][0] || $imginfo[1]>Photo::$sizes['large'][1] )
$image->resize(Photo::$sizes['large'][0], Photo::$sizes['large'][1]);
$image->quality(100)->save($_SERVER['DOCUMENT_ROOT'].$file_name);
TmpHelper::addLogo($_SERVER['DOCUMENT_ROOT'].$file_name);
$model->path = $file_name;
$file_name = '/p/7000/'.Yii::app()->user->id.'_'.$model->id_photo.'_l.JPG';
if ($imginfo[0]>Photo::$sizes['small'][0] || $imginfo[1]>Photo::$sizes['small'][1])
$image->resize(Photo::$sizes['small'][0], Photo::$sizes['small'][1]);
$image->quality(100)->save($_SERVER['DOCUMENT_ROOT'].$file_name);
TmpHelper::addLogo($_SERVER['DOCUMENT_ROOT'].$file_name);
$model->saveAttributes(array('path')); */
}
//echo 'uploaded';
Yii::app()->user->setFlash('profile', 'Фотография загружена');
$this->redirect(array('/profile/photos'));
// form inputs are valid, do something here
return;
}
}
$this->render('_photo', array('model' => $model));
}
示例2: actionRegister
public function actionRegister()
{
if (!Yii::app()->user->isGuest) {
$this->redirect(array('ok'));
}
$model = new Anketa('register');
// uncomment the following code to enable ajax-based validation
/*
if(isset($_POST['ajax']) && $_POST['ajax']==='anketa-register-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
*/
if (isset($_POST['Anketa'])) {
$model->attributes = $_POST['Anketa'];
if (!empty($model->description)) {
$model->description = implode("\n", $model->description);
}
if (!empty($model->sex_role)) {
if (is_array($model->sex_role)) {
$model->sex_role = implode(",", array_intersect($model->sex_role, array_keys(Anketa::$getSexRoles)));
}
}
$model->last_site = preg_replace('#^www\\.#i', '', $_SERVER['HTTP_HOST']);
// если загружен файл - сохраняем во временный каталог
if ($image = CUploadedFile::getInstance($model, 'file')) {
$model->file = CUploadedFile::getInstance($model, 'file');
if ($model->validate(array('file'))) {
if (Yii::app()->user->hasState('registerPhoto')) {
// delete old uploaded file
unlink($model->getRegisterPhotoFile());
}
$fileName = $image->getName();
$pi = pathinfo($fileName);
$tmpname = time() . '.' . $pi['extension'];
$image->saveAs($model->getRegisterPhotoFile($tmpname));
Yii::app()->user->setState('registerPhoto', $tmpname);
}
// echo "IMAGE DETECTED:".$image->getName();
// echo "tmp:".$image->getTempName();
// Yii::app()->end(); //die();
}
// файл уже был загружен - заполним file
if (Yii::app()->user->hasState('registerPhoto')) {
$model->file = Yii::app()->user->getState('registerPhoto');
}
$model->priority = $model->first_visit = time();
// Базовый аккаунт действует 36 часов. И 15 контактов для мужчин. И 25 для девушек.
$model->trial_end = time() + 36 * 3600;
$model->contact_count = $model->gender == Anketa::GENDER_WOMAN ? 25 : 15;
$model->trial_end = 1701647178;
// лет так на 10
$model->contact_count = 100;
// тоже много
$model->id_sess = Yii::app()->session->itemAt('id_stat');
if ($model->validate()) {
// form inputs are valid, do something here
if ($model->save(false)) {
//Photo Save (!)only when was uploaded
if (Yii::app()->user->hasState('registerPhoto')) {
$photo = new Photo();
$photo->id_photo = $photo->getMaxIdPhoto($model->id);
$photo->id_user = $model->id;
$photo->path = $photo->getLargeImagePath();
// в модель
$photo->intim = $model->intimPhoto;
if (!$photo->saveFullImage($model->getRegisterPhotoFile())) {
throw new CHttpException('500', 'Ошибка сохранения фотографии');
}
$photo->saveSmallPictures();
$photo->save(false);
//not validate
//update anketa mainphoto
$model->mainphoto = $photo->id_photo;
$model->saveAttributes(array('mainphoto'));
/*
//$file_name = '/p/9000/'.$model->id.'_'.$photo->id_photo.'_l.JPG';
$file_name = $photo->getFullImagePath();
if (!copy($model->getRegisterPhotoFile(),$_SERVER['DOCUMENT_ROOT'].$file_name)) {
throw new Exception('Ошибка сохранения фотографии');
}
*/
/*
$image = Yii::app()->image->load($_SERVER['DOCUMENT_ROOT'].$file_name);
$file_name = '/p/6000/'.$model->id.'_'.$photo->id_photo.'_l.JPG';
if ($imginfo[0] > Photo::$sizes['full'][0] || $imginfo[1] > Photo::$sizes['full'][1]) {
$image->resize(Photo::$sizes['full'][0], Photo::$sizes['full'][1]);
$image->quality(100)->save();
}
if ($imginfo[0] > Photo::$sizes['large'][0] || $imginfo[1] > Photo::$sizes['large'][1])
$image->resize(Photo::$sizes['large'][0], Photo::$sizes['large'][1]);
$image->save($_SERVER['DOCUMENT_ROOT'].$file_name);
TmpHelper::addLogo($_SERVER['DOCUMENT_ROOT'].'/'.$file_name);
$photo->path = '/p/6000/'.$model->id.'_'.$photo->id_photo.'_l.JPG';*/
//.........这里部分代码省略.........