public function actionDeleteImg() { $newsId = Yii::app()->request->getParam('id'); $imageId = Yii::app()->request->getParam('imId'); if ($newsId && $imageId) { $newsModel = News::model()->findByPk($newsId); if ($newsModel->image_id != $imageId) { throw404(); } $newsModel->image_id = 0; $newsModel->update('image_id'); $imageModel = NewsImage::model()->findByPk($imageId); $imageModel->delete(); $this->redirect(array('/news/backend/main/update', 'id' => $newsId)); } throw404(); }
public function beforeSave() { if ($this->newsImage) { if ($this->image) { $this->image->delete(); } $image = new NewsImage(); $image->imageInstance = $this->newsImage; $image->save(); if ($image->id) { $this->image_id = $image->id; } } return parent::beforeSave(); }
private function xml_node2item($xml_node) { $images = array(); foreach($xml_node->getElementsByTagname('otherImages') as $image_xml) { $images[] = NewsImage::xml2news_image($image_xml); } $item = array( 'images' => $images, 'body' => getNodeValue($xml_node,'body'), 'link' => getNodeValue($xml_node,'link'), 'category' => getNodeValue($xml_node,'category'), 'story_id' => getNodeValue($xml_node,'story_id'), 'featured' => intval(getNodeValue($xml_node,'featured')) != 0, 'author' => getNodeValue($xml_node,'author'), 'title' => getNodeValue($xml_node,'title'), 'description' => getNodeValue($xml_node,'description'), 'unixtime' => strtotime(getNodeValue($xml_node,'postDate')), ); if($xml_node->getElementsByTagname('image')->length) { $main_image = NewsImage::xml2news_image($xml_node->getElementsByTagname('image')->item(0)); if($main_image->thumb_url) { $item['main_image'] = $main_image; } } return $item; }