Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
data_source_csv.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/../include/asset.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/data_source/data_source/data_source.inc';
20 
21 
34 {
35 
36 
43  function __construct($assetid=0)
44  {
45  parent::__construct($assetid);
46 
47  }//end constructor
48 
49 
57  public function _getAllowedLinks()
58  {
59  // any link is allowed
60  $allowed_link['asset']['card'] = 'M';
61  $allowed_link['asset']['exclusive'] = FALSE;
62 
63  $links[SQ_LINK_TYPE_1] = $allowed_link;
64  $links[SQ_LINK_TYPE_2] = $allowed_link;
65  $links[SQ_LINK_TYPE_3] = $allowed_link;
66  $links[SQ_LINK_NOTICE] = $allowed_link;
67 
68  return $links;
69 
70  }//end _getAllowedLinks()
71 
72 
79  function getResultSet()
80  {
81  $GLOBALS['SQ_SYSTEM']->pm->startTimer($this);
82  $result = Array();
83  $result = parent::getResultSet($this->name);
84  if (empty($result)) {
85  if (empty($result)) $result = $this->getItems();
86  if (!empty($result)) {
87  parent::setResultSet($result, $this->name);
88  }
89  }
90  $GLOBALS['SQ_SYSTEM']->pm->stopTimer($this);
91  return $result;
92 
93  }//end getResultSet()
94 
95 
102  function getItems()
103  {
104  // lets get the content
105  $content = $this->attr('cached_content');
106  $use_header_row = $this->attr('header_row');
107 
108  if (empty($content)) return Array();
109 
110  // Initialise to handle blank content
111  $fields = Array();
112  $new_content = Array();
113 
114  // Use header row?
115  if ($use_header_row) {
116  foreach ($content[0] as $header) {
117  $fields[] = strtolower(str_replace(' ', '_', trim($header)));
118  }
119 
120  } else {
121  for ($c = 0; $c < count($content[0]) ; $c++) {
122  $fields[$c] = 'field_'.$c;
123  }
124  }
125 
126  $rc = 0;
127  foreach ($content as $record) {
128 
129  if ($rc == 0 && $use_header_row) {
130  $rc++;
131  continue;
132  }
133 
134  for ($f = 0; $f < count($fields); $f++) {
135  $record_id = ($use_header_row ? $rc - 1 : $rc);
136  $new_content[$record_id][trim($fields[$f])] = trim($record[$f]);
137  }
138 
139  $rc++;
140 
141  }//end foreach
142 
143  return $new_content;
144 
145  }//end getItems()
146 
147 
148 }//end class
149 
150 ?>