Ejemplo n.º 1
0
 public function configure()
 {
     $this->useFields(array('company_categ_id', 'ad_mobile_image'));
     //Narrow down the valid options for some field validators
     $companyCategs = CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuerySkipMain($this->getOption('company_user_id'));
     //The default value is not good enough for us. We need narrow down the results.
     $this->widgetSchema['company_categ_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getModelName(), 'add_empty' => true, 'query' => $companyCategs));
     $this->validatorSchema['company_categ_id'] = new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'required' => false, 'query' => $companyCategs));
     $this->widgetSchema['ad_mobile_image'] = new sfWidgetFormInputFileEditable(array('file_src' => '/uploads/images/' . $this->getObject()->ad_mobile_image, 'edit_mode' => !$this->isNew(), 'is_image' => true, 'with_delete' => false));
     $this->validatorSchema['ad_mobile_image'] = new sfValidatorFileImage(array('mime_types' => 'web_images', 'path' => sfConfig::get('app_default_picture_directory'), 'required' => $this->isNew(), 'is_only_image' => true, 'max_height' => 156, 'min_height' => 128, 'max_width' => 156, 'min_width' => 128, 'mime_types' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', 'application/x-shockwave-flash')));
     $this->widgetSchema['longitude'] = new sfWidgetFormInputFloat();
     $this->widgetSchema['latitude'] = new sfWidgetFormInputFloat();
     $this->validatorSchema['longitude'] = new sfValidatorNumber(array('max' => 180, 'min' => -180, 'required' => false, 'trim' => true), array('invalid' => 'Wrong Longitude', 'max' => 'Longitude "%value%" must not exceed the %max% value', 'min' => 'Longitude "%value%" must be equal or higher than %min%'));
     $this->validatorSchema['latitude'] = new sfValidatorNumber(array('max' => 90, 'min' => -90, 'required' => false, 'trim' => true), array('invalid' => 'Wrong Latitude', 'max' => 'Latitude "%value%" must not exceed the %max% value', 'min' => 'Latitude "%value%" must be equal or higher than %min%'));
     $this->widgetSchema->setLabels(array('company_categ_id' => 'Company Category'));
     $this->widgetSchema->setLabels(array('ad_mobile_image' => "Picture on the user's mobile"));
     $this->widgetSchema->setLabels(array('longitude' => 'Longitude (180 to -180): '));
     $this->widgetSchema->setLabels(array('latitude' => 'Latitude (90 to -90): '));
     //i18n (Internationalization)
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('ad_form');
     if (!$this->isTheLanguageInformationComplete()) {
         // Ad creation form
         $adDescription = new AdDescription();
         $adDescription->Ad = $this->getObject();
         $newAdDescriptionForm = new AdDescriptionForm($adDescription);
         $this->embedForm('new', $newAdDescriptionForm);
     }
     $this->embedRelation('AdDescription');
 }
 /**
  * Overriding doSave method from lib/vendor/symfony/lib/form/addon/sfFormObject.class.php
  *
  * We need to save new objects in a Nested Tree where the object must have always a parent node
  * We retrieve the parent node id and insert the new object as a child of that node.
  *
  * @param mixed $con An optional connection object
  */
 protected function doSave($con = null)
 {
     //In this way we are writing on the database twice. Right now and the second one inserting the node as a child of its parent.
     parent::doSave($con);
     $companyCateg = CompanyCategoryTable::getInstance()->findOneById($this->values['parent_category']);
     //Second one, right here
     //First of all, we have to check if this node already has a parent
     if ($this->getObject()->getNode()->getParent() != null) {
         //We have to move the node
         $this->getObject()->getNode()->moveAsFirstChildOf($companyCateg);
     } else {
         //We have to insert the node
         $this->getObject()->getNode()->insertAsFirstChildOf($companyCateg);
     }
 }
Ejemplo n.º 3
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($company_category = Doctrine_Core::getTable('CompanyCategory')->find(array($request->getParameter('id'))), sprintf('Object company_category does not exist (%s).', $request->getParameter('id')));
     //Get user Id
     $userId = $this->getUser()->getGuardUser()->getId();
     //Get company owned by that user
     $companyUserId = CompanyTable::getInstance()->findOneByUserId($userId)->getId();
     //Get id number sent by the user (never trust the users)
     $companyCategoryId = $request->getParameter('id');
     $companyId = CompanyCategoryTable::getInstance()->findOneById($companyCategoryId)->getCompanyId();
     $this->forward404Unless($companyId == $companyUserId, sprintf('Category does not exist (%s).', $request->getParameter('id')));
     //Delete node and its descendants
     $company_category->getNode()->delete();
     $this->redirect('category/index');
 }