_addTitle(); $this->_addDescription(); $this->_addPhoto(); $this->_addContactFields(); $this->_addPrice(); return $this; } protected function _initWantedElements() { $this->_addDescription(); $this->_addContactFields(); return parent::_initElements(); } protected function _initHelpWantedElements() { $this->_addTitle(); $this->_addDescription(); $this->_addContactFields(); return parent::_initElements(); } protected function _initOtherElements() { $this->_addDescription(); return parent::_initElements(); } protected function _addDescription() { $this->addElement( 'htmlEditor', 'description', ['required' => true, 'label' => 'Description', 'toolbar' => 'Basic'] ); return $this; } protected function _addPhoto() { $photoConfig = $this->getConfig('photo'); $resize = $photoConfig->width . 'x' . $photoConfig->height . Qs_ImageFs::getResizeMethodAlias( $photoConfig->resizeMethod ); $this->addElement( 'extendedImage', 'photo', [ 'label' => 'Photo', 'resize' => $resize, ] ); return $this; } protected function _addContactFields() { $this->addElement('text', 'companyName', ['required' => true, 'label' => 'Company Name']); $this->addElement('text', 'location', ['required' => true, 'label' => 'Location']); $this->addElement('text', 'contactName', ['required' => true, 'label' => 'Contact Name']); $this->addElement( 'htmlEditor', 'contactDetails', ['required' => true, 'label' => 'Contact Details', 'toolbar' => 'Basic'] ); return $this; } protected function _addTitle() { $this->addElement( 'text', 'title', ['required' => true, 'label' => 'Title'] ); return $this; } protected function _addPrice() { $this->addElement( 'text', 'price', [ 'required' => true, 'label' => 'Price', ] ); return $this; } protected function _addVisibilityDateRange() { $this->addElement('date', 'startDate', [ 'label' => 'Start Date', 'description' => 'Listing will show up on specified date at 12:00 PM. Leave empty to use current date.', ]); $this->addElement('date', 'expirationDate', [ 'label' => 'Expiration Date', 'description' => 'Listing will be visible till the end of specified date (up to 11:59 PM). ' . 'Leave empty to use Expiration Date as Start Date + ' . App_Settings_Obj::get('classifiedDays') . ' days', ]); $days = (int) App_Settings_Obj::get('classifiedDays'); $this->getElement('expirationDate')->addValidator('Callback', true, [ 'callback' => [$this, 'isValidExpirationDate'], 'messages' => "Expiration Date can't be longer than $days days after Start Date", ]); } public function isValidExpirationDate($value, $context) { if (empty($value)) { return true; } $startDate = Qs_Array::get($context, 'startDate', date('Y-m-d')); $maxDate = (new Obj())->calculateExpirationDate($startDate); return $value <= $maxDate; } }