private function loadPreferences()
 {
     $this->setPreference('box_user', null);
     $this->setPreference('box_snippets', null);
     $this->setPreference('box_language_cloud', null);
     $this->setPreference('box_tag_cloud', null);
     $this->setPreference('search_size', null);
     $this->setPreference('box_snippets_size', null);
     $this->setPreference('box_order', null);
     $c = new Criteria();
     $c->add(PreferencePeer::USER_ID, $this->getId());
     $preferences = PreferencePeer::doSelect($c);
     foreach ($preferences as $preference) {
         if ($preference->getName() != 'box_order') {
             $this->setPreference($preference->getName(), $preference->getValue());
         } else {
             $this->setPreference('box_order', explode(", ", $preference->getValue()));
         }
     }
 }
Beispiel #2
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $notice = $form->getObject()->isNew() ? 'Элемент создан успешно.' : 'Элемент изменен успешно.';
         $form->getObject()->setCompanyId($request->getParameter('element_company'));
         $form->getObject()->setPriceType($request->getParameter('element_price_type'));
         if ($form->getObject()->isNew()) {
             $form->getObject()->setDateCreated(time());
         }
         $form->getObject()->setDateUpdated(time());
         $form->getObject()->setCategoryId($request->getParameter('element_category_id'));
         $Element = $form->save();
         foreach ((array) $request->getParameter('element_file') as $key => $value) {
             if (isset($value['delete'])) {
                 $file_delete = ElementFilePeer::retrieveByPk($key);
                 $file_delete->delete();
             }
         }
         foreach ((array) $request->getFiles('element_file') as $key => $value) {
             list($type, $ext) = explode('/', $value['type']);
             if (isset($value['id']) and $value['id'] != 0) {
                 $file = ElementFilePeer::retrieveByPk($value['id']);
             } else {
                 $file = new ElementFile();
             }
             $file->setElementId($Element->getId());
             $file->setName(md5(time()) . '.' . $ext);
             $file->setFileType($type == 'image' ? 1 : 2);
             $file->save(null, $value);
         }
         foreach ((array) $request->getParameter('element_preference') as $key => $value) {
             if (isset($value['id']) and $value['id'] != 0) {
                 $preference = PreferencePeer::retrieveByPk($value['id']);
             } else {
                 $preference = new Preference();
             }
             $preference->setElementId($Element->getId());
             $preference->setCategoryPreferenceId($value['category_preference_id']);
             $preference->setValue(isset($value['value']) ? $value['value'] : 0);
             $preference->save();
         }
         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Element)));
         if ($request->hasParameter('_save_and_add')) {
             $this->getUser()->setFlash('notice', $notice . ' Можно добавить еще один.');
             $this->redirect('@element_new');
         } else {
             $this->getUser()->setFlash('notice', $notice);
             $this->redirect(array('sf_route' => 'element_edit', 'sf_subject' => $Element));
         }
     } else {
         $this->getUser()->setFlash('error', 'Эелемент не сохранен, так как некоторые поля заполненны не верно!', false);
     }
 }
Beispiel #3
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Element is new, it will return
  * an empty collection; or if this Element has previously
  * been saved, it will retrieve related Preferences from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Element.
  */
 public function getPreferencesJoinCategoryPreference($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(ElementPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collPreferences === null) {
         if ($this->isNew()) {
             $this->collPreferences = array();
         } else {
             $criteria->add(PreferencePeer::ELEMENT_ID, $this->id);
             $this->collPreferences = PreferencePeer::doSelectJoinCategoryPreference($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(PreferencePeer::ELEMENT_ID, $this->id);
         if (!isset($this->lastPreferenceCriteria) || !$this->lastPreferenceCriteria->equals($criteria)) {
             $this->collPreferences = PreferencePeer::doSelectJoinCategoryPreference($criteria, $con, $join_behavior);
         }
     }
     $this->lastPreferenceCriteria = $criteria;
     return $this->collPreferences;
 }
Beispiel #4
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
         $Element = $form->save();
         foreach ((array) $request->getParameter('element_preference') as $key => $value) {
             if (isset($value['id']) and $value['id'] != 0) {
                 $preference = PreferencePeer::retrieveByPk($value['id']);
             } else {
                 $preference = new Preference();
             }
             $preference->setElementId($Element->getId());
             $preference->setCategoryPreferenceId($value['category_preference_id']);
             $preference->setValue(isset($value['value']) ? $value['value'] : 0);
             $preference->save();
         }
         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $Element)));
         if ($request->hasParameter('_save_and_add')) {
             $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
             $this->redirect('@element_new');
         } else {
             $this->getUser()->setFlash('notice', $notice);
             $this->redirect(array('sf_route' => 'element_edit', 'sf_subject' => $Element));
         }
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
Beispiel #5
0
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = ElementPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related Preference objects
         $criteria = new Criteria(PreferencePeer::DATABASE_NAME);
         $criteria->add(PreferencePeer::ELEMENT_ID, $obj->getId());
         $affectedRows += PreferencePeer::doDelete($criteria, $con);
         // delete related Order objects
         $criteria = new Criteria(OrderPeer::DATABASE_NAME);
         $criteria->add(OrderPeer::ELEMENT_ID, $obj->getId());
         $affectedRows += OrderPeer::doDelete($criteria, $con);
         // delete related ElementFile objects
         $criteria = new Criteria(ElementFilePeer::DATABASE_NAME);
         $criteria->add(ElementFilePeer::ELEMENT_ID, $obj->getId());
         $affectedRows += ElementFilePeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
