public function countApplications()
 {
     if (isset($this->_job_id)) {
         $apps = R::count('applications', ' job_id=:job_id ORDER BY created DESC ', array(':job_id' => $this->_job_id));
     } else {
         $apps = R::count('applications', ' ORDER BY created DESC ');
     }
     return $apps;
 }
 public function deleteCity()
 {
     $count = R::count('jobs', " city=:city ", array(':city' => $this->_id));
     if (!$count) {
         $city = R::load('cities', $this->_id);
         R::trash($city);
         return true;
     }
     return false;
 }
Example #3
0
function getCLientesTotal()
{
    $app = \Slim\Slim::getInstance();
    $total = R::dispense('total');
    $total->total = R::count('clientes');
    $app->response()->header('Content-Type: text/html; charset=utf-8');
    $app->response()->header('Content-Type', 'application/json');
    //TODO: Buscar un modo elegante de hacer lo siguiente:
    echo json_encode(R::exportAll($total)[0]);
}
 public function deleteCategory()
 {
     $count = R::count('jobs', " category=:category ", array(':category' => $this->_id));
     if (!$count) {
         $category = R::load('categories', $this->_id);
         R::trash($category);
         return true;
     }
     return false;
 }
Example #5
0
 public static function getWisdom($id)
 {
     $information = R::load('information', $id);
     $typeData = self::getType($information);
     $wisdomTypeArray = [1 => 1, 2 => 2, 3 => 3];
     $out = '';
     $autor = self::getAuthorName($id);
     //        if ($typeData[3]->id == 6) {
     //
     //        $out = R::load('lesson', $id)->text . "Автор:<a  href='?ctrl=user&action=UserInfo&id=" . $autor['id'] . "'> " . $autor['surname'] .
     //            " " . $autor['name'] . " " . $autor['andername'] . " </a></div>";
     //        return $out;
     //    }
     if ($typeData[3]->id == 1) {
         $count_modul = R::count("education", " education.information_id = ? and education.block = 1", [$id]);
     } elseif ($typeData[3]->id == 5) {
         $count_modul = R::count("lesson", "lesson.information_id = ? and lesson.block = 1", [$id]);
     }
     $out .= "<ol class=\"breadcrumb\">\r\n                    <li><a href=\"?ctrl=wisdom&action=WisdomType&type=" . $typeData[3]->id . "&page=1\">" . $typeData[3]->name . "</a></li>\r\n                    <li><a href=\"?ctrl=wisdom&action=WisdomType&type=" . $typeData[3]->id . "&subtype=" . $typeData[2]->id . "&page=1\">" . $typeData[2]->name . "</a></li>\r\n                    <li><a href=\"?ctrl=wisdom&action=WisdomType&type=" . $typeData[3]->id . "&subtype=" . $typeData[2]->id . "&category=" . $typeData[1]->id . "&page=1\">" . $typeData[1]->name . "</a></li>\r\n                    <li><a href=\"?ctrl=wisdom&action=WisdomType&type=" . $typeData[3]->id . "&subtype=" . $typeData[2]->id . "&category=" . $typeData[1]->id . "&subcategory=" . $typeData[0]->id . "&page=1\">" . $typeData[0]->name . "</a></li>\r\n\r\n                </ol>";
     $out .= "<h2>" . $information->name . "</h2>";
     $out .= "<div style='margin-bottom: 15px;'>" . $information->description . "</div>";
     if ($typeData[3]->id == 6) {
         return $out;
     }
     if ($count_modul == 0) {
         $out .= "<h2 class='text-center'>Совсем скоро!</h2>";
         return $out;
     }
     $out .= "<ul class=\"list-group\">\r\n                    <li class=\"list-group-item active\">Дополнительная информация</li>\r\n                    <li class=\"list-group-item \">Автор:\r\n                    <a  href='?ctrl=cabinet&action=UserInfo&id=" . $autor['id'] . "'>" . $autor['login'] . "</a> |\r\n                    <a  href='?ctrl=cabinet&action=UserInfo&id=" . $autor['id'] . "'> " . $autor['surname'] . " " . $autor['name'] . " " . $autor['andername'] . " </a></li>\r\n                    <li class=\"list-group-item\"> Кол-во модулей: " . $count_modul . "</li></ul>";
     //        print_r($information);
     if ($typeData[3]->id == 1) {
         $education = $information->withCondition('education.information_id = ? and education.block = 1', [$id])->ownEducationList;
     } elseif ($typeData[3]->id == 5) {
         $education = $information->withCondition('lesson.information_id = ? and lesson.block = 1', [$id])->ownLessonList;
     }
     $out .= "<ul class=\"list-group\"><li class=\"list-group-item active\">Изучаемые модули</li>";
     foreach ($education as $item) {
         $out .= "<li class=\"list-group-item \"><h4 class=\"list-group-item-heading\">" . $item->name . "</h4>\r\n                    <p class=\"list-group-item-text\">{$item->description}</p>\r\n            </li>";
     }
     $out .= "</ul>";
     $requirements = $information->withCondition('block = 1')->ownRequirementsList;
     $out .= "<ul class=\"list-group\"><li class=\"list-group-item active\">Требования</li>";
     if (empty($requirements)) {
         $out .= "<li class=\"list-group-item\"><strong>Без дополнительных требований</strong></li></ul>";
     } else {
         foreach ($requirements as $item) {
             $information_requirements = R::getRow("SELECT information.id,information.name from information WHERE information.id = ?", [$item->requirements]);
             $out .= "<li class=\"list-group-item\"><a href='?ctrl=wisdom&action=GetWisdomById&id=" . $information_requirements['id'] . "'>" . $information_requirements['name'] . "</a></li>";
         }
         $out .= "</ul>";
     }
     $out .= "</div><div class=\"col-sm-3\"></div>\r\n        <div class=\"col-sm-6\">\r\n            <a href=\"?ctrl=subscription&action=SubscriptionById&id=" . $id . "\"><button style='margin-top:15px;' class=\"btn btn-success btn-block\">Записаться!</button></a>\r\n        </div>\r\n        <div class=\"col-sm-3\"></div>";
     return $out;
 }
