Habari\Vocabulary::insert PHP Метод

insert() публичный Метод

function insert Saves a new vocabulary to the vocabularies table
public insert ( )
    public function insert()
    {
        // Don't allow duplicate vocabularies
        if (Vocabulary::exists($this->fields['name'])) {
            return false;
        }
        // Let plugins disallow and act before we write to the database
        $allow = true;
        $allow = Plugins::filter('vocabulary_insert_allow', $allow, $this);
        if (!$allow) {
            return false;
        }
        Plugins::act('vocabulary_insert_before', $this);
        // Serialize features before they are stored
        if (isset($this->newfields['features'])) {
            $this->newfields['features'] = serialize($this->newfields['features']);
        }
        if (isset($this->fields['features'])) {
            $this->fields['features'] = serialize($this->fields['features']);
        }
        $result = parent::insertRecord(DB::table('vocabularies'));
        // Make sure the id is set in the vocabulary object to match the row id
        $this->newfields['id'] = DB::last_insert_id();
        // Update the vocabulary's fields with anything that changed
        $this->fields = array_merge($this->fields, $this->newfields);
        // And unserialize the features
        if (isset($this->fields['features'])) {
            $this->fields['features'] = unserialize($this->fields['features']);
        }
        // We've inserted the vocabulary, reset newfields
        $this->newfields = array();
        EventLog::log(_t('New vocabulary %1$s (%2$s)', array($this->id, $this->name)), 'info', 'content', 'habari');
        // Let plugins act after we write to the database
        Plugins::act('vocabulary_insert_after', $this);
        return $result;
    }