Esempio n. 1
0
 /**
  * Exports items of a type to a csv file
  *
  * @param Type $type The type object
  *
  * @return string File path, false if no items were found
  *
  * @since 2.0
  */
 public function toCSV($type)
 {
     $item_table = $this->app->table->item;
     $type->getApplication()->getCategoryTree();
     $data = array();
     $i = 1;
     $maxima = array();
     foreach ($item_table->getByType($type->id, $type->getApplication()->id) as $item) {
         // item properties
         $data[$i]['Id'] = $item->id;
         $data[$i]['Name'] = $item->name;
         $data[$i]['Alias'] = $item->alias;
         $data[$i]['Author Alias'] = $item->getAuthor();
         $data[$i]['Created Date'] = $item->created;
         // categories
         $data[$i]['Category'] = array();
         foreach ($item->getRelatedCategories() as $category) {
             $name = $category->name . '|||' . $category->alias;
             while (($category = $category->getParent()) && $category->id) {
                 $name = $category->name . '|||' . $category->alias . "///{$name}";
             }
             $data[$i]['Category'][] = $name;
         }
         // tags
         $data[$i]['Tag'] = $item->getTags();
         // elements
         foreach ($type->getElements() as $identifier => $element) {
             if (!isset($item->elements[$identifier])) {
                 continue;
             }
             $name = $element->config->get('name') ? $element->config->get('name') : $element->getElementType();
             switch ($element->getElementType()) {
                 case 'text':
                 case 'textarea':
                 case 'link':
                 case 'email':
                 case 'date':
                     $data[$i][$name] = array();
                     foreach ($item->elements[$identifier] as $self) {
                         $data[$i][$name][] = @$self['value'];
                     }
                     break;
                 case 'select':
                 case 'radio':
                 case 'checkbox':
                     $data[$i][$name] = isset($item->elements[$identifier]['option']) ? $item->elements[$identifier]['option'] : array();
                     break;
                 case 'country':
                     $data[$i][$name] = isset($item->elements[$identifier]['country']) ? $item->elements[$identifier]['country'] : array();
                     break;
                 case 'gallery':
                     $data[$i][$name] = @$item->elements[$identifier]['value'];
                     break;
                 case 'image':
                 case 'download':
                     $data[$i][$name] = @$item->elements[$identifier]['file'];
                     break;
                 case 'googlemaps':
                     $data[$i][$name] = @$item->elements[$identifier]['location'];
                     break;
             }
         }
         foreach ($data[$i] as $key => $value) {
             if (is_array($value)) {
                 $maxima[$key] = max(1, @$maxima[$key], count($value));
             }
         }
         $item_table->unsetObject($item->id);
         $i++;
     }
     if (empty($data)) {
         return false;
     }
     // use maxima to pad arrays
     foreach ($maxima as $key => $num) {
         foreach (array_keys($data) as $i) {
             $data[$i][$key] = array_pad($data[$i][$key], $num, '');
         }
     }
     // set header
     array_unshift($data, array());
     foreach ($data[1] as $key => $value) {
         $num = is_array($value) ? count($value) : 1;
         $data[0] = array_merge($data[0], array_fill(0, max(1, $num), $key));
     }
     $file = rtrim($this->app->system->config->get('tmp_path'), '\\/') . "/{$type->id}.csv";
     if (($handle = fopen($file, "w")) !== false) {
         foreach ($data as $row) {
             fputcsv($handle, $this->app->data->create($row)->flattenRecursive());
         }
         fclose($handle);
     } else {
         throw new AppExporterException(sprintf('Unable to write to file %s.', $file));
     }
     return $file;
 }
Esempio n. 2
0
 /**
  * Returns layouts for a type of an app.
  *
  * @param Type $type
  * @param string $layout_type
  *
  * @return array The layouts
  * @since 2.0
  */
 public function layouts($type, $layout_type = '')
 {
     $result = array();
     // get template
     if ($template = $type->getApplication()->getTemplate()) {
         // get renderer
         $renderer = $this->app->renderer->create('item')->addPath($template->getPath());
         $path = 'item';
         $prefix = 'item.';
         if ($renderer->pathExists($path . DIRECTORY_SEPARATOR . $type->id)) {
             $path .= DIRECTORY_SEPARATOR . $type->id;
             $prefix .= $type->id . '.';
         }
         foreach ($renderer->getLayouts($path) as $layout) {
             $metadata = $renderer->getLayoutMetaData($prefix . $layout);
             if (empty($layout_type) || $metadata->get('type') == $layout_type) {
                 $result[$layout] = $metadata;
             }
         }
     }
     return $result;
 }
Esempio n. 3
0
 protected static function _getElementFromXMLNode(YXMLElement $xml, Type $type)
 {
     // load element
     $element_type = (string) $xml->attributes()->type;
     $element = self::loadElement($element_type, $type->getApplication()->getPath() . '/elements');
     // bind element data or set undefined
     if ($element !== false) {
         $element->loadConfig($xml);
         return $element;
     }
     return null;
 }