Esempio n. 1
0
 /**
  * Turns the object into an array, and do some more processing depending on the object.
  *
  * @param \xPDOObject $object
  * @pram array $options
  * @return array
  */
 protected function objectToArray(\xPDOObject $object, array $options = array())
 {
     $data = $object->toArray('', true, true);
     switch (true) {
         // Handle TVs for resources automatically
         case $object instanceof \modResource:
             /** @var \modResource $object */
             $tvs = array();
             $templateVars = $object->getTemplateVars();
             foreach ($templateVars as $tv) {
                 /** @var \modTemplateVar $tv */
                 $name = $tv->get('name');
                 if (isset($options['exclude_tvs']) && is_array($options['exclude_tvs'])) {
                     if (!in_array($name, $options['exclude_tvs'])) {
                         $tvs[$tv->get('name')] = $tv->get('value');
                     }
                 } else {
                     $tvs[$tv->get('name')] = $tv->get('value');
                 }
             }
             ksort($tvs);
             $data['tvs'] = $tvs;
             break;
             // Handle string-based categories automagically on elements
         // Handle string-based categories automagically on elements
         case $object instanceof \modElement && !$object instanceof \modCategory:
             if (isset($data['category']) && !empty($data['category']) && is_numeric($data['category'])) {
                 $data['category'] = $this->getCategoryName($data['category']);
             }
             break;
     }
     return $data;
 }