Пример #1
0
 /**
  * edit template
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   array       $templateInfo       template information
  * @return  array                           edit result information
  */
 public static function editTemplate($templateInfo)
 {
     $resultInfo = array();
     $updateFlag = false;
     $title = trim($templateInfo['title']);
     $userTemplate = UserTemplate::model()->findByAttributes(array('type' => $templateInfo['type'], 'product_id' => $templateInfo['product_id'], 'created_by' => Yii::app()->user->id, 'title' => $title));
     if (false != $userTemplate) {
         $updateFlag = true;
         $userTemplate->updated_at = date(CommonService::DATE_FORMAT);
     } else {
         $userTemplate = new UserTemplate();
         $userTemplate->created_by = Yii::app()->user->id;
         $userTemplate->created_at = date(CommonService::DATE_FORMAT);
         $userTemplate->updated_at = $userTemplate->created_at;
         $userTemplate->product_id = $templateInfo['product_id'];
         $userTemplate->type = $templateInfo['type'];
         $userTemplate->title = $title;
     }
     $userTemplate->template_content = serialize($templateInfo['template_content']);
     if ($userTemplate->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         if ($updateFlag) {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_UPDATE_SUCCESS));
         } else {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_CREATE_SUCCESS));
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $userTemplate->getErrors();
     }
     return $resultInfo;
 }