Ejemplo n.º 1
0
 /**
  * Return a conditions array to pass for instance to the paginate method of the calling controller
  *
  * @access public
  */
 function get_filter()
 {
     $this->_prepareFilter();
     $filter = array();
     if (isset($this->controller->data) && count($this->controller->data) > 0) {
         //Loop for models
         foreach ($this->controller->data as $model_name => $field_values) {
             if ($model_name == self::MODEL_TECHNICAL || $model_name == '_Token') {
                 continue;
             }
             $start_end_pairs = array();
             foreach ($field_values as $field_name => $value) {
                 /*
                  * If the linked Model is not loaded yet, tries to load it
                  */
                 if (!isset($this->controller->{$model_name})) {
                     $this->controller->loadModel($model_name);
                 }
                 if (isset($this->controller->{$model_name}) || array_key_exists($field_name, $this->alias_fields)) {
                     $build_from_to = false;
                     $field_wo_prefix = null;
                     if ($this->startsWith($field_name, self::START_PREFIX)) {
                         $field_wo_prefix = substr($field_name, strlen(self::START_PREFIX));
                         if (!array_key_exists($field_wo_prefix, $start_end_pairs)) {
                             $start_end_pairs[$field_wo_prefix] = array();
                         }
                         $start_end_pairs[$field_wo_prefix]['start'] = $value;
                         if (isset($start_end_pairs[$field_wo_prefix]['end'])) {
                             $build_from_to = true;
                         }
                     } elseif ($this->startsWith($field_name, self::END_PREFIX)) {
                         $field_wo_prefix = substr($field_name, strlen(self::END_PREFIX));
                         if (!array_key_exists($field_wo_prefix, $start_end_pairs)) {
                             $start_end_pairs[$field_wo_prefix] = array();
                         }
                         $start_end_pairs[$field_wo_prefix]['end'] = $value;
                         if (isset($start_end_pairs[$field_wo_prefix]['start'])) {
                             $build_from_to = true;
                         }
                     }
                     if ($build_from_to) {
                         $filter = $this->build_from_to_filter($filter, $model_name, $field_wo_prefix, $start_end_pairs);
                     } else {
                         if (!empty($value) && is_array($value)) {
                             $filter = $this->build_many_value_filter($filter, $model_name, $field_name, $value);
                         } else {
                             if (strlen($value) > 0 && !$this->startsWith($field_name, self::START_PREFIX) && !$this->startsWith($field_name, self::END_PREFIX)) {
                                 $filter = $this->build_one_value_filter($filter, $model_name, $field_name, $value);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $filter;
 }
Ejemplo n.º 2
0
 public function auto_clean_logs()
 {
     if (isset($this->days_to_keep_logs)) {
         if (!isset($this->controller->Log)) {
             $this->controller->loadModel('Alaxos.Log');
         }
         if (!$this->controller->Log->deleteAll(array('Log.created < ' => date('Y-m-d H:i:s', strtotime('-' . $this->days_to_keep_logs . ' days')), 'NOT' => array('Log.log_category_id' => $this->log_categories_to_keep)), false, false)) {
             $this->controller->Session->setFlash(___('a log record could not be saved', true), 'flash_error');
         }
     }
 }
 function admin_configurations()
 {
     parent::loadModel('Option');
     $stitle = $this->Option->getOption('site_title');
     $title = $this->Option->getOption('title');
     $taglines = $this->Option->getOption('taglines');
     $viewlogo = $this->Option->getOption('viewlogo');
     $themes = $this->Option->getOption('theme');
     if (!empty($this->data)) {
         if ($title !== false && $title == null) {
             //do save
             $this->Option->setOption('title', $this->data['Option']['title']);
         } else {
             //do update
             $this->Option->setOption('title', $this->data['Option']['title'], false);
         }
         if ($stitle !== false && $stitle == null) {
             //do save
             $this->Option->setOption('site_title', $this->data['Option']['stitle']);
         } else {
             //do update
             $this->Option->setOption('site_title', $this->data['Option']['stitle'], false);
         }
         $taglines_val = array($this->data['Option'][0]['description'], $this->data['Option'][1]['description'], $this->data['Option'][2]['description'], $this->data['Option'][3]['description']);
         if ($taglines !== false && $taglines == null) {
             //do save
             $this->Option->setOption('taglines', $taglines_val);
         } else {
             //do update
             $this->Option->setOption('taglines', $taglines_val, false);
         }
         if ($viewlogo !== false && $viewlogo == null) {
             //do save
             $this->Option->setOption('viewlogo', $this->data['Option']['viewlogo']);
         } else {
             //do update
             $this->Option->setOption('viewlogo', $this->data['Option']['viewlogo'], false);
         }
         if ($themes !== false && $themes == null) {
             //do save
             $this->Option->setOption('theme', $this->data['Option']['theme']);
         } else {
             //do update
             $this->Option->setOption('theme', $this->data['Option']['theme'], false);
         }
         $this->Session->setFlash(__('Options Save!', true));
         $this->redirect($this->referer());
     }
     $this->set(compact('title', 'stitle', 'taglines', 'viewlogo', 'themes'));
 }
 /**
  * Tries to find an already existing user in the database corresponding to the Shibboleth logged user
  *
  * @return Model
  */
 public function get_existing_user()
 {
     if ($this->has_shibboleth_session()) {
         $shibboleth_uid = $this->get_shibboleth_uid();
         if (isset($shibboleth_uid) && strlen($shibboleth_uid) > 0) {
             /*
              * Tries to find a Model in the database having this external uid
              */
             if (!isset($this->controller->{$this->user_model_name})) {
                 $this->controller->loadModel($this->user_model_name);
             }
             if (isset($this->authentication_type_fieldname) && isset($this->default_authentication_type_value)) {
                 $user = $this->controller->{$this->user_model_name}->find('first', array('conditions' => array($this->get_external_uid_fieldname() => $shibboleth_uid, $this->get_authentication_type_fieldname() => $this->default_authentication_type_value)));
             } else {
                 $user = $this->controller->{$this->user_model_name}->find('first', array('conditions' => array($this->get_external_uid_fieldname() => $shibboleth_uid)));
             }
             return $user;
         }
     } else {
         return null;
     }
 }
Ejemplo n.º 5
0
 function initialize($controller, $settings = array())
 {
     $this->controller = $controller;
     $this->controller->loadModel("Member");
     $this->controller->loadModel("Country");
 }
 function _getOption($name)
 {
     $value = null;
     if ($this->_isTableExists('options')) {
         parent::loadModel('Options');
         $options = $this->Options->findByName($name);
         $value = $options['Options']['value'];
     }
     return $value;
 }