| Conditions | 7 |
| Paths | 22 |
| Total Lines | 35 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 16 | public function actionAppendTag() |
||
| 17 | {
|
||
| 18 | try |
||
| 19 | {
|
||
| 20 | if( $data = Yii::app()->request->getPost('appendTag') )
|
||
| 21 | {
|
||
| 22 | $tagName = Yii::app()->format->trim($data['name']); |
||
| 23 | |||
| 24 | if( !$tag = BTag::model()->findByAttributes(array('name' => $tagName, 'group' => $data['group'])) )
|
||
| 25 | {
|
||
| 26 | $tag = new BTag(); |
||
| 27 | $tag->setAttributes($data); |
||
| 28 | if( !$tag->save() ) |
||
| 29 | throw new ModelValidateException($tag); |
||
| 30 | } |
||
| 31 | |||
| 32 | if( !TagItem::model()->findByAttributes(array('tag_id' => $tag->id, 'group' => $tag->group, 'item_id' => $data['itemId'])) )
|
||
| 33 | {
|
||
| 34 | $tagItem = new TagItem(); |
||
| 35 | $tagItem->setAttributes(array( |
||
| 36 | 'tag_id' => $tag->id, |
||
| 37 | 'group' => $tag->group, |
||
| 38 | 'item_id' => $data['itemId'] |
||
| 39 | )); |
||
| 40 | |||
| 41 | if( !$tagItem->save() ) |
||
| 42 | throw new ModelValidateException($tagItem); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | catch(ModelValidateException $e) |
||
| 47 | {
|
||
| 48 | throw new Http404Exception(500, $e->getMessage()); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 63 | } |