Ejemplo n.º 1
0
 /**
  * Constructs an object instance
  *
  * @return  void
  * @since   2.0.0
  **/
 public function __construct()
 {
     $r = new \ReflectionClass($this);
     // Set model name
     $this->modelName = $r->getShortName();
     $this->modelNamespace = $r->getNamespaceName();
     // If table name isn't explicitly set, build it
     $namespace = !$this->namespace ? '' : $this->namespace . '_';
     $plural = \Hubzero\Utility\Inflector::pluralize(strtolower($this->getModelName()));
     $this->table = $this->table ?: '#__' . $namespace . $plural;
     // Set up connection and query object
     $this->newQuery();
     // Store methods for later
     //
     // Here we store the methods per class name. This allows for quicker
     // lookup and less memory usage when dealing with multiple classes
     // of the same type (i.e., a listing of records).
     $key = $r->getName();
     if (!isset(self::$classMethods[$key])) {
         self::$classMethods[$key] = get_class_methods($this);
         $this->methods = self::$classMethods[$key];
     }
     $this->methods = self::$classMethods[$key];
     // Run extra setup. This is so subclasses don't have to overwrite
     // the constructor and then call parent::__construct().
     // They can instead just add a setup() method.
     $this->setup();
 }
Ejemplo n.º 2
0
 /**
  * Scan template folder for files to iterate through
  *
  * @param   string  $path  Path of folder to scan
  * @return  void
  **/
 private function scanFolder($path)
 {
     $files = array_diff(scandir($path), array('.', '..', '.DS_Store'));
     if ($files && count($files) > 0) {
         foreach ($files as $file) {
             if (is_file($path . DS . $file)) {
                 $contents = file_get_contents($path . DS . $file);
                 $contents = $this->doReplacements($contents);
                 $this->putContents($path . DS . $file, $contents);
             } else {
                 // See if we need to do var replacement in directory name
                 if (preg_match("/%=([[:alpha:]_]*)(\\+[[:alpha:]]+)?=%/", $path . DS . $file, $matches) && isset($this->replacements[$matches[1]])) {
                     $newfile = str_replace($matches[0], $this->replacements[$matches[1]], $file);
                     if (isset($matches[2])) {
                         $modifier = substr($matches[2], 1);
                         switch ($modifier) {
                             // Upper case word
                             case 'uc':
                                 $value = strtoupper($v);
                                 break;
                                 // Upper case first character
                             // Upper case first character
                             case 'ucf':
                                 $newfile = ucfirst($newfile);
                                 break;
                                 // Upper case first character and plural
                             // Upper case first character and plural
                             case 'ucfp':
                                 $newfile = ucfirst(Inflector::pluralize($newfile));
                                 break;
                                 // Plural form
                             // Plural form
                             case 'p':
                                 $newfile = Inflector::pluralize($newfile);
                                 break;
                         }
                     }
                     rename($path . DS . $file, $path . DS . $newfile);
                     $file = $newfile;
                 }
                 $this->scanFolder($path . DS . $file);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public function getHubTypesTask()
 {
     $config = Component::params('com_search');
     $query = new \Hubzero\Search\Query($config);
     $terms = Request::getVar('terms', '*:*');
     $type = Request::getVar('type', '');
     $limit = 0;
     $start = 0;
     $types = Event::trigger('search.onGetTypes');
     foreach ($types as $type) {
         $query->addFacet($type, array('hubtype', '=', $type));
     }
     // Administrators can see all records
     $isAdmin = User::authorise('core.admin', 'com_users');
     if ($isAdmin) {
         $query = $query->query($terms)->limit($limit)->start($start);
     } else {
         $query = $query->query($terms)->limit($limit)->start($start)->restrictAccess();
     }
     $query = $query->run();
     $facets = array();
     $total = 0;
     foreach ($types as $type) {
         $name = $type;
         if (strpos($type, "-") !== false) {
             $name = substr($type, 0, strpos($type, "-"));
         }
         $count = $query->getFacetCount($type);
         $total += $count;
         $name = ucfirst(\Hubzero\Utility\Inflector::pluralize($name));
         array_push($facets, array('type' => $type, 'name' => $name, 'count' => $count));
     }
     $response = new stdClass();
     $response->results = json_encode($facets);
     $response->total = $total;
     $response->success = true;
     $this->send($response);
 }
Ejemplo n.º 4
0
 private function getCategories($type, $terms, $limit, $start)
 {
     $config = Component::params('com_search');
     $query = new \Hubzero\Search\Query($config);
     $types = Event::trigger('search.onGetTypes');
     foreach ($types as $type) {
         $query->addFacet($type, array('hubtype', '=', $type));
     }
     // Administrators can see all records
     $isAdmin = User::authorise('core.admin', 'com_users');
     if ($isAdmin) {
         $query = $query->query($terms)->limit($limit)->start($start)->restrictAccess();
     } else {
         $query = $query->query($terms)->limit($limit)->start($start)->restrictAccess();
     }
     $query = $query->run();
     $facets = array();
     $total = 0;
     foreach ($types as $type) {
         $name = $type;
         if (strpos($type, "-") !== false) {
             $name = substr($type, 0, strpos($type, "-"));
         }
         $count = $query->getFacetCount($type);
         $total += $count;
         $name = ucfirst(\Hubzero\Utility\Inflector::pluralize($name));
         array_push($facets, array('type' => $type, 'name' => $name, 'count' => $count));
     }
     return array('facets' => $facets, 'total' => $total);
 }
Ejemplo n.º 5
0
 /**
  * Constructs an object instance
  *
  * @return  void
  * @since   2.0.0
  **/
 public function __construct()
 {
     // Set model name
     $this->modelName = with(new \ReflectionClass($this))->getShortName();
     // If table name isn't explicitly set, build it
     $namespace = !$this->namespace ? '' : $this->namespace . '_';
     $plural = \Hubzero\Utility\Inflector::pluralize(strtolower($this->getModelName()));
     $this->table = $this->table ?: '#__' . $namespace . $plural;
     // Set up connection and query object
     $this->newQuery();
     // Store methods for later
     $this->methods = get_class_methods($this);
     // Run extra setup. This is so subclasses don't have to overwrite
     // the constructor and then call parent::__construct().
     // They can instead just add a setup() method.
     $this->setup();
 }