/**
  * Returns false if the name already exists
  */
 public static function isUnique($partnerName, $id = false)
 {
     $partner = new TrainingPartner();
     $select = $partner->select();
     $select->where("partner_name = ?", $partnerName);
     if ($id) {
         $select->where("id != ?", $id);
     }
     if ($partner->fetchRow($select)) {
         return false;
     }
     return true;
 }
    public function viewAction()
    {
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        require_once 'models/table/OptionList.php';
        $sql = 'SELECT
		organizer_partners.id,
		ifnull(organizer_id,training_organizer_phrase) as organizer_id,
		p.id as organizer_id
		from organizer_partners
		right outer JOIN training_organizer_option AS p ON p.id = organizer_id
		where p.is_deleted = 0 and organizer_partners.is_deleted = 0
		order by organizer_id ASC
		';
        $partners = $db->fetchAll($sql);
        if ($partners === false) {
            $partners = array();
        }
        $this->viewAssignEscaped('partners', $partners);
        if ($id = $this->getSanParam('id')) {
            if ($this->hasACL('edit_course')) {
                //redirect to edit mode
                //$this->_redirect ( str_replace ( 'view', 'edit', 'http://' . $_SERVER ['SERVER_NAME'] . $_SERVER ['REQUEST_URI'] ) );
            }
            $partner = new TrainingPartner();
            $partnerRow = $partner->fetchRow('id = ' . $id);
            $partnerArray = $partnerRow->toArray();
            // and link to training_organizer_option
            if ($partnerArray['organizer_id']) {
                $sql = 'SELECT training_organizer_phrase from training_organizer_option where id = ' . $partnerArray['organizer_id'] . ' and is_deleted = 0';
                $partnerArray['training_organizer_phrase'] = $db->fetchOne($sql);
            }
        } else {
            $partnerArray = array();
            $partnerArray['id'] = null;
        }
        $this->viewAssignEscaped('partner', $partnerArray);
    }