GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 61aacd...05f06e )
by Alexey
18:53
created

RetailCrmXml::setOffers()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.5125
cc 5
eloc 13
nc 5
nop 0
1
<?php
2
/**
3
 * @author Sergey Glagolev <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package frontend.models.xml
8
 */
9
/**
10
 * Class RetailCrmXml
11
 * @property RetailCrmDataProvider $dataProvider
12
 */
13
class RetailCrmXml extends BaseXml
14
{
15
  public $dataProvider;
16
17
  private $offerCounter = 0;
18
19
  private $debugLimit = null;
20
21
  public function buildXml()
22
  {
23
    $this->xmlWriter->setIndent(true);
24
    $this->xmlWriter->startDocument('1.0', $this->charset);
25
    $this->xmlWriter->text('<!DOCTYPE yml_catalog SYSTEM "shops.dtd">'.PHP_EOL);
26
    $this->xmlWriter->startElement('yml_catalog');
27
    $this->xmlWriter->writeAttribute('date', date("Y-m-d H:i"));
28
    $this->xmlWriter->startElement('shop');
29
30
    $this->setShop();
31
    $this->setCategories();
32
    $this->setOffers();
33
34
    $this->xmlWriter->endElement();
35
    $this->xmlWriter->endElement();
36
37
    $this->saveXml();
38
  }
39
40
  public function setCategory($attributes = array())
41
  {
42
    $this->xmlWriter->startElement('category');
43
    $this->xmlWriter->writeAttribute('id', $attributes['id']);
44
45
    if( isset($attributes['parent']) )
46
    {
47
      $this->xmlWriter->writeAttribute('parentId', $attributes['parent']);
48
    }
49
50
    $this->xmlWriter->text($attributes['name']);
51
52
    $this->xmlWriter->endElement();
53
  }
54
55
  protected function setShop()
56
  {
57
    foreach($this->dataProvider->getShop() as $key => $value)
58
    {
59
      $this->xmlWriter->writeElement($key, XmlHelper::escape($value));
60
    }
61
  }
62
63
  protected function setCategories()
64
  {
65
    $this->xmlWriter->startElement('categories');
66
67
    foreach($this->dataProvider->getCategories() as $attributes)
68
    {
69
      $this->setCategory($attributes);
70
    }
71
72
    $this->xmlWriter->endElement();
73
  }
74
75
  protected function setOffers()
76
  {
77
    $st = 0;
78
79
    $this->xmlWriter->startElement('offers');
80
    foreach($this->dataProvider->getOffers() as $offersList)
81
    {
82
      foreach($offersList as $attributes)
83
      {
84
        $this->setOffer($attributes);
85
        $this->followBuffer();
86
87
        Yii::app()->retailCrm->createDebugReport($attributes, $this->offerCounter++);
88
        Yii::app()->retailCrm->increaseExportProductCounter();
89
90
        if( !empty($this->debugLimit) )
91
        {
92
          if( $st++ == $this->debugLimit )
93
            break 2;
94
        }
95
      }
96
    }
97
    $this->xmlWriter->endElement();
98
  }
99
100
  protected function setOffer(array $offer)
101
  {
102
    $this->xmlWriter->startElement('offer');
103
    $this->xmlWriter->writeAttribute('id', $offer['id']);
104
    $this->xmlWriter->writeAttribute('productId', $offer['productId']);
105
106
    if( isset($offer['quantity']) )
107
      $this->xmlWriter->writeAttribute('quantity', $offer['quantity']);
108
109
    foreach(Arr::extract($offer, array('url', 'price', 'purchasePrice', 'categories', 'picture', 'name', 'xmlId', 'productName', 'vendor'))  as $attribute => $value)
110
    {
111
      if( empty($value) )
112
        continue;
113
114
      if( $attribute == 'categories' )
115
      {
116
        foreach($value as $categoryId)
117
        {
118
          $this->xmlWriter->writeElement('categoryId', XmlHelper::escape($categoryId));
119
        }
120
      }
121
      else
122
      {
123
        $this->xmlWriter->writeElement($attribute, $value);
124
      }
125
    }
126
127
    $this->setParameters($offer);
128
129
    $this->xmlWriter->endElement();
130
  }
131
132
  protected function setParameters(array $offer)
133
  {
134
    if( empty($offer['params']) )
135
      return;
136
137
    foreach($offer['params'] as $param)
138
    {
139
      $this->xmlWriter->startElement('param');
140
      $this->xmlWriter->writeAttribute('name', XmlHelper::escape($param['name']));
141
142
      if( !empty($param['code']) )
143
        $this->xmlWriter->writeAttribute('code', XmlHelper::escape($param['code']));
144
145
      $this->xmlWriter->text(XmlHelper::escape($param['value']));
146
147
      $this->xmlWriter->endElement();
148
    }
149
  }
150
}