/** * Ajax photoreloader * @param integer $id */ public function actionReloadphoto($id) { try { $temp_dir = sys_get_temp_dir(); $model = $this->loadModel($id); //$model = new Person; //$model->scenario = "PHOTO"; $edbeo_file = WebServices::getPersonPhotoByCodeU($model->codeU); if (!empty($edbeo_file)) { $oldPhoto = $model->PhotoName; $tfio = Transliteration::translit2010($model->FirstName) . "_" . Transliteration::translit2010($model->LastName) . "_" . Transliteration::translit2010($model->MiddleName); $model->PhotoName = "person_{$id}" . "_{$tfio}.jpg"; $path = Yii::app()->basePath . "/.." . Yii::app()->params['photosPath']; $bigpath = Yii::app()->basePath . "/.." . Yii::app()->params['photosBigPath']; $img = EWideImage::loadFromString(base64_decode($edbeo_file)); if ($img->getWidth() < $img->getHeight()) { $img->resize(120, null)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg"); $img->resize(180, null)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } else { $img->resize(null, 150)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg"); $img->resize(null, 225)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } if ($model->save()) { //PC::debug($model->PhotoName); } else { //PC::debug(print_r($model->getErrors())); } echo CJSON::encode(array("result" => "SUCCESS", "data" => Yii::app()->request->baseUrl . Yii::app()->params['photosPath'] . $model->PhotoName)); } else { echo CJSON::encode(array("result" => "ERROR", "data" => "Фото відсутнє!")); } } catch (Exception $e) { if (defined('YII_DEBUG')) { Yii::log($e->getMessage(), CLogger::LEVEL_INFO, 'actionReloadphoto'); } echo CJSON::encode(array("result" => "ERROR", "data" => $e->getMessage())); } }
public function actionReloadphoto($id) { $model = $this->loadModel($id); WebServices::getPersonPhotoByCodeU($model->codeU); $this->renderPartial('_photo', array('model' => $model)); }
<?php $url = Yii::app()->createUrl("photoloader/reloadphoto", array('id' => $model->idPerson)); $this->widget('bootstrap.widgets.TbButton', array('label' => '', 'type' => 'primary', 'size' => null, 'icon' => 'arrow-left', 'loadingText' => '...', 'htmlOptions' => array('id' => 'addSpec', 'onclick' => "PSN.reloadPersonPhote(this,'{$url}');", 'title' => "Замінити існуюче фотографію"))); ?> <?php $url = Yii::app()->createUrl("person/reloadphoto", array('id' => $model->idPerson)); $this->widget('bootstrap.widgets.TbButton', array('label' => '', 'icon' => 'refresh', 'type' => 'primary', 'size' => null, 'loadingText' => '...', 'htmlOptions' => array('id' => 'addSpec', 'onclick' => "PSN.updatePersonPhote(this,'{$url}');", 'title' => "Оновити", 'style' => "margin-top: 10px;"))); ?> </div> <div class="span5" > <b>У ЄДБО</b> <a href="#" style="width: 120px;" class="thumbnail" rel="tooltip" data-title="Фото абітурієнта"> <?php $photo_exist = Yii::app()->cache->get($model->codeU); if (!empty($model->codeU) && !empty($photo_exist)) { $photo = WebServices::getPersonPhotoByCodeU($model->codeU); if (!empty($photo)) { echo '<img src="data:image/gif;base64,' . $photo . '" />'; } else { $path = Yii::app()->baseUrl . Yii::app()->params['photosPath'] . Yii::app()->params['defaultPersonPhotoSmall']; echo CHtml::image($path, 'Фото абітурієнта'); } } else { $path = Yii::app()->baseUrl . Yii::app()->params['photosPath'] . Yii::app()->params['defaultPersonPhotoSmall']; echo CHtml::image($path, 'Фото абітурієнта'); } ?> </a> </div> <?php if (Yii::app()->user->hasFlash("photomessage")) {