Beispiel #6
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PreferencePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setElementId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setCategoryPreferenceId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setValue($arr[$keys[3]]);
     }
 }
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = CategoryPreferencePeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related Preference objects
         $criteria = new Criteria(PreferencePeer::DATABASE_NAME);
         $criteria->add(PreferencePeer::CATEGORY_PREFERENCE_ID, $obj->getId());
         $affectedRows += PreferencePeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PreferencePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PreferencePeer::DATABASE_NAME);
         $criteria->add(PreferencePeer::ID, $pks, Criteria::IN);
         $objs = PreferencePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 public function executeSavePreferences()
 {
     sfLoader::loadHelpers('I18N');
     $criteria = new Criteria();
     $criteria->add(PreferencePeer::USER_ID, $this->getUser()->getId());
     $preferences = PreferencePeer::doSelect($criteria);
     foreach ($preferences as $preference) {
         $preference->delete();
     }
     $this->msg = __('Preferences saved.');
     if (($preference = $this->getUser()->getPreference('box_user')) != sfConfig::get('app_preference_box_user')) {
         $this->msg .= "\napp_preference_box_user : "******"\napp_preference_box_snippets : " . ($preference == 'none' ? __('do not display') : __('display'));
         $p = new Preference();
         $p->setUserId($this->getUser()->getId());
         $p->setName('box_snippets');
         $p->setValue($preference);
         $p->save();
     }
     if (($preference = $this->getUser()->getPreference('box_language_cloud')) != sfConfig::get('app_preference_box_language_cloud')) {
         $this->msg .= "\napp_preference_box_language_cloud : " . ($preference == 'none' ? __('do not display') : __('display'));
         $p = new Preference();
         $p->setUserId($this->getUser()->getId());
         $p->setName('box_language_cloud');
         $p->setValue($preference);
         $p->save();
     }
     if (($preference = $this->getUser()->getPreference('box_tag_cloud')) != sfConfig::get('app_preference_box_tag_cloud')) {
         $this->msg .= "\napp_preference_box_tag_cloud : " . ($preference == 'none' ? __('do not display') : __('display'));
         $p = new Preference();
         $p->setUserId($this->getUser()->getId());
         $p->setName('box_tag_cloud');
         $p->setValue($preference);
         $p->save();
     }
     if (($preference = $this->getUser()->getPreference('box_snippets_size')) != sfConfig::get('app_preference_box_snippets_size')) {
         $this->msg .= "\napp_preference_box_snippets_size : " . $preference;
         $p = new Preference();
         $p->setUserId($this->getUser()->getId());
         $p->setName('box_snippets_size');
         $p->setValue($preference);
         $p->save();
     }
     if (($preference = $this->getUser()->getPreference('search_size')) != sfConfig::get('app_preference_search_size')) {
         $this->msg .= "\napp_preference_search_size : " . $preference;
         $p = new Preference();
         $p->setUserId($this->getUser()->getId());
         $p->setName('box_search_size');
         $p->setValue($preference);
         $p->save();
     }
     if (($preference = $this->getUser()->getPreference('box_order')) != sfConfig::get('app_preference_box_order')) {
         $order_str = "";
         foreach ($preference as $order_no) {
             $order_str .= "{$order_no}, ";
         }
         $order_str = substr($order_str, 0, strlen($order_str) - 2);
         $p = new Preference();
         $p->setUserId($this->getUser()->getId());
         $p->setName('box_order');
         $p->setValue($order_str);
         $p->save();
         $this->msg .= "\napp_preference_box_order : " . $order_str;
     }
 }