Exemplo n.º 1
0
 public function onCCK_Storage_LocationStore($type, $data, &$config = array(), $pk = 0)
 {
     if (self::$type != $type) {
         return;
     }
     if ($data['_']->table == '#__cck_core') {
         // ...
     } else {
         if (!self::$pk) {
             // Init
             $table = self::_getTable($pk, $data['_']->table, $config);
             $isNew = $pk > 0 ? false : true;
             self::_initTable($table, $data, $config);
             // Check Error
             if (self::$error === true) {
                 return false;
             }
             if ($config['join'] && $config['pk'] > 0) {
                 if (!$data[$config['join']]) {
                     $data[$config['join']] = $config['pk'];
                 }
             }
             // Prepare
             if (is_array($data)) {
                 $table->bind($data);
             }
             $table->check();
             self::_completeTable($table, $data, $config);
             // Store
             if ($isNew === true && parent::g_isMax(JFactory::getUser()->get('id'), 0, $config)) {
                 return;
             }
             if (!$table->store()) {
                 JFactory::getApplication()->enqueueMessage($table->getError(), 'error');
                 if ($isNew) {
                     parent::g_onCCK_Storage_LocationRollback($config['id']);
                 }
                 return false;
             }
             self::$pk = $table->{self::$key};
             if (!$config['pk']) {
                 $config['pk'] = self::$pk;
             }
             if ($config['join']) {
                 self::_core($data, $config);
             } else {
                 if (!isset($config['primary']) && self::$pk) {
                     self::_core($data, $config);
                 }
             }
         }
     }
     return self::$pk;
 }
Exemplo n.º 2
0
 protected function _core($data, &$config = array(), $pk = 0)
 {
     if (!$config['id']) {
         $isNew = true;
         $config['id'] = parent::g_onCCK_Storage_LocationPrepareStore();
     } else {
         $isNew = false;
     }
     // Init
     $table = self::_getTable($pk);
     $isNew = $pk > 0 ? false : true;
     if (isset($table->tags)) {
         $tags = $table->tags;
         unset($table->tags);
     } else {
         $tags = null;
     }
     if (isset($data['tags'])) {
         if (!empty($data['tags']) && $data['tags'][0] != '') {
             $table->newTags = $data['tags'];
         }
         unset($data['tags']);
     }
     self::_initTable($table, $data, $config);
     // Check Error
     if (self::$error === true) {
         return false;
     }
     // Prepare
     if (is_array($data)) {
         $table->bind($data);
     }
     if ($isNew && !isset($data['rules'])) {
         $data['rules'] = array('core.create' => array(), 'core.delete' => array(), 'core.edit' => array(), 'core.edit.state' => array(), 'core.edit.own' => array());
     }
     if (isset($data['rules']) && $data['rules']) {
         if (!is_array($data['rules'])) {
             $data['rules'] = json_decode($data['rules']);
         }
         $rules = new JAccessRules(JCckDevHelper::getRules($data['rules']));
         $table->setRules($rules);
     }
     $table->check();
     self::_completeTable($table, $data, $config);
     // Store
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     $dispatcher->trigger('onContentBeforeSave', array(self::$context, &$table, $isNew));
     if ($isNew === true && parent::g_isMax($table->{self::$author}, $table->{self::$parent}, $config)) {
         return;
     }
     if (!$table->store()) {
         JFactory::getApplication()->enqueueMessage($table->getError(), 'error');
         if ($isNew) {
             parent::g_onCCK_Storage_LocationRollback($config['id']);
         }
         return false;
     }
     // Checkin
     parent::g_checkIn($table);
     self::$pk = $table->{self::$key};
     if (!$config['pk']) {
         $config['pk'] = self::$pk;
     }
     $config['author'] = $table->{self::$author};
     $config['parent'] = $table->{self::$parent};
     parent::g_onCCK_Storage_LocationStore($data, self::$table, self::$pk, $config);
     $dispatcher->trigger('onContentAfterSave', array(self::$context, &$table, $isNew));
     // Associations
     // todo
 }