Example #6
0
 /**
  * Handle publication recent results operations /
  *
  * @param object    $context    The context object for the site
  *
  * @return string    A template name
  */
 public function handle($context)
 {
     $pagesize = 5;
     $amount = R::count('publication');
     $page = $context->getpar('page', 1);
     # Find all publications and paginate them.
     $pubs = R::findAll('publication', 'ORDER BY Id desc limit ?,?', [($page - 1) * $pagesize, $pagesize]);
     # Get the URL for the paginator.
     $url = $context->action() . '?';
     # Delegate the publishement bean to the results handler.
     return (new Results($pubs, $url, $pagesize, $amount, $page))->handle($context);
 }
 /**
  * Tests dependencies (variation).
  * 
  * @return void
  */
 public function testDependency4()
 {
     R::dependencies(array('bean' => array('can')));
     $can = $this->createCanForBean();
     asrt(R::count('bean'), 1);
     R::trash($can);
     asrt(R::count('bean'), 0);
     R::dependencies(array());
     $can = $this->createCanForBean();
     asrt(R::count('bean'), 1);
     R::trash($can);
     asrt(R::count('bean'), 1);
 }
Example #8
0
 public function __construct()
 {
     // Check for pre-existing fields in db
     $gnl_count = R::count('fields', ' service=? ', array('gnl'));
     $sf_count = R::count('fields', ' service=? ', array('sf'));
     $mapped_count = R::count('fields', ' service=? ', array('mapped'));
     // If no GNL keys mapped, use the following array and store in db
     if ($gnl_count < 1) {
         $key_items = '0,1,caller_city,caller_name,caller_number,caller_postal_code,caller_state,classification,comments,date,duration,email,first_name,help,how_can_we_help,id,im_budget,interested_in,name,notes,phone,seogroup-form-email,seogroup-form-keyword,seogroup-form-name,source,status,trackable_number,type,website_budget,website_url';
         $w = R::dispense('fields');
         $w->service = 'gnl';
         $w->key = $key_items;
         R::store($w);
     } else {
         $leads = R::find('fields', 'service = ?', array('gnl'));
         foreach ($leads as $key => $value) {
             $key_items .= $value->key;
         }
     }
     $gnl_fields = explode(',', $key_items);
     unset($key_items);
     // If no SF keysk call GetSFKey which grabs the keys from SF
     if ($sf_count < 1) {
         $leads = new GetSFKey();
         $sf_fields = $leads->sf_fields;
         foreach ($sf_fields as $key => $value) {
             $key_items .= $value->name . ',';
         }
         $sf_fields = explode(',', $key_items);
     } else {
         $leads = R::find('fields', 'service = ?', array('sf'));
         foreach ($leads as $key => $value) {
             $key_items = $value->key;
         }
         $sf_fields = explode(',', $key_items);
     }
     // Mapped field
     if ($mapped_count > 0) {
         $mapped = R::find('fields', 'service = ?', array('mapped'));
         foreach ($mapped as $key => $value) {
             $mapped_keys .= $value->key;
         }
         $mapped_fields = explode(',', $mapped_keys);
     }
     $this->gnl_fields = $gnl_fields;
     $this->sf_fields = $sf_fields;
     $this->mapped_fields = $mapped_fields;
 }
 public function manageView()
 {
     /*
      * Loading libraries
      */
     $this->load->library(array('rb', 'session'));
     $this->load->helper(array('form'));
     /*
      * Verify if user has autority to view the ic's
      */
     if (!parent::_hasAuth('view_ic', $this->session->userdata('user_ic'))) {
         echo "Você não tem permissão para realizar este procedimento.";
         exit;
     }
     /*
      * Setting allowed functions of user for manage information center
      */
     $allow = '';
     if (parent::_hasAuth('edit_ic', $this->session->userdata('user_ic'))) {
         $allow .= 'E';
     }
     if (parent::_hasAuth('create_ic', $this->session->userdata('user_ic'))) {
         $allow .= 'C';
     }
     if (parent::_hasAuth('remove_ic', $this->session->userdata('user_ic'))) {
         $allow .= 'R';
     }
     /* 
      * Verify if the user is logged in MASTER IC or not. If it's the MASTER IC
      * then it shows all the IC's, otherwise, only show the actual IC.
      */
     $ics = null;
     if (R::count('ic', 'id=? AND master="yes" ', array($this->session->userdata('user_ic')))) {
         $ics = R::find('ic', ' active!="no" ');
     } else {
         $ics = R::find('ic', ' id=? AND active!="no" ', array($this->session->userdata('user_ic')));
     }
     /* 
      * Loading views
      */
     $this->load->view('dashboard/template/header');
     $this->load->view('dashboard/template/menu', array('menu' => parent::_getMenu(parent::_getIc()->id), 'ics' => parent::_getIcs(), 'ic' => parent::_getIc()));
     $this->load->view('dashboard/ic/manage', array('ics' => $ics, 'gauth' => R::find('gauth'), 'allow' => $allow));
     $this->load->view('dashboard/template/footer');
 }
