<table id="rounded-corner">
<thead>
<tr>
- <th scope="col" class="rounded-company"><?php echo __('Name') ?></th>
+ <th scope="col" class="rounded-company"><?php echo __('Logo') ?></th>
+ <th scope="col" class="rounded"><?php echo __('Name') ?></th>
<th scope="col" class="rounded-q4"><?php echo __('CIF') ?></th>
</tr>
</thead>
<tfoot>
<tr>
- <td colspan="1" class="rounded-foot-left"><em><?php echo __('Your data company') ?></em></td>
+ <td colspan="2" class="rounded-foot-left"><em><?php echo __('Your data company') ?></em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<tr>
+ <td><img src="<?php echo "/uploads/images/".$company->getCompany()->getCompanyLogo() ?>" width="100" height="100"/></td>
<td><?php echo $company->getCompanyName() ?></td>
<td><?php echo $company->getCompany()->getCompanyCif() ?></td>
</tr>
//If there are not results.
//In production replace this line by a die command (trying to stop wasting TCP bandwidth)
throw new sfError404Exception(sprintf('
- There are not offices with GPS coordinates: longitude "%s" and
+ There are not offices or ads with GPS coordinates: longitude "%s" and
latitude "%s".', $request->getParameter('longitude'), $request->getParameter('latitude')));
//die;
}
#
Company:
+ actAs: [Timestampable]
columns:
user_id: { type: integer (4), notnull: true }
company_cif: { type: string(255), notnull: true, unique: true }
+ company_logo: { type: string(255), notnull: true }
relations:
User: { class: sfGuardUser, local: user_id, onDelete: CASCADE }
columns:
company_id: { type: integer, notnull: true }
company_categ_id: { type: integer }
+ ad_gps: { type: blob }
ad_mobile_image_link: { type: string (3000), notnull: true }
relations:
Company: { onDelete: CASCADE, local: company_id, foreign: id }
MOBILEADVERTISING:
User: MOBILEADVERTISING
company_cif: 4683838383-I
+ company_logo: mobileads.jpg
DIA:
User: DIA
company_cif: 5748934949-K
+ company_logo: dia.jpg
CARREFOUR:
User: CARREFOUR
company_cif: 0390390309-L
-
+ company_logo: carrefour.jpg
+
Office:
DIA_Mostoles:
Company: DIA
BabuchasVerdes:
Company: CARREFOUR
CompanyCategory: CompanyCategory_2
- ad_mobile_image_link: http://gumartinm.name/vickie.gif
+ ad_mobile_image_link: babuchasverdes.jpg
BabuchasVerdisimas:
Company: CARREFOUR
CompanyCategory: CompanyCategory_2
- ad_mobile_image_link: http://gumartinm.name/vickie.gif
+ ad_mobile_image_link: babuchasverdisimas.jpg
Donuts:
Company: CARREFOUR
CompanyCategory: CompanyCategory_3
- ad_mobile_image_link: http://gumartinm.name/vickie.gif
+ ad_mobile_image_link: donuts.jpg
AdDescription:
-CREATE TABLE ad (id BIGSERIAL, company_id BIGINT NOT NULL, company_categ_id BIGINT, ad_mobile_image_link VARCHAR(3000) NOT NULL, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id));
+CREATE TABLE ad (id BIGSERIAL, company_id BIGINT NOT NULL, company_categ_id BIGINT, ad_gps BYTEA, ad_mobile_image_link VARCHAR(3000) NOT NULL, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id));
CREATE TABLE ad_description (id BIGSERIAL, language_id BIGINT NOT NULL, ad_id BIGINT NOT NULL, ad_name VARCHAR(255) NOT NULL, ad_description text, ad_mobile_text VARCHAR(500) NOT NULL, ad_link VARCHAR(3000) NOT NULL, PRIMARY KEY(id));
CREATE TABLE city (id BIGSERIAL, city_name VARCHAR(64) NOT NULL, region_id BIGINT NOT NULL, PRIMARY KEY(id));
-CREATE TABLE company (id BIGSERIAL, user_id INT NOT NULL, company_cif VARCHAR(255) NOT NULL UNIQUE, PRIMARY KEY(id));
+CREATE TABLE company (id BIGSERIAL, user_id INT NOT NULL, company_cif VARCHAR(255) NOT NULL UNIQUE, company_logo VARCHAR(255) NOT NULL, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, PRIMARY KEY(id));
CREATE TABLE company_category (id BIGSERIAL, company_id BIGINT NOT NULL, general_categ_id BIGINT, created_at TIMESTAMP NOT NULL, updated_at TIMESTAMP NOT NULL, root_id BIGINT, lft INT, rgt INT, level SMALLINT, PRIMARY KEY(id));
CREATE TABLE company_category_description (id BIGSERIAL, language_id BIGINT NOT NULL, company_categ_id BIGINT NOT NULL, company_categ_name VARCHAR(255) NOT NULL, company_categ_description text, PRIMARY KEY(id));
CREATE TABLE company_description (id BIGSERIAL, company_id BIGINT NOT NULL, language_id BIGINT NOT NULL, company_name VARCHAR(255) NOT NULL, PRIMARY KEY(id));
$this->setWidgets(array(
'company_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Company'), 'add_empty' => true)),
'company_categ_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('CompanyCategory'), 'add_empty' => true)),
+ 'ad_gps' => new sfWidgetFormFilterInput(),
'ad_mobile_image_link' => new sfWidgetFormFilterInput(array('with_empty' => false)),
'created_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
'updated_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
$this->setValidators(array(
'company_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Company'), 'column' => 'id')),
'company_categ_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('CompanyCategory'), 'column' => 'id')),
+ 'ad_gps' => new sfValidatorPass(array('required' => false)),
'ad_mobile_image_link' => new sfValidatorPass(array('required' => false)),
'created_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
'updated_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
'id' => 'Number',
'company_id' => 'ForeignKey',
'company_categ_id' => 'ForeignKey',
+ 'ad_gps' => 'Text',
'ad_mobile_image_link' => 'Text',
'created_at' => 'Date',
'updated_at' => 'Date',
public function setup()
{
$this->setWidgets(array(
- 'user_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => true)),
- 'company_cif' => new sfWidgetFormFilterInput(array('with_empty' => false)),
+ 'user_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => true)),
+ 'company_cif' => new sfWidgetFormFilterInput(array('with_empty' => false)),
+ 'company_logo' => new sfWidgetFormFilterInput(array('with_empty' => false)),
+ 'created_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
+ 'updated_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
));
$this->setValidators(array(
- 'user_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('User'), 'column' => 'id')),
- 'company_cif' => new sfValidatorPass(array('required' => false)),
+ 'user_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('User'), 'column' => 'id')),
+ 'company_cif' => new sfValidatorPass(array('required' => false)),
+ 'company_logo' => new sfValidatorPass(array('required' => false)),
+ 'created_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
+ 'updated_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
));
$this->widgetSchema->setNameFormat('company_filters[%s]');
public function getFields()
{
return array(
- 'id' => 'Number',
- 'user_id' => 'ForeignKey',
- 'company_cif' => 'Text',
+ 'id' => 'Number',
+ 'user_id' => 'ForeignKey',
+ 'company_cif' => 'Text',
+ 'company_logo' => 'Text',
+ 'created_at' => 'Date',
+ 'updated_at' => 'Date',
);
}
}
'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_link' => "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)
}
}
}
+
+ /**
+ * Overriding updateDefaultsFromObject method from lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
+ *
+ * TODO: create a Doctrine_Record for PostGIS
+ */
+ protected function updateDefaultsFromObject()
+ {
+ parent::updateDefaultsFromObject();
+
+ $this->setDefault('longitude', $this->getObject()->getLongitude());
+ $this->setDefault('latitude', $this->getObject()->getLatitude());
+ }
+
+ /**
+ * Overriding doSave method from lib/vendor/symfony/lib/form/addon/sfFormObject.class.php
+ *
+ * We are updating the data base in just 1 transaction
+ * In case of unsetting longitude or latitude fields you will have to override this method.
+ * TODO: create a Doctrine_Record for PostGIS
+ */
+ protected function doSave($con = null)
+ {
+ parent::doSave($con);
+
+ //Get latitude and longitude values. They will be translated to GEOGRAPHIC data.
+ foreach ($this->values as $field => $value)
+ {
+ if ($field == 'longitude')
+ $longitude = $value;
+ if ($field == 'latitude')
+ $latitude = $value;
+ }
+ //Catch id element. We will use this id to insert the PostGIS value in the right row.
+ $arrowId = $this->getObject()->getId();
+ //Update PostGIS
+ //This connection will throw exception in case of error.
+ Doctrine_Manager::connection()->execute("UPDATE ad SET ad_gps=ST_GeographyFromText('SRID=4326;POINT($longitude $latitude)') WHERE id=$arrowId");
+ }
}
$this->useFields(array('company_cif'));
+ $this->widgetSchema['company_logo'] =
+ new sfWidgetFormInputFileEditable(array('file_src' => '/uploads/images/'.$this->getObject()->company_logo,
+ 'edit_mode' => !$this->isNew(),
+ 'is_image' => true,
+ 'with_delete' => false));
+
+
+ $this->validatorSchema['company_logo'] = new sfValidatorFileImage(array('mime_types' => 'web_images',
+ 'path' => sfConfig::get('app_default_picture_directory'),
+ 'required' => $this->isNew(),
+ 'is_only_image' => true,
+ 'max_height' => 150,
+ 'min_height' => 128,
+ 'max_width' => 150,
+ 'min_width' => 128,
+ 'mime_types' => array('image/jpeg','image/pjpeg','image/png','image/x-png','image/gif','application/x-shockwave-flash')));
+
+
+
$this->widgetSchema->setLabels(array('company_cif' => 'CIF: '));
+ $this->widgetSchema->setLabels(array('company_logo' => "Your company logo: "));
//Company create new description form
'id' => new sfWidgetFormInputHidden(),
'company_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Company'), 'add_empty' => false)),
'company_categ_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('CompanyCategory'), 'add_empty' => true)),
+ 'ad_gps' => new sfWidgetFormTextarea(),
'ad_mobile_image_link' => new sfWidgetFormTextarea(),
'created_at' => new sfWidgetFormDateTime(),
'updated_at' => new sfWidgetFormDateTime(),
'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
'company_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Company'))),
'company_categ_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('CompanyCategory'), 'required' => false)),
+ 'ad_gps' => new sfValidatorString(array('required' => false)),
'ad_mobile_image_link' => new sfValidatorString(array('max_length' => 3000)),
'created_at' => new sfValidatorDateTime(),
'updated_at' => new sfValidatorDateTime(),
public function setup()
{
$this->setWidgets(array(
- 'id' => new sfWidgetFormInputHidden(),
- 'user_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => false)),
- 'company_cif' => new sfWidgetFormInputText(),
+ 'id' => new sfWidgetFormInputHidden(),
+ 'user_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => false)),
+ 'company_cif' => new sfWidgetFormInputText(),
+ 'company_logo' => new sfWidgetFormInputText(),
+ 'created_at' => new sfWidgetFormDateTime(),
+ 'updated_at' => new sfWidgetFormDateTime(),
));
$this->setValidators(array(
- 'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
- 'user_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('User'))),
- 'company_cif' => new sfValidatorString(array('max_length' => 255)),
+ 'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
+ 'user_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('User'))),
+ 'company_cif' => new sfValidatorString(array('max_length' => 255)),
+ 'company_logo' => new sfValidatorString(array('max_length' => 255)),
+ 'created_at' => new sfValidatorDateTime(),
+ 'updated_at' => new sfValidatorDateTime(),
));
$this->validatorSchema->setPostValidator(
//Finally, if nothing was found, return nice error message.
return (string) "Ad without default language";
}
+
+ public function getGpsST_AsText()
+ {
+ $aux=$this->getAdGps();
+ if ($aux)
+ {
+ //Using a PostGIS query to convert a GIS value? This is a bit strange
+ $results=Doctrine_Manager::getInstance()->getCurrentConnection()->fetchColumn("SELECT ST_AsText('$aux')");
+ return trim($results['0'], "POINT()");
+ }
+ else
+ return 0;
+ }
+
+ public function getLongitude()
+ {
+ $gpsST_AsText=$this->getGpsST_AsText();
+
+ $longitude = strstr($gpsST_AsText, ' ', true);
+
+ return $longitude;
+ }
+
+ public function getLatitude()
+ {
+ $gpsST_AsText=$this->getGpsST_AsText();
+
+ $latitude = strstr($gpsST_AsText, ' ');
+
+ return $latitude;
+ }
}
try{
$adIds = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchColumn(
- "SELECT ad_id from office INNER JOIN office_ads ON (office_ads.office_id=office.id)
+ "SELECT ad_id FROM office INNER JOIN office_ads ON (office_ads.office_id=office.id)
WHERE ST_DWithin(office_gps, ST_GeographyFromText('SRID=4326;POINT($longitude $latitude)'), $radius)"
);
}
//In case of error return as soon as posible.
return null;
}
- if (empty($adIds))
+ try{
+ $directAdIds = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchColumn(
+ "SELECT id FROM ad WHERE ST_DWithin(ad_gps, ST_GeographyFromText('SRID=4326;POINT($longitude $latitude)'), $radius)"
+ );
+ }
+ catch (Exception $e)
+ {
+ //In case of error return as soon as posible.
+ return null;
+ }
+ if (empty($adIds) && empty($directAdIds))
{ //There are not offices with those GPS coordinates.
//In many situations we will get this result, so a fast response.
return null;
}
-
- $uniqAdIds = array_unique($adIds, SORT_NUMERIC);
+ $arrayMerge = array_merge($adIds, $directAdIds);
+ $uniqAdIds = array_unique($arrayMerge, SORT_NUMERIC);
//We can not waste time doing this query. What is the best way to achieve this goal?
//Is a direct query the best way? With big tables I think this is not going to work.
*
* @property integer $company_id
* @property integer $company_categ_id
+ * @property blob $ad_gps
* @property string $ad_mobile_image_link
* @property Company $Company
* @property CompanyCategory $CompanyCategory
*
* @method integer getCompanyId() Returns the current record's "company_id" value
* @method integer getCompanyCategId() Returns the current record's "company_categ_id" value
+ * @method blob getAdGps() Returns the current record's "ad_gps" value
* @method string getAdMobileImageLink() Returns the current record's "ad_mobile_image_link" value
* @method Company getCompany() Returns the current record's "Company" value
* @method CompanyCategory getCompanyCategory() Returns the current record's "CompanyCategory" value
* @method Doctrine_Collection getOfficeAds() Returns the current record's "OfficeAds" collection
* @method Ad setCompanyId() Sets the current record's "company_id" value
* @method Ad setCompanyCategId() Sets the current record's "company_categ_id" value
+ * @method Ad setAdGps() Sets the current record's "ad_gps" value
* @method Ad setAdMobileImageLink() Sets the current record's "ad_mobile_image_link" value
* @method Ad setCompany() Sets the current record's "Company" value
* @method Ad setCompanyCategory() Sets the current record's "CompanyCategory" value
$this->hasColumn('company_categ_id', 'integer', null, array(
'type' => 'integer',
));
+ $this->hasColumn('ad_gps', 'blob', null, array(
+ 'type' => 'blob',
+ ));
$this->hasColumn('ad_mobile_image_link', 'string', 3000, array(
'type' => 'string',
'notnull' => true,
*
* @property integer $user_id
* @property string $company_cif
+ * @property string $company_logo
* @property sfGuardUser $User
* @property Doctrine_Collection $CompanyDescription
* @property Doctrine_Collection $Office
*
* @method integer getUserId() Returns the current record's "user_id" value
* @method string getCompanyCif() Returns the current record's "company_cif" value
+ * @method string getCompanyLogo() Returns the current record's "company_logo" value
* @method sfGuardUser getUser() Returns the current record's "User" value
* @method Doctrine_Collection getCompanyDescription() Returns the current record's "CompanyDescription" collection
* @method Doctrine_Collection getOffice() Returns the current record's "Office" collection
* @method Doctrine_Collection getAd() Returns the current record's "Ad" collection
* @method Company setUserId() Sets the current record's "user_id" value
* @method Company setCompanyCif() Sets the current record's "company_cif" value
+ * @method Company setCompanyLogo() Sets the current record's "company_logo" value
* @method Company setUser() Sets the current record's "User" value
* @method Company setCompanyDescription() Sets the current record's "CompanyDescription" collection
* @method Company setOffice() Sets the current record's "Office" collection
'unique' => true,
'length' => 255,
));
+ $this->hasColumn('company_logo', 'string', 255, array(
+ 'type' => 'string',
+ 'notnull' => true,
+ 'length' => 255,
+ ));
}
public function setUp()
$this->hasMany('Ad', array(
'local' => 'id',
'foreign' => 'company_id'));
+
+ $timestampable0 = new Doctrine_Template_Timestampable(array(
+ ));
+ $this->actAs($timestampable0);
}
}
\ No newline at end of file