Ejemplo n.º 1
0
 public function fillModel(Model $model)
 {
     parent::fillModel($model);
     if (!$this->submitted() && $model) {
         $this->allowComments->checked($model->hasFlag(BlogPostFlag::ALLOW_COMMENTS));
         $this->sticky->checked($model->hasFlag(BlogPostFlag::STICKY));
         // tags
         if (!empty($model->Tags)) {
             $tags = new IndexedArray();
             foreach ($model->Tags as $Tag) {
                 $tags[] = $Tag->get('name');
             }
             $this->tags->value($tags->implode(' '));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  *	Return possible template names that can be used by the nodes
  *	for rendering by listing all files from the node view directory
  *	
  * 	@return array(string)
  */
 public function templateNames()
 {
     $templateNames = new IndexedArray();
     // get correct template directory from appcontroller’s theme
     $r = get_class_vars('AppController');
     if (empty($r['theme'])) {
         $templateDir = VIEW_DIR . 'node/';
     } else {
         $templateDir = VIEW_DIR . 'theme/' . $r['theme'] . '/node/';
     }
     // list files
     $dir = new Dir($templateDir);
     foreach ($dir->read('@\\.php$@') as $file) {
         if (!$file->isFile()) {
             continue;
         }
         // ignore directories
         if (in_array($file->basename(false), array())) {
             continue;
         }
         // ignore files?
         $templateNames[$file->basename(false)] = $file->basename(false);
     }
     return $templateNames->toArray();
 }
Ejemplo n.º 3
0
 public function similarEntries()
 {
     if (!$this->exists() || $this->Tags->count() == 0) {
         return false;
     }
     $queryFile = dirname(__FILE__) . '/../../console/sql/similarBlogPosts.sql';
     if (!file_exists($queryFile)) {
         return false;
     }
     $tmp = new IndexedArray();
     foreach ($this->Tags as $Tag) {
         $tmp[] = 'Tag.name = ' . DBQuery::quote($Tag->get('name'));
     }
     $tagConditions = $tmp->implode(' OR ');
     $query = sprintf(file_get_contents($queryFile), $tagConditions, $this->id);
     return $this->query($query);
 }