Example #10
0
 public function create($email, $firstname, $lastname, $password, $passwordConfirm)
 {
     //echo "create called";
     //	exit();
     $errors = array('email' => false, 'firstname' => false, 'lastname' => false, 'password' => false);
     $fixes = array();
     if ('' == $email || '' == $firstname || '' == $lastname || '' == $password) {
         $fixes[] = "All fields are required.";
     }
     if (0 != \R::count(self::TABLENAME, 'email = ?', [$email])) {
         $errors['email'] = true;
         $fixes[] = 'That email address is already in use. Please click Sign In below and try again.';
     }
     /*  if (0 != \R::count(self::TABLENAME, 'email = ?', [$email]))
     		{
     		$errors['email'] = true;
     		$fixes[] = 'That email is already in use.';
     		}
     		 */
     if ($password != $passwordConfirm) {
         $errors['password'] = true;
         $fixes[] = 'The passwords entered do not match.';
     }
     if (0 == count($fixes)) {
         $date = date(self::DATE_FORMAT);
         $user = $this->bean;
         $user->email = $email;
         $user->first_name = $firstname;
         $user->last_name = $lastname;
         $user->salt = password_hash($email . $date, PASSWORD_BCRYPT);
         $user->password = password_hash($password, PASSWORD_BCRYPT, array('salt' => $user->salt));
         $user->created_at = $date;
         $user->last_login = null;
         $user->loginAttempts = 0;
         $user->active = true;
         // Add any other attributes you want a User to have here (or not,
         // Redbean will add them when you use them if the DB isn't frozen).
         \R::store($user);
         $this->bean = $user;
         $_SESSION['user'] = $user;
     }
     return array($errors, $fixes);
 }
