Beispiel #1
0
 /**
  *
  * @author Thiago Lagden
  */
 public static function query($filters, $fields, $table, $name = 'q')
 {
     $q = $table->getListQuery();
     $alias = $q->getRootAlias();
     if (isset($filters[$name]) && $filters[$name]) {
         if (method_exists($table, 'search')) {
             try {
                 // Removendo palavras pequenas
                 $fix = static::fix($filters[$name]);
                 // Try Searchable
                 $search = $table->search($fix);
                 $arr = array();
                 foreach ($search as $v) {
                     $arr[] = $v['id'];
                 }
                 if (count($arr) > 0) {
                     $q->orWhereIn("{$alias}.id", $arr);
                 }
             } catch (Exception $e) {
                 // No Searchable
             }
         }
         // Or Array
         $buildOr = array();
         foreach ($fields as $field) {
             $buildOr[] = "{$alias}.{$field} LIKE '%{$filters[$name]}%'";
         }
         // Add $buildOr in query
         if (count($buildOr)) {
             $q->andWhere(join(' OR ', $buildOr));
         }
     }
     // Added table fields
     if (!empty($filters)) {
         foreach ($filters as $k => $v) {
             if ($k != 'q' && $k != '_csrf_token' && Utils::stringIsNullOrEmpty($v) == false) {
                 $q->andWhere("{$alias}.{$k} = ?", $v);
             }
         }
     }
     // Sort
     $order = sfContext::getInstance()->getUser()->getAttribute(sfConfig::get('order_by'), sfConfig::get('order_by_default', 'id'));
     $direction = sfContext::getInstance()->getUser()->getAttribute(sfConfig::get('order_by_direction'), sfConfig::get('order_by_direction_default', 'DESC'));
     $q->orderBy("{$alias}.{$order} {$direction}");
     return $q;
 }
Beispiel #2
0
 public static function setHttpMeta($o, $n = false, $nc = false, $d = false, $t = false)
 {
     $r = sfContext::getInstance()->getResponse();
     $nc = sfConfig::get($nc, false);
     if ($n) {
         $r->addMeta('title', "{$o->{$n}}" . ($nc ? " - {$nc}" : ''), true, true);
     }
     if ($d) {
         $r->addMeta('description', "{$o->{$d}}", true, true);
     }
     if ($t) {
         if (isset($o->Tags) && count($o->Tags) > 0) {
             $r->addMeta('keywords', Utils::getJoin($o->Tags), true, true);
         }
     }
 }
Beispiel #3
0
 public static function buildLink($v, $param, $extraParam = array(), $offset = null)
 {
     if (isset($param[$offset]) && $v->offsetExists($param[$offset])) {
         return static::buildLink($v->get($param[$offset]), $param, $extraParam, $offset);
     } else {
         $params = array('param' => $param, 'extraParam' => $extraParam);
         if ($v->offsetExists('target')) {
             $r = Utils::regexValidador($v->get('route'), '@(https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?)@');
             $r = $r ? 'param' : 'extraParam';
             $params[$r] = array_merge($params[$r], array('target' => $v->get('target')));
         }
         return link_to($v->get('label'), $v->get('route'), $params['param'], $params['extraParam']);
     }
 }
Beispiel #4
0
 public function executeRemoveFile(sfWebRequest $request)
 {
     $g = static::galeriaInfo();
     $this->getResponse()->setContentType('application/json');
     // Response
     $response = Utils::response();
     // Verifica a sessão
     $auth = $this->getUser()->isAuthenticated();
     if (!$auth) {
         $response['auth'] = false;
         $response['msg'] = "Sessão expirada. Efetue o login novamente.";
         return $this->renderText(json_encode($response));
     }
     // Verificando Method
     if ($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::DELETE)) {
         $result = Doctrine_Core::getTable($g['tabela'])->find($request['id']);
     } else {
         $response['msg'] = "Os métodos permitidos são: POST ou DELETE.";
     }
     // Do it
     if ($result) {
         $result->delete();
         $response['success'] = true;
         $response['msg'] = "O arquivo foi removido com sucesso.";
         $response['data'] = array('id' => $request['id']);
     } else {
         $response['msg'] = "Arquivo não encontrado.";
     }
     return $this->renderText(json_encode($response));
 }