<?php
/*
 * Plugin table
 *
 * auto-generated by the sfDoctrine plugin
 * creation date: 2007-05-02 13:45:58
 */
class PlugincsSettingTable extends Doctrine_Table
{
  public function findAllForList()
  {
    return $this->findAll();
  }
  
  public function findSettingsByGroup($query)
  {
    return $query->addOrderBy($query->getRootAlias().'.setting_group ASC');
  }
  public function getExistingGroupsArray()
  {
    $groups = $this->createQuery()
                   ->groupBy('setting_group')
                   ->execute();
                   
    $groupArray = array();
    
    foreach ($groups as $group) 
    {
      $groupArray[$group['setting_group']] = $group['setting_group'];
    }
    return array_filter($groupArray);
  }
  
  public function getRestoreDefaultsQuery()
  {
    return $this->createQuery('s')
                ->update()
                ->set('s.value', 's.setting_default');
  }
  
  public function restoreAllDefaults()
  {
    return $this->getRestoreDefaultsQuery()->execute();
  }
  
  public function restoreDefault($id)
  {
    $q = $this->getRestoreDefaultsQuery()->addWhere('s.id = ?', $id);
    
    return $q->execute();
  }
}