Example #11
0
 /**
  * Test count and wipe.
  * 
  * @return void
  */
 public function testCountAndWipe()
 {
     testpack("Test count and wipe");
     $page = R::dispense("page");
     $page->name = "ABC";
     R::store($page);
     $n1 = R::count("page");
     $page = R::dispense("page");
     $page->name = "DEF";
     R::store($page);
     $n2 = R::count("page");
     asrt($n1 + 1, $n2);
     R::wipe("page");
     asrt(R::count("page"), 0);
     asrt(R::$redbean->count("page"), 0);
     asrt(R::$redbean->count("kazoo"), 0);
     // non existing table
     R::freeze(TRUE);
     asrt(R::$redbean->count("kazoo"), 0);
     // non existing table
     R::freeze(FALSE);
     $page = R::dispense('page');
     $page->name = 'foo';
     R::store($page);
     $page = R::dispense('page');
     $page->name = 'bar';
     R::store($page);
     asrt(R::count('page', ' name = ? ', array('foo')), 1);
     // Now count something that does not exist, this should return 0. (just be polite)
     asrt(R::count('teapot', ' name = ? ', array('flying')), 0);
     asrt(R::count('teapot'), 0);
     $currentDriver = $this->currentlyActiveDriverID;
     // Some drivers don't support that many error codes.
     if ($currentDriver === 'mysql' || $currentDriver === 'postgres') {
         try {
             R::count('teaport', ' for tea ');
             fail();
         } catch (RedBean_Exception_SQL $e) {
             pass();
         }
     }
 }
 /**
  * Authenticate 
  *
  * @param   string  $username   The HTTP Authentication username
  * @param   string  $password   The HTTP Authentication password     
  *
  */
 public function authenticate($username, $password)
 {
     if (!ctype_alnum($username)) {
         return false;
     }
     if (isset($username) && isset($password)) {
         $user = R::findOne('users', 'login="******" AND password="******"');
         if ($user) {
             /*
              * Deleting all beans older then 5mn
              */
             $date2 = time() - 60;
             $date = date('Y-m-d h:i:s', $date2);
             $beans = R::findAll('log', 'date<"' . $date . '"');
             R::trashAll($beans);
             /*
              * checking if the users can do more requests
              */
             $number = R::count('log', 'user_id= ?', [$user->id]);
             if ($number > 250) {
                 return false;
             } else {
                 /*
                  * saving the logs in the database
                  */
                 $log = R::dispense('log');
                 $log->date = date('Y-m-d h:i:s');
                 $log->user = $user;
                 R::store($log);
                 return true;
             }
         }
     } else {
         return false;
     }
 }
 public function updateDo()
 {
     /* 
      * Loading libraries and helpers
      */
     $this->load->library(array('rb', 'form_validation', 'session'));
     $this->load->helper(array('security'));
     /*
      * User is logged ?
      */
     if (!parent::_isLogged()) {
         redirect('dashboard');
         exit;
     }
     /* 
      * Getting post variables
      */
     $id = $this->input->post('id');
     $name = $this->input->post('name');
     $email = $this->input->post('email');
     $pass = $this->input->post('passre');
     $cpf = $this->input->post('cpf');
     $phone = $this->input->post('phone');
     $permissions = $this->input->post('permissions');
     /*
      * Has permissions?
      */
     $canEditPermissions = parent::_hasAuth('edit_user_permission', $this->session->userdata('user_ic'));
     if ($canEditPermissions && !count($permissions)) {
         $this->session->set_flashdata('error', 'O usuário precisa ter permissões para ser atualizado.');
         $this->session->set_flashdata('popform', array('name' => $name, 'email' => $email, 'cpf' => $cpf, 'phone' => $phone));
         redirect('dashboard/user/edit/' . $id);
     }
     /*
      * Resolving permissions
      */
     $permissionsFinal = array();
     foreach ($permissions as $p) {
         $ar = explode('-', $p);
         $permissionsFinal[] = array('ic' => R::findOne('ic', ' id=? ', array($ar[0])), 'group' => R::findOne('group', ' id=? ', array($ar[1])));
     }
     /*
      * Setting rules
      */
     $this->form_validation->set_rules('name', 'Nome', 'required');
     $this->form_validation->set_rules('email', 'Email', 'required');
     $this->form_validation->set_rules('cpf', 'CPF', 'required');
     $this->form_validation->set_rules('phone', 'Telefone', 'required');
     if ($canEditPermissions) {
         $this->form_validation->set_rules('permissions[]', 'Permissões', 'required');
     }
     /*
      * Normally, user wiil never see what makes this true, just for security issues
      */
     if (!$this->form_validation->run()) {
         $this->session->set_flashdata('error', $this->form_validation->error_string());
         if ($canEditPermissions) {
             $this->session->set_flashdata('popform', array('name' => $name, 'email' => $email, 'cpf' => $cpf, 'phone' => $phone, 'permissions' => $user->ownPermissionList));
         } else {
             $this->session->set_flashdata('popform', array('name' => $name, 'email' => $email, 'cpf' => $cpf, 'phone' => $phone));
         }
         redirect('dashboard/user/edit/' . $id);
         exit;
     }
     /* 
      * User has auth to do this?
      */
     if (!parent::_hasAuth('edit_user', $this->session->userdata('user_ic'))) {
         $this->session->set_flashdata('error', 'Você não tem permissão para realizar este procedimento.');
         redirect('dashboard/user');
         exit;
     }
     /* 
      * User has auth to do this?
      */
     $user = R::findOne('user', 'id=? AND active!="no" ', array($id));
     /* 
      * Verifying if user exists
      */
     if ($user == NULL) {
         $this->session->set_flashdata('error', 'O usuário solicitado para atualização não existe.');
         redirect('dashboard/user');
     }
     /* 
      * CPF already exists ?
      */
     if ($user->cpf != $cpf && R::count('user', 'cpf=?', array($cpf))) {
         $this->session->set_flashdata('error', 'Já existe um usuário cadastrado com este CPF.');
         redirect('dashboard/user');
         exit;
     }
     /* begin clone to log */
     $user->ownPermissionList;
     $aprex0 = json_encode($user->export());
     /* end clone to log */
     $user->name = $name;
     $user->email = $email;
     if ($pass != '') {
         $user->password = do_hash($pass, 'md5');
     }
     $user->cpf = $cpf;
     $user->phone = $phone;
     /*
      * Has permission to edit permission?
      */
     if ($canEditPermissions) {
         // Removing permissions from user
         $user->ownPermissionList = array();
     }
     /*
      * Update User
      */
     R::store($user);
     /*
      * Adding permissions to user
      */
     if ($canEditPermissions) {
         foreach ($permissionsFinal as $p) {
             $pe = R::dispense('permission');
             $pe->user = $user;
             $pe->ic = $p['ic'];
             $pe->group = $p['group'];
             R::store($pe);
         }
     }
     /*
      * Generating and creating log 
      */
     $user->ownPermissionList;
     $aprex = json_encode($user->export());
     parent::_createLog('update_user', $aprex0, $aprex);
     /*
      * Success message
      */
     $this->session->set_flashdata('success', 'Usuário atualizado com sucesso');
     redirect('dashboard/user');
 }
 /**
  * Test multiple assiociation.
  * 
  * @return void
  */
 public function testMultiAssociationDissociation()
 {
     $wines = R::dispense('wine', 3);
     $cheese = R::dispense('cheese', 3);
     $olives = R::dispense('olive', 3);
     R::associate($wines, array_merge($cheese, $olives));
     asrt(R::count('cheese'), 3);
     asrt(R::count('olive'), 3);
     asrt(R::count('wine'), 3);
     asrt(count($wines[0]->sharedCheese), 3);
     asrt(count($wines[0]->sharedOlive), 3);
     asrt(count($wines[1]->sharedCheese), 3);
     asrt(count($wines[1]->sharedOlive), 3);
     asrt(count($wines[2]->sharedCheese), 3);
     asrt(count($wines[2]->sharedOlive), 3);
     R::unassociate($wines, $olives);
     asrt(count($wines[0]->sharedCheese), 3);
     asrt(count($wines[0]->sharedOlive), 0);
     asrt(count($wines[1]->sharedCheese), 3);
     asrt(count($wines[1]->sharedOlive), 0);
     asrt(count($wines[2]->sharedCheese), 3);
     asrt(count($wines[2]->sharedOlive), 0);
     R::unassociate(array($wines[1]), $cheese);
     asrt(count($wines[0]->sharedCheese), 3);
     asrt(count($wines[0]->sharedOlive), 0);
     asrt(count($wines[1]->sharedCheese), 0);
     asrt(count($wines[1]->sharedOlive), 0);
     asrt(count($wines[2]->sharedCheese), 3);
     asrt(count($wines[2]->sharedOlive), 0);
     R::unassociate(array($wines[2]), $cheese);
     asrt(count($wines[0]->sharedCheese), 3);
     asrt(count($wines[0]->sharedOlive), 0);
     asrt(count($wines[1]->sharedCheese), 0);
     asrt(count($wines[1]->sharedOlive), 0);
     asrt(count($wines[2]->sharedCheese), 0);
     asrt(count($wines[2]->sharedOlive), 0);
 }
