本文整理汇总了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']);
}