Пример #1
0
 /**
  * function to add all user's widgets in my_widgets table
  * use user id and db_user_type
  * @return the number of widget added
  */
 public function addUserWidgets($thisWidget = null)
 {
     $count_widget = 0;
     $array_right = Users::getTypes(array('db_user_type' => self::ADMIN));
     foreach ($array_right as $key => $right) {
         $file = MyWidgets::getFileByRight($key);
         if ($file) {
             $data = new Doctrine_Parser_Yml();
             $array = $data->loadData($file);
             foreach ($array as $widget => $array_values) {
                 if ($thisWidget) {
                     if (isset($thisWidget['category']) && $thisWidget['category'] != $array_values['category']) {
                         continue;
                     } elseif (isset($thisWidget['name']) && isset($thisWidget['category']) && ($thisWidget['name'] != $array_values['group_name'] || $thisWidget['category'] != $array_values['category'])) {
                         continue;
                     }
                 }
                 $pref = new MyWidgets();
                 $array_values['user_ref'] = $this->getId();
                 $pref->fromArray($array_values);
                 $pref->setIsAvailable(true);
                 try {
                     $pref->save();
                     $count_widget++;
                 } catch (Doctrine_Exception $ne) {
                 }
             }
         }
     }
     return $count_widget;
 }
 /**
  * set or unset the availability of widgets for a user and a role
  * @param string $role Group of widget for which the availability must be updated
  * @param boolean $availability Is the $role must be set as available or not
  */
 public function updateWigetsAvailabilityForRole($role, $availability)
 {
     $file = MyWidgets::getFileByRight($role);
     if ($file) {
         $data = new Doctrine_Parser_Yml();
         $array = $data->loadData($file);
         $q = Doctrine_Query::create()->update('MyWidgets p')->set('p.is_available', '?', $availability)->where('p.user_ref = ?', $this->user_ref);
         $list_group_name = array();
         foreach ($array as $widget => $array_values) {
             $list_group_name[] = $array_values['group_name'];
         }
         $q->wherein('p.group_name', $list_group_name)->execute();
     }
 }
Пример #3
0
 public function setPropertyTemplate($template)
 {
     $file = sfConfig::get('sf_data_dir') . '/feed/properties_template.yml';
     $data = new Doctrine_Parser_Yml();
     $array = $data->loadData($file);
     //This test below is theoricaly not necessary since the table should exist in properties_template.yml
     if (@is_array($array[$this->getReferencedRelation()][$template])) {
         $this->fromArray($array[$this->getReferencedRelation()][$template]);
     } else {
         return null;
     }
 }