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()));
         }
     }
 }
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Gets an array of Preference objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this Element has previously been saved, it will retrieve
  * related Preferences from storage. If this Element is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array Preference[]
  * @throws     PropelException
  */
 public function getPreferences($criteria = null, PropelPDO $con = null)
 {
     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);
             PreferencePeer::addSelectColumns($criteria);
             $this->collPreferences = PreferencePeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // 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);
             PreferencePeer::addSelectColumns($criteria);
             if (!isset($this->lastPreferenceCriteria) || !$this->lastPreferenceCriteria->equals($criteria)) {
                 $this->collPreferences = PreferencePeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastPreferenceCriteria = $criteria;
     return $this->collPreferences;
 }
 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;
     }
 }