<?php

class JobOffersDataAdmin extends ModelAdmin {
    
    public static $managed_models = array(   //since 2.3.2
        'JobOffersData'
    );

    static $url_segment = 'joboffersdata'; // will be linked as /admin/products
    static $menu_title = 'Job Offers Admin';
    
    public static $page_length = 10;
  
    public function getEditForm(){ 
        $report = new TableListField(
        'CorporateReport',
        'JobOffersData',
        array(
            'ID' => 'ID',
            'Title' => 'First Name',
            
        )
    );
        return $this->bindModelController('JobOffersData')->ResultsForm(array()); 
    }
    
   
    
//    public function init() {
//		parent::init();
//
//		Requirements::css(CMS_DIR . '/css/ModelAdmin.css'); // standard layout formatting for management UI
//        Requirements::customCSS(".action_goBack, .action_goForward {display:none;} "); 
//
//	}
//	
 
}


class JobOffersData extends DataObject  {
   
    public static $db = array(
        'Type'          => 'Int',
        'Xmlidn'        => 'Int',
        'URLSegment'    => 'Varchar(255)',
        'OfferLang'     => 'Varchar(3)',
        'City'          => 'Varchar(100)',
        'OfferType'     => 'Varchar(255)',
        'Title'         => 'Varchar(255)',
        'Sector'        => 'Varchar(255)',
        'Company'       => 'HTMLText',
        'Description'   => 'HTMLText',
        'AdditionalInfo'=> 'HTMLText',
        'Email'         => 'Varchar(255)',
        'ContactPerson' => 'Varchar(255)',
        'Department'    => 'Varchar(255)',
        'WorkHours'     => 'Varchar(255)',
        'ShowLT'        => 'Boolean',
        'ShowEN'        => 'Boolean',
        'ShowRU'        => 'Boolean',
        'PublishDate'   => 'Date',
        'ValidToDate'   => 'Date',
        'CreatedDate'   => 'Datetime',
        'UpdatedDate'   => 'Datetime',
        'TsCreated'     => 'Datetime',
		'TsUpdated'     => 'Datetime'
    );
    
    public static $has_one = array(
        'Logo' => 'Image'
    );
    
    public static $default_sort = 'Xmlidn ASC';
    
    public static $defaults = array(
		'ShowLT' => false,
		'ShowEN' => false,
        'ShowRU' => false
	);
    
    public static $summary_fields = array( 
        'Xmlidn',
        'Title', 
        'Sector',
        'Company',
        'OfferType',
        'City'
    );
    
	public $DiffTranslation = null;
    public function canCreate() {
        return false;
    }
    public function canEdit() {
        return false;
    }
    public function canDelete() {
        return false;
    }
    
    
//    public static $searchable_fields = array(
//      'Title',
//      'Section'
//   );
//    public function canCreate() {
//        return false;
//    }
    
    public function getCMSFields() {
		$fields = parent::getCMSFields();

//        $fields->addFieldToTab('Root.Main', new TextField('Code', _t('Country.CODE', 'Code')), 'Content');

		return $fields;
	}
    
    public function offerURL() {
    
        $offerHolder = DataObject::get_one('JobOffersHolder', "Status='Published' AND ShowInMenus='1'");
        if($offerHolder) {
            return $offerHolder->AbsoluteLink().'show/'.$this->URLSegment;
        }
        return false;
    }
	public function getDiffTranslation() {
        
        
        $originalLocale = Translatable::get_current_locale();
        if($originalLocale=='en_US') {
            $currLang = 'en';
        } elseif($originalLocale=='ru_RU') {
            $currLang = 'ru';
        } else {
            $currLang = 'lt';
        }

        $this->DiffTranslation = new DataObjectSet();
        if($this->OfferLang!=$currLang) {
            $newLocale = 'lt_LT';
            if($this->OfferLang=='en') {
                $newLocale = 'en_US';
            } elseif($this->OfferLang=='ru') {
                $newLocale = 'ru_RU';
            }
            Translatable::set_current_locale($newLocale);
            //i18n::set_locale($newLocale); 
        }
        
        $this->DiffTranslation->About = _t('LangEditor.JOB_OFFER_COMPANY_TITLE', 'About company:');
        $this->DiffTranslation->DateFrom = _t('LangEditor.JOB_TABLE_DATE_FROM', 'Published:');
        $this->DiffTranslation->DateTo = _t('LangEditor.JOB_TABLE_DATE_TO', 'Valid until:');
        $this->DiffTranslation->Department = _t('LangEditor.JOB_OFFER_DEPARTMENT', 'Department:');
        $this->DiffTranslation->WorkHours = _t('LangEditor.JOB_OFFER_WORK_HOURS', 'Work hours:');
        $this->DiffTranslation->City = _t('LangEditor.JOB_OFFER_CITY', 'City:');
        $this->DiffTranslation->ContactPerson = _t('LangEditor.JOB_OFFER_CONTACT_PERSON', 'Contact person:');

        
        if($this->OfferLang!=$currLang) {
            Translatable::set_current_locale($originalLocale);
            //i18n::set_locale($originalLocale); 
        }
        return $this->DiffTranslation;
        
    }
	public function companyTitleFix() {

        // isakaidom "Company" i dvi dalis - apie Biuro pirmas sakinys, po to apie klienta
        // by biuro programuotojai   
        $this->CompanyFix = new DataObjectSet();
             
        $temp = explode("<br />", $this->Company);   
	      $this->CompanyFix->Biuro = $temp[0];
	      unset($temp[0]);
	      
        if (is_array($temp)) 
        $this->CompanyFix->Client = implode("<br />", $temp);
        
        return $this->CompanyFix;
	} 
}

?>