Example #15
0
        if ($vehiculo) {
            $app->response()->header('Content-Type', 'application/json');
            echo json_encode(R::exportAll($vehiculo)[0]);
        } else {
            throw new ResourceNotFoundException();
        }
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(404);
    } catch (Exception $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
});
$app->get('/vehiculos/total/', function () use($app) {
    $total = R::dispense('total');
    $total->total = R::count('vehiculos');
    $app->response()->header('Content-Type: text/html; charset=utf-8');
    $app->response()->header('Content-Type', 'application/json');
    //TODO: Buscar un modo elegante de hacer lo siguiente:
    echo json_encode(R::exportAll($total)[0]);
});
$app->get('/vehiculos/page/:pagenumber', function ($pagenumber) use($app) {
    $vehiculos = R::findAll('vehiculos', 'ORDER BY economico LIMIT ?,8', array($pagenumber * 8 - 8));
    $app->response()->header('Content-Type: text/html; charset=utf-8');
    $app->response()->header('Content-Type', 'application/json');
    foreach ($vehiculos as $vehiculo) {
        $vehiculo->tipo_vehiculos = $vehiculo->tipo_vehiculos;
    }
    echo json_encode(R::exportAll($vehiculos));
});
// Handle GET by vehiculo name
 public function manageView()
 {
     /*
      * Loadings libraries and helpers
      */
     $this->load->library(array('rb'));
     $this->load->helper(array('form'));
     /*
      * User is logged?
      */
     if (!parent::_isLogged()) {
         redirect('dashboard');
     }
     /*
      * General Information
      */
     $openRequestsQry = '
         SELECT r.*
         FROM status AS s
         JOIN request AS r 
         ON r.id = s.request_id 
         WHERE 
             s.current = "Y" 
             AND ( s.type = "waiting-open" 
                 OR s.type = "request_created" 
                 OR s.type = "request_moved" 
                 OR s.type = "request_extended" 
             ) 
     ';
     $openRequests = R::getAll($openRequestsQry);
     $openRequests = R::convertToBeans('request', $openRequests);
     $deadlineRequestsQry = '
         SELECT r.*
         FROM status AS s 
         JOIN request AS r 
         ON r.id = s.request_id 
         WHERE 
             ( 
                 NOW() > DATE_ADD( r.created_at, INTERVAL 20 DAY )
                 AND
                 ( SELECT COUNT(*) FROM status AS ss WHERE request_id = r.id AND type = "request_extended" ) <= 0
             )
             OR
             (
                 NOW() > DATE_ADD( r.created_at, INTERVAL 30 DAY )
                 AND
                 ( SELECT COUNT(*) FROM status AS ss WHERE request_id = r.id AND type = "request_extended" ) > 0
             )
     ';
     $deadlineRequests = R::getAll($deadlineRequestsQry);
     $deadlineRequests = R::convertToBeans('request', $deadlineRequests);
     $repliedRequestsQry = '
         SELECT r.*
         FROM status AS s
         JOIN request AS r 
         ON r.id = s.request_id 
         WHERE 
             s.current = "Y" 
             AND s.type = "request_replied" 
     ';
     $repliedRequests = R::getAll($repliedRequestsQry);
     $repliedRequests = R::convertToBeans('request', $repliedRequests);
     $data = array('ics' => R::find('ic', ' active="yes" '), 'openRequests' => count($openRequests), 'deadlineRequests' => count($deadlineRequests), 'replyRequests' => count($repliedRequests), 'totalRequests' => R::count('request'));
     /*
      * Loading views
      */
     $this->load->view('dashboard/template/header');
     $this->load->view('dashboard/template/menu', array('menu' => parent::_getMenu(parent::_getIc()->id), 'ics' => parent::_getIcs(), 'ic' => parent::_getIc()));
     $this->load->view('dashboard/manage', $data);
     $this->load->view('dashboard/template/footer');
 }
