ArticleTypeField::delete PHP Method

delete() public method

Deletes the current article type field.
public delete ( )
    public function delete()
    {
        global $g_ado_db;
        if (!$this->exists()) {
            return false;
        }
        $oldFieldName = $this->m_data['field_name'];
        $typeName = $this->m_data['type_name'];
        $typeType = $this->getType();
        $orders = $this->getOrders();
        $translation = new Translation(null, $this->getPhraseId());
        $translation->deletePhrase();
        $success = false;
        if ($this->getPrintName() != 'NULL') {
            $queryStr = "ALTER TABLE `X" . $this->m_data['type_name'] . "` DROP COLUMN `" . $this->getName() . "`";
            $success = $g_ado_db->Execute($queryStr);
        }
        if ($success || $this->getPrintName() == 'NULL') {
            $myType = $this->getType();
            if ($myType == self::TYPE_TOPIC) {
                $queryStr = "DELETE FROM TopicFields WHERE ArticleType = " . $g_ado_db->escape($this->m_data['type_name']) . " and FieldName = " . $g_ado_db->escape($this->m_data['field_name']);
                $g_ado_db->Execute($queryStr);
                $this->m_rootTopicId = null;
            }
            $fieldName = $this->m_data['field_name'];
            $success = parent::delete();
        }
        if ($success) {
            if ($typeType == self::TYPE_COMPLEX_DATE) {
                $em = Zend_Registry::get('container')->getService('em');
                $repo = $em->getRepository('Newscoop\\Entity\\ArticleDatetime');
                $repo->deleteField($typeName, array('old' => $oldFieldName));
            }
        }
        // reorder
        if ($success) {
            $newOrders = array();
            foreach ($orders as $k => $v) {
                if (array_key_exists('field_name', $this->m_data)) {
                    if ($v != $this->m_data['field_name']) {
                        $newOrders[] = $v;
                    }
                }
            }
            $newOrders = array_reverse($newOrders);
            $this->setOrders($newOrders);
            CampCache::singleton()->clear('user');
        }
        return $success;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Delete the article type. This will delete the entire table
  * in the database. Not recommended unless there is no article
  * data in the table.
  */
 public function delete()
 {
     global $g_ado_db;
     $translation = new Translation(null, $this->m_metadata->getPhraseId());
     $translation->deletePhrase();
     foreach ($this->m_dbColumns as $field) {
         $field->delete();
     }
     $this->m_metadata->delete();
     $queryStr = "DROP TABLE `" . $this->m_dbTableName . "`";
     $success = $g_ado_db->Execute($queryStr);
     CampCache::singleton()->clear('user');
 }
All Usage Examples Of ArticleTypeField::delete