/** * Return render value * (non-PHPdoc) * @see \Engine\Crud\Grid\Column::render() * @param mixed $row * @return string */ public function render($row) { if ($this->_template) { $image = \Engine\Tools\String::generateStringTemplate($this->_template, $row, '{', '}'); } else { $image = $this->_empty; } return $this->createImage($image); }
/** * Return render value * (non-PHPdoc) * @see \Engine\Crud\Grid\Column::render() * @param mixed $row * @return string */ public function render($row) { $attribs = $this->getAttribs(); $href = \Engine\Tools\String::generateStringTemplate($this->_template, $row, '{', '}'); $code = '<a href="' . $href . '"'; foreach ($attribs as $name => $value) { $code .= ' ' . $name . '="' . $value . '"'; } $title = \Engine\Tools\String::generateStringTemplate($this->_templateTitle, $row, '{', '}'); $code .= '><span>' . $title . '</span></a>'; return $code; }
/** * (non-PHPdoc) * @see Crud\Form\Field.Field::getRenderValue() */ public function getRenderValue() { $value = $this->getValue(); $values = $this->_form->getData(); $source = \Engine\Tools\String::generateStringTemplate($this->_renderTemplate, $values, '{', '}'); if ($source === false) { return $value; } $values = $this->_form->getRenderData(); $label = \Engine\Tools\String::generateStringTemplate($this->_labelTemplate, $values, '{' . '}'); $class = $this->getAttrib('class'); $xhtml = $this->createImage($source, $label, $class); return $xhtml; }
/** * Set options * * @return void */ protected function _setCount($params = null) { $queryBuilder = $this->_getModel()->queryBuilder(); if (isset($params['name'])) { $name = $params['name']; $names = explode($this->_separator, $name); $names = \Engine\Tools\String::quote($names); $queryBuilder->columnsName(); $queryBuilder->where("name IN (" . $names . ")"); } elseif (isset($params['query'])) { $name = $params['name']; $name = trim($params['query']); $queryBuilder->columnsName(); $queryBuilder->where("name LIKE '" . $name . "%'"); } $queryBuilder->setColumn("COUNT(id)", "count", false); if ($params) { } $result = $queryBuilder->getQuery()->execute(); $this->_count = $result[0]['count']; }
/** * Return decrypt password * * @return string */ public function getDecryptValue() { //Create an instance $crypt = new \Phalcon\Crypt(); $crypt->setCipher($this->_cryptType); $key = \Engine\Tools\String::generateStringTemplate($this->_keyTemplate, $this->_form->getData(), '{', '}'); $value = $this->_value; return $crypt->decryptBase64($value, $key); }
/** * Delete rows by id values. * * @param string|array $ids * @param \Phalcon\DiInterface $di * @param \Phalcon\Events\ManagerInterface $eventsManager * @return string */ public static function deleteRows($params, $key, \Phalcon\DiInterface $di = null, \Phalcon\Events\ManagerInterface $eventsManager = null) { $result = ['success' => false, 'error' => []]; if (is_string($params)) { if (!\Engine\Tools\String::isJson($params)) { $result['error'][] = 'Params not valid'; return $result; } $params = json_decode($params); } if (is_array($params)) { if (!isset($params[$key]) && !is_array($params[$key])) { $result['error'][] = 'Array params not valid'; return $result; } $rows = !isset($rows[0]) ? [$params[$key]] : $params[$key]; } elseif ($params instanceof \stdClass) { if (!isset($params->{$key})) { $result['error'][] = 'Object params not valid'; return $result; } $rows = is_object($params->{$key}) ? [(array) $params->{$key}] : $params->{$key}; } else { $result['error'][] = 'Params not valid'; return $result; } $false = false; $form = new static(null, [], $di, $eventsManager); if (!$form->isRemovable()) { $result['error'][] = 'Data can\'t be remove from this form'; } $primary = $form->getPrimaryField(); if (!$primary) { throw new \Engine\Exception('Primary field not found'); } $primaryKey = $primary->getKey(); foreach ($rows as $id) { if (is_array($id)) { if (!isset($id[$primaryKey])) { throw new \Engine\Exception('Primary key not found in params'); } $id = $id[$primaryKey]; } elseif (is_object($id)) { if (!isset($id->{$primaryKey})) { throw new \Engine\Exception('Primary key not found in params'); } $id = $id->{$primaryKey}; } $resultRow = $form->delete($id); if ($resultRow === false) { $false = true; //$result['error'] = array_merge($result['error'], $rowResult['error']); } } if (!$false) { $result['success'] = true; $result['msg'] = "Deleted"; } return $result; }
/** * Find records by array of ids * * @param string $column * @param string|array $values * @return \Phalcon\Mvc\Model\ResultsetInterface */ public static function findByColumn($column, $values) { $model = new static(); $db = $model->getWriteConnection(); if (is_array($values)) { $values = \Engine\Tools\String::quote($values); $credential = $column . " IN (" . $values . ")"; } else { $credential = $column . " = " . $db->escapeString($values); } return static::find($credential); }
/** * Generate form item link from link template * * @return string */ public function getLink() { if (!$this->_linkTemplate) { return false; } return \Engine\Tools\String::generateStringTemplate($this->_linkTemplate, $this->getData(), "{", "}"); }
/** * Set grid params * * @param array $params * @return \Engine\Crud\Grid */ public function setParams(array $params) { $sort = $this->getSortParamName(); $direction = $this->getSortDirectionParamName(); if (isset($params[$sort])) { if (\Engine\Tools\String::isJson($params[$sort])) { $sortParams = json_decode($params[$sort])[0]; $params[$sort] = $sortParams->property; $params[$direction] = $sortParams->direction; } $this->_sortParamValue = $params[$sort]; } if (isset($params[$direction])) { $this->_directionParamValue = $params[$direction]; } $limit = $this->getLimitParamName(); if (isset($params[$limit])) { $this->_limitParamValue = $params[$limit]; } $page = $this->getPageParamName(); if (isset($params[$page])) { $this->_pageParamValue = $params[$page]; } $this->_params = $params; return $this; }
/** * Normalize form field value * * @param string|array $value * @return mixed */ public function normalizeValue($value) { return \Engine\Tools\String::formSpecialChars($value); }
/** * After save field trigger * * @param array $data */ public function postSaveAction(array $data) { $key = $this->getKey(); if (empty($_FILES) || !isset($_FILES[$key]) || !empty($_FILES[$key]['error'])) { return false; } $fullName = $this->_template; if (!$fullName) { $file = explode(".", $_FILES[$key]['name']); $fullName = $file[0]; } if (strpos($fullName, '{sha}') !== false) { $file_hash_name = $this->sha1 ? $this->sha1($this->getId()) : $this->getId(); $fullName = str_replace('{sha}', $file_hash_name, $fullName); } $uploadDirectory = rtrim(\Engine\Tools\String::generateStringTemplate($this->_uploadDirectory, $data, '{', '}'), "/)"); $fullName = \Engine\Tools\String::generateStringTemplate($fullName, $data, '{', '}'); $fileType = strtolower(end(explode(".", $_FILES[$key]['name']))); $fullName = $fullName . '.' . $fileType; $zend_upload_dir = $uploadDirectory; $fullName = $uploadDirectory . '/' . $fullName; $pathinfo = pathinfo($fullName); $uploadDirectory = $pathinfo['dirname']; $fileName = $pathinfo['basename']; /* Debuger: */ /* echo '$fileType = '.$fileType."\n"; echo '$this->fileName = '.$this->fileName."\n"; echo '$this->uploadDirectory = '.$this->uploadDirectory."\n"; echo '$fullName = '.$fullName."\n"; exit; */ if (!is_dir($uploadDirectory)) { mkdir($uploadDirectory, 0755, true); } if (file_exists($fullName)) { unlink($fullName); } if (is_uploaded_file($_FILES[$key]['tmp_name'])) { $result = move_uploaded_file($_FILES[$key]['tmp_name'], $fullName); } elseif (is_file($zend_upload_dir . '/' . $_FILES[$key]['name'])) { $result = rename($zend_upload_dir . '/' . $_FILES[$key]['name'], $fullName); } $def_data = [$this->_name => $fileName]; $container = $this->_form->getContainer(); $result = $container->update($this->_id, $def_data); $_FILES[$key]['name'] = $fileName; }