Example #17
0
//
// NEWS FEED FROM BUNGIE
//
$feed = implode(file('https://www.bungie.net/en/Rss/NewsByCategory?category=destiny&currentpage=1&itemsPerPage=10'));
$xml = simplexml_load_string($feed);
$json = json_encode($xml);
$array = json_decode($json, TRUE);
$data['feed'] = [];
foreach ($array['channel']['item'] as $item) {
    array_push($data['feed'], $item);
}
//
// GUARDIANS DATA
//
$data['guardians'] = [];
$data['guardianCount'] = R::count("users", " banned = 0 AND enabled = 1");
$guardians = R::find("users", " banned = 0 AND enabled = 1 ORDER BY id DESC LIMIT 5");
foreach ($guardians as $g) {
    // find characters
    $uuid = $user->getMembershipID($g['gamerid'], $g['platform']);
    $gData = $user->getAccountDetails($uuid, $g['platform']);
    foreach ($gData['Response']['data']['characters'] as $char) {
        if ($char['baseCharacterLevel'] == 20) {
            $char['characterBase']['bonus'] = $char['characterLevel'] - $char['baseCharacterLevel'];
        }
        $char['characterBase']['owner'] = $g['gamerid'];
        $char['characterBase']['class'] = lib\classHash::toText($char['characterBase']['classHash']);
        $char['characterBase']['level'] = $char['baseCharacterLevel'];
        $char['characterBase']['toNextLevel'] = $char['percentToNextLevel'];
        $char['characterBase']['emblem'] = 'http://www.bungie.net' . $char['emblemPath'];
        array_push($data['guardians'], $char['characterBase']);
    	All of the images you see here are transformed and served by Cloudinary. 
    	For instance, the logo and the poster frame. 
    	They are both generated in the cloud using the Cloudinary shortcut functions: fetch_image_tag and facebook_profile_image_tag. 
    	These two pictures weren't even have to be uploaded to Cloudinary, they are retrieved by the service, transformed, cached and distributed through a CDN.
    </p>

    <h1>Your Images</h1>
    <div class="photos">
	  <p>
	  	Following are the images uploaded by you. You can also upload more pictures.
	    
	    You can click on each picture to view its original size, and see more info about and additional transformations.
	    <a class="upload_link" href="upload.php">Upload Images...</a>
	  </p>
      <?php 
if (R::count('photo') == 0) {
    ?>
        <p>No images were uploaded yet.</p>
      <?php 
}
$index = 0;
foreach (R::findAll('photo') as $photo) {
    ?>
        <div class="photo">
            <a href="<?php 
    echo cloudinary_url($photo["public_id"], array("format" => $photo["format"]));
    ?>
" target="_blank" class="public_id_link">
                <?php 
    echo "<div class='public_id'>" . $photo["public_id"] . "</div>";
    echo cl_image_tag($photo["public_id"], array_merge($thumbs_params, array("crop" => "fill")));
Example #19
0
    // send response header for JSON content type
    $app->response()->header('Content-Type', 'application/json');
    // return JSON-encoded response body with query results
    echo json_encode(R::exportAll($subsegmentos));
});
$app->get('/subsegmentos/justnames/:segmentid', function ($segmentid) use($app) {
    $rows = R::getAll("select s.id, s.segmento_id, s.nombre from subsegmento s where s.segmento_id=?", array($segmentid));
    $subsegmentos = R::convertToBeans('subsegmentos', $rows);
    // send response header for JSON content type
    $app->response()->header('Content-Type', 'application/json');
    // return JSON-encoded response body with query results
    echo json_encode(R::exportAll($subsegmentos));
});
$app->get('/subsegmentos/total/', function () use($app) {
    $total = R::dispense('total');
    $total->total = R::count('subsegmento');
    $app->response()->header('Content-Type: text/html; charset=utf-8');
    $app->response()->header('Content-Type', 'application/json');
    //TODO: Buscar un modo elegante de hacer lo siguiente:
    echo json_encode(R::exportAll($total)[0]);
});
$app->get('/subsegmentos/page/:pagenumber', function ($pagenumber) use($app) {
    // query database for all segmentos
    $subsegmentos = R::findAll('subsegmento', 'ORDER BY nombre LIMIT ?,8', array($pagenumber * 8 - 8));
    // send response header for JSON content type
    $app->response()->header('Content-Type: text/html; charset=utf-8');
    $app->response()->header('Content-Type', 'application/json');
    foreach ($subsegmentos as $subsegmento) {
        $subsegmento->segmento = $subsegmento->segmento;
    }
    // return JSON-encoded response body with query results
 public function countBlockList()
 {
     $blocks = R::count('blocks');
     return $blocks;
 }
        $nodeNames[] = $node;
    }
}
// Get each nodes properties
foreach ($nodeNames as $nodeName) {
    $queryString = "MATCH (n:`" . $nodeName . "`) return count(n) as count";
    $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
    $result = $query->getResultSet();
    $count = 0;
    foreach ($result as $row) {
        $count = $row["count"];
    }
    echo "Total Count for {$nodeName}: {$count} \n";
    $mysql_count = 0;
    try {
        $mysql_count = R::count($nodeName);
    } catch (Exception $e) {
        echo "Records do not exist for {$nodeName} in MySQL\n";
    }
    if ($mysql_count == $count) {
        echo "Already did {$nodeName}, continuing \n";
        continue;
    }
    $storedRecords = 0;
    $page = 0;
    //$count = ($count < 25) ? $count : 25;
    while ($storedRecords < $count) {
        $queryString = "MATCH (n:`" . $nodeName . "`) RETURN n skip " . 200 * $page . " limit 200";
        $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
        $result = $query->getResultSet();
        foreach ($result as $row) {
Example #22
0
 protected function getLatestComic()
 {
     return \R::load('comic', \R::count('comic'));
 }
Example #23
0
 /**
  * Handle AJAX operations
  *
  * @param object    $context    The context object for the site
  *
  * @return void
  */
 public function handle($context)
 {
     if (($lg = $context->getpar('login', '')) != '') {
         # this is a parsley generated username check call
         if (R::count('user', 'login=?', array($lg)) > 0) {
             return (new Web())->notfound();
             // error if it exists....
         }
     } else {
         $op = $context->mustpostpar('op');
         if (isset(self::$ops[$op])) {
             # a valid operation
             if (self::$ops[$op][0]) {
                 # this operation requires a logged in user
                 $context->mustbeuser();
             }
             if (self::$ops[$op][1]) {
                 # this operation needs admin privileges
                 $context->mustbeadmin();
             }
             if (self::$ops[$op][2]) {
                 # this operation needs developer privileges
                 $context->mustbedeveloper();
             }
             $this->{$op}($context);
         } else {
             # return a 400
             (new Web())->bad();
         }
     }
     exit;
 }
Example #24
0
    // On renvoie les données des vins récupérés
    return json_encode(["tabWines" => $tabWinesForJSON, "nbWines" => $nbWines]);
});
// Filtrer les vins selon le pays choisi
$app->get('/filtre/{pays}', function ($request, $response, $args) use($twig) {
    // Récupération du pays choisi
    $pays = $args['pays'];
    // Modification des variables de session
    $_SESSION['pays'] = $pays;
    $_SESSION['typeTri'] = null;
    // Récupération des vins appartenant au pays choisi
    $tabWines = R::find('wine', 'country = :pays LIMIT 0, 6', [':pays' => $pays]);
    // Transformation des données en un tableau permettant de former du JSON par la suite
    $tabWinesForJSON = transformDataForJSON($tabWines);
    // Récupération dans la DB du nombre de vins appartenant au pays choisi
    $nbWines = R::count('wine', 'country = :pays', [':pays' => $pays]);
    // On renvoie les données des vins récupérés
    return json_encode(["tabWines" => $tabWinesForJSON, "nbWines" => $nbWines]);
});
// Afficher les vins triés par pays
$app->get('/liste', function ($request, $response) use($twig) {
    // Récupération de tous les vins dans la DB
    $tabWines = R::findAll('wine');
    // Récupération des différents pays dans un tableau
    $tabCountries = recupPays();
    // On affiche le template "liste.twig.html"
    echo $twig->render('liste.twig.html', ["tabWines" => $tabWines, "tabCountries" => $tabCountries]);
});
/********************************/
/*   Définition des fonctions   */
/********************************/
Example #25
0
 public static function getAllCount()
 {
     return R::count('user');
 }
 public function countPageList()
 {
     $pages = R::count('pages');
     return $pages;
 }
Example #27
0
 asrt(getList(R::unrelated($accountant, "person"), "job"), "");
 asrt(getList(R::unrelated($painter, "person"), "job"), "developer,salesman");
 asrt(getList(R::unrelated($salesman, "person"), "job"), "painter");
 asrt(getList(R::unrelated($developer, "person"), "job"), "painter");
 testpack("Test count and wipe");
 $page = R::dispense("page");
 $page->name = "ABC";
 R::store($page);
 $n1 = R::count("page");
 $page = R::dispense("page");
 $page->name = "DEF";
 R::store($page);
 $n2 = R::count("page");
 asrt($n1 + 1, $n2);
 R::wipe("page");
 asrt(R::count("page"), 0);
 asrt(R::$redbean->count("page"), 0);
 function setget($val)
 {
     global $pdo;
     $bean = R::dispense("page");
     $_tables = R::$writer->getTables();
     if (in_array("page", $_tables)) {
         $pdo->Execute("DROP TABLE page");
     }
     $bean->prop = $val;
     $id = R::store($bean);
     $bean = R::load("page", $id);
     asrt(is_string($bean->prop) || is_null($bean->prop), true);
     return $bean->prop;
 }
 public function countJobApplications()
 {
     $count = R::count('applications', ' job_id=:job_id ', array(':job_id' => $this->_id));
     return $count;
 }
Example #29
0
 /**
  * @return int
  */
 public function count($userid = NULL)
 {
     $count = R::count($this->tbname);
     return $count;
 }
 public function countSubscriptions()
 {
     $count = R::count('subscriptions');
     return $count;
 }