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(' ')); } } }
/** * 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(); }
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); }