Esempio n. 1
0
 /**
  * Save element structure to datasource
  *
  * @param   \Grid\Banner\Model\Banner\Structure\ProxyAbstract $structure
  * @return  int Number of affected rows
  */
 public function save(&$structure)
 {
     if ($structure instanceof Structure) {
         $data = $structure->toArray();
     } else {
         $data = (array) $structure;
     }
     if (isset($data['tagBanners'])) {
         $tagBanners = (array) $data['tagBanners'];
         unset($data['tagBanners']);
     }
     if (isset($data['localeBanners'])) {
         $localeBanners = (array) $data['localeBanners'];
         unset($data['localeBanners']);
     }
     if (isset($data['globalBanners'])) {
         $globalBanners = (array) $data['globalBanners'];
         unset($data['globalBanners']);
     }
     $result = parent::save($data);
     if ($result > 0) {
         if (empty($structure->id)) {
             $structure->setOption('id', $id = $data['id']);
         } else {
             $id = $structure->id;
         }
         if (isset($tagBanners)) {
             $result += $this->saveTagBanners($id, $tagBanners);
         }
         if (isset($localeBanners)) {
             $result += $this->saveLocaleBanners($id, $localeBanners);
         }
         if (isset($globalBanners)) {
             $result += $this->saveGlobalBanners($id, $globalBanners);
         }
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Save element structure to datasource
  *
  * @param   \Grid\Banner\Model\Banner\Structure\ProxyAbstract $structure
  * @return  int Number of affected rows
  */
 public function save(&$structure)
 {
     if (!$structure instanceof Structure\ProxyAbstract || empty($structure->type)) {
         return 0;
     }
     $data = ArrayUtils::iteratorToArray($structure->getBaseIterator());
     $result = parent::save($data);
     if ($result > 0) {
         if (empty($structure->id)) {
             $structure->setOption('id', $id = $data['id']);
         } else {
             $id = $structure->id;
         }
         foreach ($structure->getPropertiesIterator() as $property => $value) {
             $result += $this->saveProperty($id, $property, $value);
         }
     }
     return $result;
 }