public function actionSetdefault($listing, $photo) { $model = ProListingPhotos::model()->findByPk($photo); if ($model) { ProListingPhotos::model()->updateAll(array('default' => 0), "listing_id={$listing}"); $model->default = 1; $model->save(); } }
public function getDefaultImageUrl($width = null, $height = null) { $noImageUrl = null; $model = ProListingPhotos::model()->findByAttributes(array('listing_id' => $this->id, 'default' => 1)); if ($model) { return $model->getImageUrl($width, $height, true); } return $noImageUrl; }
/** * @Author: ANH DUNG Jan 19, 2015 * @Todo: handle sort photo * @Param: $model is model Listing */ public static function HandleSortPhoto($model) { $order = 1; $sql = ''; $tableName = ProListingPhotos::model()->tableName(); foreach ($_POST['photo_display_order'] as $key => $pk) { $sql .= "UPDATE {$tableName} SET `display_order`={$order} WHERE `id` = {$pk} AND `listing_id`={$model->id} ;"; $order++; } //UPDATE mytable SET (id, column_a, column_b) FROM VALUES ( (1, 12, 6), (2, 1, 45), (3, 56, 3), … ); Yii::app()->db->createCommand($sql)->execute(); }