v7‰PNG
IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ±üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0AºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT
DataSource/Array.php 0000644 00000004663 15210162073 0010373 0 ustar 00 array[$this->getHash($a)] = $a;
}
public function getFoundRows()
{
return count($this->array);
}
public function selectPageRecords($page, $itemCountPerPage)
{
return array_map(function($a) {return (object)$a;},
array_slice($this->array, $page*$itemCountPerPage, $itemCountPerPage));
}
public function setOrder($fieldNameOrRaw, $desc=null)
{
switch (is_null($desc)) {
case true :
if ($fieldNameOrRaw) {
$this->_setOrderRaw($fieldNameOrRaw);
}
break;
case false :
$this->_setOrder($fieldNameOrRaw, $desc);
break;
}
}
protected function _setOrder($fieldName, $desc)
{
uasort($this->array, function($a, $b) use ($fieldName, $desc) {
return ($desc ? -1 : 1) * strcmp($a->{$fieldName}, $b->{$fieldName});
});
}
protected function _setOrderRaw($raw)
{
//@todo Parse Raw Order and use _setOrder
}
//this method is only for use in Am_Grid_Filter
public function _friendGetArray() {
return $this->array;
}
//this method is only for use in Am_Grid_Filter
public function _friendSetArray($records)
{
return $this->array = $records;
}
public function getDataSourceQuery()
{
throw new Am_Exception_NotImplemented(__METHOD__);
}
public function getIdForRecord($record)
{
return $this->getHash($record);
}
protected function getHash($record)
{
return md5(serialize(get_object_vars($record)));
}
public function createRecord()
{
return new stdClass;
}
public function deleteRecord($id, $record)
{
unset($this->array[$id]);
}
public function getRecord($id)
{
return (object)$this->array[$id];
}
public function insertRecord($record, $valuesFromForm)
{
throw new Am_Exception_NotImplemented(__METHOD__);
}
public function updateRecord($record, $valuesFromForm)
{
throw new Am_Exception_NotImplemented(__METHOD__);
}
} DataSource/Interface/Editable.php 0000644 00000000712 15210162073 0012715 0 ustar 00 di = $table->getDi();
$this->config_key = $table->getCustomFieldsConfigKey();
$this->table = $table->getName(true);
$this->pk = $table->getKeyField();
}
public function insertRecord($record, $valuesFromForm)
{
$fields = $this->di->config->get($this->config_key, array());
$recordForStore = $this->getRecordForStore($valuesFromForm);
$recordForStore['name'] = $valuesFromForm['name'];
$fields[] = $recordForStore;
Am_Config::saveValue($this->config_key, $fields);
$this->di->config->set($this->config_key, $fields);
if ($recordForStore['sql'])
$this->addSqlField($recordForStore['name'], $recordForStore['additional_fields']['sql_type']);
}
public function updateRecord($record, $valuesFromForm)
{
$fields = $this->di->config->get($this->config_key);
foreach ($fields as $k => $v) {
if ($v['name'] == $record->name) {
$recordForStore = $this->getRecordForStore($valuesFromForm);
$recordForStore['name'] = $record->name;
$fields[$k] = $recordForStore;
}
}
Am_Config::saveValue($this->config_key, $fields);
$this->di->config->set($this->config_key, $fields);
if ($record->sql != $recordForStore['sql']) {
if ($recordForStore['sql']) {
$this->convertFieldToSql($record->name, $recordForStore['additional_fields']['sql_type']);
} else {
$this->convertFieldFromSql($record->name);
}
} elseif ($recordForStore['sql'] &&
$record->sql_type != $recordForStore['additional_fields']['sql_type']) {
$this->changeSqlField($record->name, $recordForStore['additional_fields']['sql_type']);
}
}
public function deleteRecord($id, $record)
{
$record = $this->getRecord($id);
if (in_array($record->type, array('upload', 'multi_upload'))) {
if ($record->sql) {
$col = $this->di->db->selectCol("SELECT ?# FROM ?_{$this->table}
WHERE ?# IS NOT NULL AND ?#<>'' AND ?#<>'a:0:{}'",
$record->name, $record->name,
$record->name, $record->name);
} else {
$col = $this->di->db->selectCol("SELECT `blob` FROM ?_data
WHERE `table`=? AND `key`=? AND `blob` IS NOT NULL AND `blob`<>'' AND `blob`<>'a:0:{}'",
$this->table, $record->name);
}
foreach ($col as $f) {
$files = ($f[0] == 'a') ? unserialize($f) : array($f);
foreach ($files as $id) {
$file = $this->di->uploadTable->load($id, false);
if ($file)
$file->delete();
}
}
}
$fields = $this->di->config->get($this->config_key);
foreach ($fields as $k => $v) {
if ($v['name'] == $record->name)
unset($fields[$k]);
}
Am_Config::saveValue($this->config_key, $fields);
$this->di->config->set($this->config_key, $fields);
if ($record->sql) {
$this->dropSqlField($record->name);
} else {
$this->dropDataField($record->name);
}
}
public function createRecord()
{
$o = new stdClass;
$o->name = null;
$o->options = array();
$o->default = null;
return $o;
}
protected function getRecordForStore($values)
{
if (($values['type'] == 'text') ||
($values['type'] == 'textarea') ||
($values['type'] == 'date')) {
$default = $values['default'];
} else {
$default = array_intersect($values['values']['default'], array_keys($values['values']['options']));
if ($values['type'] == 'radio')
$default = $default[0];
}
if ($values['type'] == 'select')
$values['size'] = 1;
$recordForStore['title'] = $values['title'];
$recordForStore['description'] = $values['description'];
$recordForStore['sql'] = $values['sql'];
$recordForStore['type'] = $values['type'];
$recordForStore['validate_func'] = $values['validate_func'];
$recordForStore['additional_fields'] = array(
'sql' => intval($values['sql']),
'sql_type' => $values['sql_type'],
'size' => $values['size'],
'default' => $default,
'options' => $values['values']['options'],
'cols' => $values['cols'],
'rows' => $values['rows'],
);
$default_fields = array(
'type' => 1,
'default' => 1,
'values' => 1,
'size' => 1,
'title' => 1,
'description' => 1,
'validate_func' => 1,
'sql' => 1,
'sql_type' => 1,
'cols' => 1,
'rows' => 1);
foreach ($values as $k => $v) {
if (!isset($default_fields[$k]) && $k[0] != '_') {
$recordForStore['additional_fields'][$k] = $v;
}
}
return $recordForStore;
}
protected function addSqlField($name, $type)
{
$this->di->db->query("ALTER TABLE ?_{$this->table} ADD ?# $type", $name);
}
protected function dropSqlField($name)
{
$this->di->db->query("ALTER TABLE ?_{$this->table} DROP ?#", $name);
}
protected function dropDataField($name)
{
$this->di->db->query("DELETE FROM ?_data WHERE `table`=? AND `key`=?",
$this->table, $name);
}
protected function changeSqlField($name, $type)
{
$this->di->db->query("ALTER TABLE ?_{$this->table} CHANGE ?# ?# $type", $name, $name);
}
protected function convertFieldToSql($name, $type)
{
$this->addSqlField($name, $type);
$this->di->db->query("UPDATE ?_{$this->table} t SET ?# = (SELECT
CASE `type`
WHEN ? THEN `blob`
WHEN ? THEN `blob`
ELSE `value`
END
FROM ?_data
WHERE `table`='{$this->table}'
AND `key`= ?
AND `id`=t.{$this->pk} LIMIT 1)",
$name,
Am_DataFieldStorage::TYPE_BLOB,
Am_DataFieldStorage::TYPE_SERIALIZED,
$name);
$this->dropDataField($name);
}
protected function convertFieldFromSql($name)
{
$this->di->db->query("INSERT INTO ?_data (`table`, `key`, `id`, `type`, `value`, `blob`) "
. "(SELECT '{$this->table}', ?, {$this->pk}, "
. "IF(SUBSTRING(?#,1,2) = 'a:', 1, 0), "
. "IF(SUBSTRING(?#,1,2) = 'a:', NULL, ?#), "
. "IF(SUBSTRING(?#,1,2) = 'a:', ?#, NULL) "
. "FROM ?_{$this->table} WHERE ?# IS NOT NULL)",
$name, $name, $name, $name, $name, $name, $name);
$this->dropSqlField($name);
}
public function getDataSourceQuery()
{
return null;
}
} Editable/Content.php 0000644 00000015202 15210162073 0010375 0 ustar 00 joinSort($this->createAdapter());
parent::__construct('_'.$this->getContentGridId(), $this->getTitle(), $adapter, $request, $view);
$this->setEventId('gridContent' . ucfirst($this->getContentGridId()));
$this->addCallback(self::CB_AFTER_INSERT, array($this, 'afterInsert'));
$this->addCallback(self::CB_AFTER_UPDATE, array($this, 'afterInsert'));
$this->addCallback(self::CB_VALUES_TO_FORM, array($this, '_valuesToForm'));
foreach ($this->getActions() as $action)
$action->setTarget('_top');
}
/**
* Add join to resource_access_sort and sort field
* to be present in the result
*/
protected function joinSort(Am_Query $q)
{
$q->getTable()->addDefaultSort($q);
return $q;
}
public function getTitle()
{
return ___(ucfirst($this->getContentGridId()));
}
public function getContentGridId()
{
$id = preg_split('#[\\\\_]#', get_class($this));
$id = strtolower(array_pop($id));
return $id;
}
function renderAccessTitle(ResourceAbstract $r)
{
$title = $this->escape($r->title);
if (!empty($r->hide))
$title = "$title";
return $this->renderTd($title, false);
}
protected function initGridFields()
{
$this->addField(new Am_Grid_Field_Expandable('_access', ___('Products'), false))
->setPlaceholder(array($this, 'getPlaceholder'))
->setRenderFunction(array($this, 'renderProducts'))
->setGetFunction(array($this, 'getProducts'))
->setMaxLength(200);
$this->addField('_link', ___('Link'), false)->setRenderFunction(array($this, 'renderLink'));
$this->actionAdd(new Am_Grid_Action_SortContent());
parent::initGridFields();
}
public function renderLink(ResourceAbstract $resource)
{
$html = "";
$url = $resource->getUrl();
if (!empty($url))
$html = sprintf('%s',
$this->escape($url), ___('link'));
return $this->renderTd($html, false);
}
public function renderProducts($obj, $fieldName, $controller, $field)
{
return $this->renderTd($field->get($obj, $controller), false);
}
public function renderCategory(ResourceAbstract $e)
{
$res = array();
$options = $this->getDi()->resourceCategoryTable->getOptions();
foreach ($e->getCategories() as $resc_id)
{
$res[] = $options[$resc_id];
}
return $this->renderTd(implode(", ", $res));
}
public function getProducts(ResourceAbstract $resource)
{
$s = "";
foreach ($resource->getAccessList() as $access) {
$l = "";
if ($access->getStart())
$l .= " from " . $access->getStart();
if ($access->getStop())
$l .= " to " . $access->getStop();
$s .= sprintf("%s %s %s
\n", $access->getClassTitle(), $access->getTitle(), $l);
}
return $s;
}
public function getPlaceholder($val, ResourceAbstract $resource)
{
return ___('%d access records…', count($resource->getAccessList()));
}
public function afterInsert(array & $values, ResourceAbstract $record)
{
$record->setAccess($values['_access']);
}
public function _valuesToForm(array & $values, Am_Record $record)
{
$values['_access'] = $this->getRecord()->getAccessList();
}
public function renderPath(ResourceAbstractFile $file)
{
$upload = $file->getUpload();
try{
$file->isLocal();
} catch (Exception $e) {
if (!$upload)
return $this->renderTd(
'' . ___('The file has been removed from disk or corrupted. Please re-upload it.') . '' .
' (' . ___('Error from Storage Engine') . ': ' . $this->escape($e->getMessage()) . ')' .
'
' . ___('Real Path') . ': ' . $this->escape($file->path), false);
}
return $upload && !file_exists($upload->getFullPath()) ?
$this->renderTd(
'