当前位置: 首页>>代码示例>>PHP>>正文


PHP Apartment::saveFromXml方法代码示例

本文整理汇总了PHP中Apartment::saveFromXml方法的典型用法代码示例。如果您正苦于以下问题:PHP Apartment::saveFromXml方法的具体用法?PHP Apartment::saveFromXml怎么用?PHP Apartment::saveFromXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Apartment的用法示例。


在下文中一共展示了Apartment::saveFromXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionXmlfeed

 public function actionXmlfeed()
 {
     $report = array();
     $model = $this->loadModel(Yii::app()->user->id);
     if (isset($_REQUEST['xml_path']) and !empty($_REQUEST['xml_path'])) {
         $xml = @file_get_contents($_REQUEST['xml_path']);
         $xml = trim($xml);
         $xml_read = @simplexml_load_string($xml);
         if (false !== $xml_read and false !== $xml) {
             $xml_items = array();
             $lists = XMLFeedItem::generateLists();
             foreach ($xml_read->offer as $item) {
                 $xml_items[] = XMLFeedItem::populate($item, $lists);
             }
             $report['errors'] = array();
             $report['success'] = 0;
             $report['fail'] = 0;
             $report['total'] = count($xml_items);
             foreach ($xml_items as $item) {
                 if ($item->validate()) {
                     if (Apartment::saveFromXml($item)) {
                         $report['success']++;
                     } else {
                         $report['fail']++;
                     }
                 } else {
                     $report['errors'][$item->internal_id] = CHtml::errorSummary($item, '', '');
                     $report['fail']++;
                 }
             }
             $new_feed = new ApartmentXMLFeed();
             $new_feed->owner_id = yii::app()->user->id;
             $new_feed->report = json_encode($report);
             $new_feed->xml = $xml;
             $new_feed->save();
             if (!empty($report['errors'])) {
                 Yii::import('application.extensions.mailer.EMailer');
                 $mailer = new EMailer();
                 if (param('mailUseSMTP', 0)) {
                     $mailer->IsSMTP();
                     $mailer->SMTPAuth = true;
                     $mailer->Host = param('mailSMTPHost', 'localhost');
                     $mailer->Port = param('mailSMTPPort', 25);
                     $mailer->Username = param('mailSMTPLogin');
                     // SMTP login
                     $mailer->Password = param('mailSMTPPass');
                     // SMTP password
                     $mailer->SMTPSecure = param('mailSMTPSecure');
                 }
                 $mailer->From = param('adminEmail');
                 $mailer->FromName = param('mail_fromName', User::getAdminName());
                 $mailer->AddAddress($model->email);
                 $mailer->Subject = 'Результаты импорта объектов';
                 $mailer->Body = $this->renderPartial('_mailReport', array('report' => $report), true);
                 $mailer->CharSet = 'UTF-8';
                 $mailer->IsHTML(true);
                 if (!$mailer->Send()) {
                     throw new CHttpException(503, tt('message_not_send', 'notifier') . ' ErrorInfo: ' . $mailer->ErrorInfo);
                     //showMessage(tc('Error'), tt('message_not_send', 'notifier'));
                 }
             }
         }
     }
     $this->render('xmlfeed', ['model' => $model, 'report' => $report, 'feeds' => ApartmentXMLFeed::model()->mine()->findAll(array('limit' => 5, 'order' => 'id DESC')), 'baseURL' => Yii::app()->theme->baseUrl . '/views/modules/usercpanel']);
 }
开发者ID:barricade86,项目名称:raui,代码行数:65,代码来源:MainController.php


注:本文中的Apartment::saveFromXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。