public function getBrands() { $brands = array(); $pdo = DataSource::load(); $data = array(); $statement = 'SELECT brand.*, category.name AS categoryName FROM brand LEFT JOIN category ON brand.category = category.id WHERE deleted = 0'; if (!empty($this->categoryId)) { $statement .= ' AND category = :category'; $data['category'] = $this->categoryId; } if ($this->status !== null) { $statement .= ' AND status = :status'; $data['status'] = $this->status; } if (!empty($this->orderBy)) { $statement .= ' ORDER BY ' . $this->orderBy; } if (!empty($this->limit)) { $statement .= ' LIMIT ' . (int) $this->limit; } if (!empty($this->offset)) { $statement .= ' OFFSET ' . (int) $this->offset; } $preparedStatement = $pdo->prepare($statement); $preparedStatement->execute($data); $brandsData = $preparedStatement->fetchAll(); foreach ($brandsData as $brandData) { $brand = new Brand(); $brand->setProperties($brandData); $brands[] = $brand; } return $brands; }
public function create() { $pdo = DataSource::load(); $statement = 'INSERT INTO click (brand, creation_time) VALUES (:brand, :creation_time)'; $data = array(); $data['brand'] = $this->brand; $data['creation_time'] = date('Y-m-d H:i:s'); $preparedStatement = $pdo->prepare($statement); return $preparedStatement->execute($data); }
public static function getLatest($limit) { $limit = (int) $limit; $logs = array(); $pdo = DataSource::load(); $statement = 'SELECT log.*, brand.name AS brandName, brand.brandColor AS brandColor, brand.slug AS brandSlug FROM log LEFT JOIN brand ON log.brand = brand.id ORDER BY log.date DESC LIMIT :limit'; $preparedStatement = $pdo->prepare($statement); $preparedStatement->bindParam('limit', $limit, PDO::PARAM_INT); $preparedStatement->execute(); $logsData = $preparedStatement->fetchAll(); foreach ($logsData as $logData) { $log = new self(); $log->setProperties($logData); $logs[] = $log; } return $logs; }
public function addLoader($datasourceType, DataSource $datasource) { foreach ($this->config as $maphperName => $sourceConfig) { if ($sourceConfig['type'] != $datasourceType) { continue; } $this->dice->addRule('$Maphper_Source_' . $maphperName, $datasource->load($sourceConfig)); $rules = []; if (isset($sourceConfig['relations'])) { foreach ($sourceConfig['relations'] as $relationConfig) { if ($relationConfig['type'] === 'ManyMany') { continue; } $relation = []; $relation['instanceOf'] = 'Maphper\\Relation\\' . ucwords($relationConfig['type']); $relation['substitutions'] = ['Maphper\\Maphper' => ['instance' => '$Maphper_' . $relationConfig['to']]]; $relation['constructParams'] = [$relationConfig['localKey'], $relationConfig['foreignKey']]; $name = '$Maphper_Relation_' . $maphperName . '_' . $relationConfig['name']; $rules[$relationConfig['name']] = $name; $this->dice->addRule($name, $relation); } } $mapper = []; $mapper['instanceOf'] = 'Maphper\\Maphper'; $mapper['substitutions'] = ['Maphper\\DataSource' => ['instance' => '$Maphper_Source_' . $maphperName]]; //$mapper['shared'] = true; $mapper['call'] = []; foreach ($rules as $name => $rule) { $mapper['call'][] = ['addRelation', [$name, ['instance' => $rule]]]; } // If `resultCLass` option is set then automatically use Dice to resolve dependencies if (isset($sourceConfig['resultClass'])) { $mapper['constructParams'] = [['resultClass' => function () use($sourceConfig) { return $this->dice->create($sourceConfig['resultClass']); }]]; } $this->dice->addRule('$Maphper_' . $maphperName, $mapper); } }
public function users() { $pdo = DataSource::load(); $statement = 'SELECT id, firstName, lastName, login FROM User'; $preparedStatement = $pdo->prepare($statement); $preparedStatement->execute(); $usersData = $preparedStatement->fetchAll(); $this->set('usersData', $usersData); $this->render('administration/users'); }
public function __viewIndex() { // This is the 'correct' way to append a string containing an entity $title = $this->createElement('title'); $title->appendChild($this->createTextNode(__('Symphony') . ' ')); $title->appendChild($this->createEntityReference('ndash')); $title->appendChild($this->createTextNode(' ' . __('Data Sources'))); $this->insertNodeIntoHead($title); $this->appendSubheading(__('Data Sources'), Widget::Anchor(__('Create New'), Administration::instance()->getCurrentPageURL() . '/new/', array('title' => __('Create a new data source'), 'class' => 'create button'))); $datasources = new DatasourceIterator(); $dsTableHead = array(array(__('Name'), 'col'), array(__('Source'), 'col'), array(__('Type'), 'col'), array(__('Used By'), 'col')); $dsTableBody = array(); $colspan = count($dsTableHead); if ($datasources->length() <= 0) { $dsTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), array('class' => 'inactive', 'colspan' => $colspan))), array('class' => 'odd'))); } else { // Load Views so we can determine what Datasources are attached if (!self::$_loaded_views) { foreach (new ViewIterator() as $view) { self::$_loaded_views[$view->guid] = array('title' => $view->title, 'handle' => $view->handle, 'data-sources' => $view->{'data-sources'}); } } foreach ($datasources as $pathname) { $ds = DataSource::load($pathname); $view_mode = $ds->allowEditorToParse() == true ? 'edit' : 'info'; $handle = DataSource::getHandleFromFilename($pathname); // Name $col_name = Widget::TableData(Widget::Anchor($ds->about()->name, ADMIN_URL . "/blueprints/datasources/{$view_mode}/{$handle}/", array('title' => $ds->parameters()->pathname))); $col_name->appendChild(Widget::Input("items[{$handle}]", NULL, 'checkbox')); // Source try { $col_source = $ds->prepareSourceColumnValue(); } catch (Exception $e) { $col_source = Widget::TableData(__('None'), array('class' => 'inactive')); } // Used By $fragment_views = $this->createDocumentFragment(); foreach (self::$_loaded_views as $view) { if (is_array($view['data-sources']) && in_array($handle, $view['data-sources'])) { if ($fragment_views->hasChildNodes()) { $fragment_views->appendChild(new DOMText(', ')); } $fragment_views->appendChild(Widget::Anchor($view['title'], ADMIN_URL . "/blueprints/views/edit/{$view['handle']}/")); } } if (!$fragment_views->hasChildNodes()) { $col_views = Widget::TableData(__('None'), array('class' => 'inactive')); } else { $col_views = Widget::TableData($fragment_views); } // Type if (is_null($ds->getType())) { $col_type = Widget::TableData(__('Unknown'), array('class' => 'inactive')); } else { $col_type = Widget::TableData($this->types[$ds->getType()]->name); } $dsTableBody[] = Widget::TableRow(array($col_name, $col_source, $col_type, $col_views)); } } $table = Widget::Table(Widget::TableHead($dsTableHead), NULL, Widget::TableBody($dsTableBody), array('id' => 'datasources-list')); $this->Form->appendChild($table); $tableActions = $this->createElement('div'); $tableActions->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'))); $tableActions->appendChild(Widget::Select('with-selected', $options)); $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit')); $this->Form->appendChild($tableActions); }
public function updateClicksCount() { if ($this->hasId()) { $pdo = DataSource::load(); $statement = 'UPDATE brand SET clicksCount = (SELECT COUNT(*) FROM click WHERE click.brand = brand.id) WHERE id = :brandId;'; $data = array(); $data['brandId'] = (int) $this->getId(); $preparedStatement = $pdo->prepare($statement); return $preparedStatement->execute($data); } return false; }
public static function delete(Section $section) { /* TODO: Upon deletion it should update all data-sources/events attached to it. Either by deleting them, or making section $unknown. I think deletion is best because if the section is renamed, the rename() function will take care of moving the dependancies, so there should be no data-sources/events to delete anyway. However, if you delete page accidentally (hm, even though you clicked confirm), do you really want your data-sources/events to just be deleted? Verdict? */ // Remove fields: foreach ($section->fields as $field) { $field->remove(); } // Remove sync data: Symphony::Database()->delete('tbl_sections_sync', array($section->guid), '`section` = "%s"'); // Remove entry metadata Symphony::Database()->delete('tbl_entries', array($section->handle), '`section` = "%s"'); if (General::deleteFile(SECTIONS . '/' . $section->handle . '.xml')) { // Cleanup Datasources foreach (new DataSourceIterator() as $datasource) { $ds = DataSource::load($datasource); if ($ds->parameters()->section == $section->handle) { DataSource::delete($ds); } } // Cleanup Events foreach (new EventIterator() as $event) { $ev = Event::load($event); if ($ev->parameters()->source == $section->handle) { Event::delete($ev); } } } }
?> " required autofocus> </div> <div class="form-group"> <label for="aemenudesc">Description</label> <textarea class="form-control" name="description" rows="5" id="aemenudesc" maxlength="1000"><?php echo isset($menudesc) ? $menudesc : ''; ?> </textarea> </div> <div class="form-group"> <label for="aemenusource">Data Source</label> <select class="form-control" id="aemenusource" name="menusource"> <option></option> <?php $datasources = DataSource::load(); foreach ($datasources as $datasource => $datasourcename) { echo ' <option value="' . $datasource . '" ' . ($datasource == $menusource ? 'selected' : '') . '>' . $datasourcename . '</option>'; } ?> </select> </div> <div class="pull-right"> <?php if ($pageaction == 'add') { $buttonvalue = 'addmenu'; $buttonlabel = 'Add Menu'; } else { $buttonvalue = 'editmenu'; $buttonlabel = 'Save Changes'; }
public function delete() { $pdo = DataSource::load(); if ($this->hasId()) { $statement = 'DELETE FROM user WHERE id = :id'; $preparedStatement = $pdo->prepare($statement); $data['id'] = $this->id; if ($preparedStatement->execute($data)) { $this->id = 0; return true; } } return false; }
public static function getAll() { $categories = array(); $pdo = DataSource::load(); $statement = 'SELECT * FROM category'; $preparedStatement = $pdo->prepare($statement); $preparedStatement->execute(); $categoriesData = $preparedStatement->fetchAll(); foreach ($categoriesData as $categoryData) { $category = new self(); $category->setProperties($categoryData); $categories[] = $category; } return $categories; }
public function __form() { $layout = new Layout(); $left = $layout->createColumn(Layout::LARGE); $center = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::LARGE); $existing = null; $fields = array(); // Verify view exists: if ($this->_context[0] == 'edit') { if (!isset($this->_context[1]) || strlen(trim($this->_context[1])) == 0) { redirect(ADMIN_URL . '/blueprints/views/'); } $context = $this->_context; array_shift($context); $view_pathname = implode('/', $context); $existing = self::__loadExistingView($view_pathname); } // Status message: $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag']) && !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('View updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/views/new/', ADMIN_URL . '/blueprints/views/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('View created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/views/new/', ADMIN_URL . '/blueprints/views/')), AlertStack::SUCCESS); break; } } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = (array) $existing->about(); // Flatten the types array: $fields['types'] = (isset($fields['types']) and is_array($fields['types'])) ? implode(', ', $fields['types']) : null; // Flatten the url-parameters array: $fields['url-parameters'] = (isset($fields['url-parameters']) and is_array($fields['url-parameters'])) ? implode('/', $fields['url-parameters']) : null; $fields['parent'] = $existing->parent() instanceof View ? $existing->parent()->path : NULL; $fields['handle'] = $existing->handle; } $title = null; if (isset($fields['title'])) { $title = $fields['title']; } if (strlen(trim($title)) == 0) { $title = $existing instanceof View ? $existing->title : 'New View'; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Views'), $title))); if ($existing instanceof View) { $template_name = $fields['handle']; $this->appendSubheading(__($title ? $title : __('New View'))); $viewoptions = array(__('Configuration') => Administration::instance()->getCurrentPageURL(), __('Template') => sprintf('%s/blueprints/views/template/%s/', ADMIN_URL, $view_pathname)); $this->appendViewOptions($viewoptions); } else { $this->appendSubheading($title ? $title : __('Untitled')); } // Fieldset ----------------------------------------------------------- $fieldset = Widget::Fieldset(__('Essentials')); // Title -------------------------------------------------------------- $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', isset($fields['title']) ? $fields['title'] : null)); if (isset($this->errors->title)) { $label = Widget::wrapFormElementWithError($label, $this->errors->title); } $fieldset->appendChild($label); // Type --------------------------------------------------------------- $container = $this->createElement('div'); $label = Widget::Label(__('View Type')); $label->appendChild(Widget::Input('fields[types]', isset($fields['types']) ? $fields['types'] : null)); if (isset($this->errors->types)) { $label = Widget::wrapFormElementWithError($label, $this->errors->types); } $tags = $this->createElement('ul'); $tags->setAttribute('class', 'tags'); foreach (self::__fetchAvailableViewTypes() as $t) { $tags->appendChild($this->createElement('li', $t)); } $container->appendChild($label); $container->appendChild($tags); $fieldset->appendChild($container); $left->appendChild($fieldset); // Fieldset ----------------------------------------------------------- $fieldset = Widget::Fieldset(__('URL Settings')); // Parent ------------------------------------------------------------- $label = Widget::Label(__('Parent')); $options = array(array(NULL, false, '/')); foreach (new ViewIterator() as $v) { // Make sure the current view cannot be set as either a child of itself, or a child of // another view that is already at child of the current view. if (isset($existing) && $existing instanceof View && ($v->isChildOf($existing) || $v->guid == $existing->guid)) { continue; } $options[] = array($v->path, isset($fields['parent']) and $fields['parent'] == $v->path, "/{$v->path}"); } $label->appendChild(Widget::Select('fields[parent]', $options)); $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $label = Widget::Label(__('Handle')); $label->appendChild(Widget::Input('fields[handle]', isset($fields['handle']) ? $fields['handle'] : null)); if (isset($this->errors->handle)) { $label = Widget::wrapFormElementWithError($label, $this->errors->handle); } $fieldset->appendChild($label); // Parameters --------------------------------------------------------- $label = Widget::Label(__('Parameters')); $label->appendChild(Widget::Input('fields[url-parameters]', isset($fields['url-parameters']) ? $fields['url-parameters'] : null)); $fieldset->appendChild($label); $center->appendChild($fieldset); // Fieldset ----------------------------------------------------------- $fieldset = Widget::Fieldset(__('Resources')); $label = Widget::Label(__('Events')); $options = array(); foreach (new EventIterator() as $pathname) { $event = Event::load($pathname); $handle = Event::getHandleFromFilename($pathname); $options[] = array($handle, in_array($handle, (array) $fields['events']), $event->about()->name); } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $options = array(); foreach (new DataSourceIterator() as $pathname) { $ds = DataSource::load($pathname); $handle = DataSource::getHandleFromFilename($pathname); $options[] = array($handle, in_array($handle, (array) $fields['data-sources']), $ds->about()->name); } $label->appendChild(Widget::Select('fields[data-sources][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $right->appendChild($fieldset); $layout->appendTo($this->Form); // Controls ----------------------------------------------------------- $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create View'), array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this view')))); } $this->Form->appendChild($div); }