示例#1
0
 public function checkUniqueAction($chars, $id = FALSE)
 {
     $query = 'SELECT ' . $this->name . ' FROM ' . PREFIX . $this->entity->getModule() . '_' . $this->entity->getName() . ' WHERE ' . $this->name . ' = :chars';
     $params = array(':chars' => $chars);
     if ($id !== FALSE && !empty($id)) {
         $query .= ' AND ' . $this->entity->getId()->name . ' != :id';
         $params[':id'] = $id;
     }
     $sth = \PDOconnection::getDB()->prepare($query);
     $sth->execute($params);
     if ($sth->fetch() === FALSE) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
示例#2
0
 /**
  * Build a pagination object
  * @param string $query
  * @param integer $itemsPerPage
  */
 public function __construct($query, $itemsPerPage = 10, $args = array())
 {
     $this->itemsPerPage = $itemsPerPage;
     if (!isset(self::$cache[$query]) || !empty($args)) {
         $page = PDOconnection::getDB()->prepare('SELECT count(*) FROM (' . $query . ') AS paginationtottal');
         /* subquery to allow us to count even there is a group by */
         $page->execute($args);
         if ($page) {
             $page = $page->fetch();
             $this->nbRow = $page[0];
             self::$cache[$query] = $this->nbRow;
         }
         $this->nbPages = ceil($this->nbRow / $itemsPerPage);
     }
     // Current Page
     $this->currentPage = app::$request->getParam('page');
     if (!$this->currentPage) {
         /* 0 <-! or FALSE */
         $this->currentPage = 1;
     }
 }
示例#3
0
 public function process($vars)
 {
     \app::removeListener('afterInsert');
     \app::removeListener('afterUpdate');
     $idEntity = $this->entity->getId()->name;
     $cutForeign = explode('_', $this->entity_foreign, 2);
     $foreignEntity = \app::getModule($cutForeign[0])->getEntity($cutForeign[1]);
     $idNameForeignEntity = $foreignEntity->getId()->name;
     $cutAsso = explode('_', $this->entity_asso, 2);
     $assoEntity = \app::getModule($cutAsso[0])->getEntity($cutAsso[1]);
     $idAsso = $assoEntity->getId()->name;
     /* Get old links */
     $old = array();
     foreach (\PDOconnection::getDB()->query('SELECT ' . PREFIX . $assoEntity->getTableName() . '.* FROM ' . PREFIX . $assoEntity->getTableName() . ' WHERE ' . $idEntity . ' = ' . $vars[':' . $idEntity], \PDO::FETCH_ASSOC) as $oldRows) {
         $old[$oldRows[$idNameForeignEntity]] = $oldRows[$idAsso];
     }
     /* Add new links */
     if (!empty($this->value) && is_array($this->value)) {
         /* is_array in case all items are removed and $this->value == "empty" */
         foreach ($this->value as $idForeign => $value) {
             if (isset($old[$idForeign])) {
                 unset($old[$idForeign]);
             } else {
                 if (substr($idForeign, 0, 3) === 'new') {
                     $idForeign = $foreignEntity->insertInto(array($idNameForeignEntity => '', $foreignEntity->getBehaviorTitle() => trim($value)), FALSE);
                 }
                 $assoEntity->insertInto(array($idAsso => '', $idEntity => $vars[':' . $idEntity], $idNameForeignEntity => $idForeign), FALSE);
             }
         }
     }
     /* Remove killed links */
     if (!empty($old)) {
         foreach ($old as $linkID) {
             $assoEntity->delete($linkID, FALSE);
         }
     }
 }
示例#4
0
 /**
  * Auth
  * @param string $login
  * @param string $password
  * @return bool
  */
 public static function authentication($login, $password)
 {
     if (\app::getModule('core')->getEntity('user')->pseudo()->validate($login) === FALSE || \app::getModule('core')->getEntity('user')->pass()->validate($password) === FALSE) {
         return FALSE;
     } else {
         $sth = PDOconnection::getDB()->prepare('SELECT pseudo, pass, id_user, ' . PREFIX . 'core_role.id_role, ' . PREFIX . 'core_role.permissions FROM ' . PREFIX . 'core_user INNER JOIN ' . PREFIX . 'core_role ON ' . PREFIX . 'core_user.id_role = ' . PREFIX . 'core_role.id_role WHERE pseudo = :pseudo AND ' . PREFIX . 'core_user.state = 1');
         $sth->execute(array(':pseudo' => $login));
         $obj = $sth->fetch();
         if (is_array($obj)) {
             $mdp = $obj['pass'];
             if ((string) $mdp === \sha1($password . \app::$config['security']['salt'])) {
                 $_SESSION['login'] = $login;
                 $_SESSION['id_user'] = (int) $obj['id_user'];
                 $_SESSION['id_role'] = (int) $obj['id_role'];
                 $_SESSION['permissions'] = (int) $obj['permissions'];
                 return TRUE;
             } else {
                 return FALSE;
             }
         } else {
             return FALSE;
         }
     }
 }
示例#5
0
    /**
     * Save model
     * @return string
     */
    protected function saveModelAction($module, $list, $oldSchema)
    {
        $schema = json_decode($list);
        $oldSchema = json_decode($oldSchema, TRUE);
        $tableExists = array();
        /* Get roles ids with behavior anonymous */
        $rolesBehaviorAnonymous = array();
        foreach (\app::getModule('core')->getEntity('role') as $role) {
            if ($role->permissions == 0) {
                $rolesBehaviorAnonymous[] = $role->id_role;
            }
        }
        if (is_array($schema)) {
            foreach ($schema as $tableKey => $table) {
                /* Prepare entity's properties */
                $tplProp = '';
                $tplParam = '';
                $tplAssign = '';
                $args = array();
                $matchOldNewNames = array();
                foreach ($table->properties as $fieldName => $fieldProps) {
                    list($name, $type) = explode(':', $fieldName);
                    $tplProp .= "\t" . 'protected $' . $name . ';' . PHP_EOL;
                    //generates attributes
                    $tplParam .= '\\' . $type . ' $' . $name . ',';
                    //generates the constructor parameters
                    $tplAssign .= "\t\t" . '$this->' . $name . ' = $' . $name . ";\n";
                    //generates assignments in the constructor
                    $reflectionObj = new \ReflectionClass($type);
                    $fieldProps = json_encode($fieldProps);
                    $fieldProps = json_decode($fieldProps, true);
                    if (isset($fieldProps['oldName']) && ($fieldProps['oldName'] != $name && !empty($fieldProps['oldName']))) {
                        $matchOldNewNames[$name] = $fieldProps['oldName'];
                    }
                    unset($fieldProps['oldName']);
                    $field = $reflectionObj->newInstanceArgs(array('name' => $fieldName, 'properties' => $fieldProps));
                    if (!isset($fieldProps['rights'])) {
                        /* Set rights forbidden for non admins, admins are allowed by default */
                        foreach ($rolesBehaviorAnonymous as $id_role) {
                            $field->setRights($id_role, 0);
                        }
                    }
                    $args[] = $field;
                }
                /* Prepare entity's php file */
                $tpl = '<?php
namespace ' . $module . '\\model;
/**
* Description of entity ' . $table->name . '
* @author Parsimony
* @top ' . $table->top . '
* @left ' . $table->left . '
*/
class ' . $table->name . ' extends \\entity {

' . $tplProp . '

	public function __construct(' . substr($tplParam, 0, -1) . ') {
		parent::__construct();
' . $tplAssign . '
	}
';
                $model = 'modules/' . $module . '/model/' . $table->name . '.php';
                if (!is_file($model)) {
                    $tpl .= '// DON\'T TOUCH THE CODE ABOVE ##########################################################' . PHP_EOL . '}' . PHP_EOL . '?>';
                } else {
                    $code = file_get_contents($model);
                    $tpl = preg_replace('@<\\?php(.*)}(.*)?(ABOVE ##########################################################)?@Usi', $tpl, $code);
                }
                \tools::file_put_contents($model, $tpl);
                include_once $model;
                $oldObjModel = FALSE;
                if (is_file('modules/' . $module . '/model/' . $table->oldName . '.' . \app::$config['dev']['serialization'])) {
                    $oldObjModel = \tools::unserialize('modules/' . $module . '/model/' . $table->oldName);
                }
                // Change table Name if changes
                if ($table->name !== $table->oldName) {
                    \PDOconnection::getDB()->exec('ALTER TABLE ' . PREFIX . $module . '_' . $table->oldName . ' RENAME TO ' . $module . '_' . $table->name . ';');
                    unlink('modules/' . $module . '/model/' . $table->oldName . '.php');
                    unlink('modules/' . $module . '/model/' . $table->oldName . '.' . \app::$config['dev']['serialization']);
                }
                // make a reflection object
                $reflectionObj = new \ReflectionClass($module . '\\model\\' . $table->name);
                $newObj = $reflectionObj->newInstanceArgs($args);
                $newObj->__wakeup();
                /* Set entity's properties */
                $newObj->setTitle($table->title);
                $newObj->behaviorTitle = $table->behaviorTitle;
                $newObj->behaviorDescription = $table->behaviorDescription;
                $newObj->behaviorKeywords = $table->behaviorKeywords;
                $newObj->behaviorImage = $table->behaviorImage;
                /* Set entity's rights */
                if (is_object($oldObjModel)) {
                    $newObj->setAllRights($oldObjModel->getAllRights());
                } else {
                    /* Set rights forbidden for non admins, admins are allowed by default */
                    foreach ($rolesBehaviorAnonymous as $id_role) {
                        $newObj->setRights($id_role, 0);
                    }
                }
                if ($oldObjModel !== FALSE) {
                    $nameFieldBefore = '';
                    $newObj->__wakeup();
                    /* to insert entity's ref into fields */
                    foreach ($newObj->getFields() as $field) {
                        if (isset($oldSchema[$table->name]) && isset($oldSchema[$table->name][$field->name])) {
                            $field->alterColumn($nameFieldBefore);
                        } elseif (isset($matchOldNewNames[$field->name])) {
                            $field->alterColumn($nameFieldBefore, $matchOldNewNames[$field->name]);
                        } else {
                            $field->addColumn($nameFieldBefore);
                        }
                        if ($field->type !== '') {
                            /* field_formasso */
                            $nameFieldBefore = $field->name;
                        }
                    }
                    if (isset($oldSchema[$table->name])) {
                        foreach ($oldSchema[$table->name] as $fieldName => $field) {
                            $newFields = $newObj->getFields();
                            if (!isset($newFields[$fieldName]) && !in_array($fieldName, $matchOldNewNames)) {
                                $sql = 'ALTER TABLE ' . PREFIX . $module . '_' . $table->name . ' DROP ' . $fieldName;
                                \PDOconnection::getDB()->exec($sql);
                                //$field->deleteColumn();  //removed to avoid old includes
                            }
                        }
                    }
                } else {
                    $newObj->createTable();
                }
                \tools::serialize('modules/' . $module . '/model/' . $table->name, $newObj);
                $tableExists[] = $table->name;
            }
        }
        $entities = glob('modules/' . $module . '/model/*.php');
        foreach (is_array($entities) ? $entities : array() as $filename) {
            $modelName = substr(substr(strrchr($filename, "/"), 1), 0, -4);
            if (!in_array($modelName, $tableExists)) {
                \app::getModule($module)->getEntity($modelName)->deleteTable();
            }
        }
        return ' ';
    }
示例#6
0
 // define url
 $selpage = 'select ' . PREFIX . 'blog_post.id_post, ' . PREFIX . 'blog_post.publicationGMT, ' . PREFIX . 'blog_post.url, ' . PREFIX . 'blog_post.has_comment from ' . PREFIX . 'blog_post where ' . PREFIX . 'blog_post.url =  "' . $url . '"';
 $qpage = \PDOconnection::getDB()->query($selpage);
 $result = $qpage->fetch();
 $has_comment = $result['has_comment'];
 $rowdate = $result['publicationGMT'];
 $entity = \app::getModule('blog')->getEntity('comment');
 $desc = '';
 // Number of items
 $desc = ' order by ' . PREFIX . 'blog_comment.id_comment ' . $configs['commentOrder'];
 $qcomment = 'select ' . PREFIX . 'blog_comment.id_comment, ' . PREFIX . 'blog_comment.author, ' . PREFIX . 'blog_comment.author_ip, ' . PREFIX . 'blog_comment.date, ' . PREFIX . 'blog_comment.content, ' . PREFIX . 'blog_comment.status, ' . PREFIX . 'blog_comment.id_user, ' . PREFIX . 'blog_comment.id_parent, ' . PREFIX . 'blog_comment.author_email from ' . PREFIX . 'blog_comment where ' . PREFIX . 'blog_comment.id_post =  ' . $idpage . ' AND ' . PREFIX . 'blog_comment.status = 1 ' . $desc;
 if (is_numeric($configs['items'])) {
     $qcomment .= ' limit 0, ' . $configs['items'] . '';
 }
 // Query approved comments
 $comments = \PDOconnection::getDB()->query($qcomment);
 // if config provides that comments must be automatically closed on articles after X days
 $days = $configs['closeAfterDays'];
 if (\app::getModule('blog')->getEntity('comment')->olderComments($rowdate, $days) == TRUE) {
     if ($has_comment == '1') {
         $heldFormoderation = $configs['alwaysApprove'];
         if ($heldFormoderation == '1') {
             $notify = t('Your comment is held for moderation');
         } else {
             $notify = t('Your comment is approved');
         }
         if (isset($_POST['add'])) {
             $_POST['blog_comment']['id_post'] = $idpage;
             $res = $entity->insertInto($_POST);
             if ($res === TRUE || is_numeric($res)) {
                 echo '<div class="notify positive">' . $notify . '</div>';
示例#7
0
 * to license@parsimony.mobi so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.parsimony.mobi for more information.
 *
 * @authors Julien Gras et Benoît Lorillot
 * @copyright Julien Gras et Benoît Lorillot
 * 
 * @category Parsimony
 * @package blog/blocks
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */
$tags = \PDOconnection::getDB()->query('SELECT ' . PREFIX . 'blog_tag.name, ' . PREFIX . 'blog_tag.url, COUNT( ' . PREFIX . 'blog_tag.name ) AS nb
FROM ' . PREFIX . 'blog_tag INNER JOIN ' . PREFIX . 'blog_tag_post ON ' . PREFIX . 'blog_tag.id_tag = ' . PREFIX . 'blog_tag_post.id_tag
GROUP BY ' . PREFIX . 'blog_tag.name ORDER BY nb DESC LIMIT 0 , 30');
if (is_object($tags)) {
    $tags = $tags->fetchAll(\PDO::FETCH_ASSOC);
    if (isset($tags[0]['nb'])) {
        $nbMax = $tags[0]['nb'];
        echo '<ul>';
        foreach ($tags as $key => $tag) {
            $percent = floor($tag['nb'] / $nbMax * 100);
            if ($percent < 20) {
                $size = 'xsmall';
            } elseif ($percent >= 20 and $percent < 40) {
                $size = 'small';
            } elseif ($percent >= 40 and $percent < 60) {
                $size = 'medium';
示例#8
0
 public function afterInsert($vars)
 {
     $configs = \app::getModule('blog')->getConfigs();
     $reqhold = 'SELECT count(' . PREFIX . 'blog_comment.id_comment) from ' . PREFIX . 'blog_comment where ' . PREFIX . '.blog_comment.status = 0';
     $hold = \PDOconnection::getDB()->query($reqhold)->fetch();
     $holdcomments = $hold[0];
     if ($holdcomments == '') {
         $holdcomments = 0;
     }
     if (isset($vars[':author'])) {
         $author = $vars[':author'];
     }
     if (isset($vars[':author_email'])) {
         $author_email = $vars[':author_email'];
     }
     $id_comment = $vars[':id_comment'];
     $id_post = $vars[':id_post'];
     $author_ip = $vars[':author_ip'];
     $author_url = $vars[':author_url'];
     $content = $vars[':content'];
     $remote = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $author_ip;
     $postquery = "SELECT blog_post.title, blog_post.url from blog_post where id_post =" . $id_post;
     $posttitle = '';
     $posturl = '';
     $params = \PDOconnection::getDB()->query($postquery);
     foreach ($params as $param) {
         $posttitle = $param['title'];
         $posturl = $param['url'];
     }
     // Email me when anyone posts a comment mailForAnyPost or a comment is held for moderation
     if ($configs['mailForAnyPost'] == '1' || $configs['heldModeration'] == '1' && $vars[':status'] == '0') {
         // if block config provides mailing before moderation
         $titre = utf8_decode('Comment Moderation for ' . $posttitle . ' (' . $vars[':date'] . ')');
         $message = t('A new comment on', FALSE) . ' ' . $posttitle . ' ' . t('is held for moderation', FALSE);
         $message .= '<br><A href="' . $posturl . '">' . $posturl . '</A><br>';
         $message .= '<br>' . isset($vars[':author']) ? t('Author :') . $author : '' . t('(IP :') . $author_ip . ',' . $remote . ' )';
         if (isset($vars[':author_email'])) {
             $message .= '<br>' . t('E-mail :') . '<A href="mailto:' . $author_email . '">' . $author_email . '</A>';
         }
         $message .= '<br>' . t('Website :') . $author_url;
         $message .= '<br>' . t('Whois :') . '<A href="' . 'http://whois.arin.net/rest/ip/' . $author_ip . '">' . 'http://whois.arin.net/rest/ip/' . $author_ip . '</a>';
         $message .= '<br>' . t('Comment :') . $content . '<br>' . t('ID Comment') . $id_comment;
         $message .= '<br>' . '<A href="' . BASE_PATH . 'index#modules/model/blog/comment">' . BASE_PATH . 'index#modules/model/blog/comment</a>';
         $message .= '<br>' . t('Right now, ' . $holdcomments . ' comments await your approval', false) . '.';
         $message = utf8_decode($message);
         $adminmail = \app::$config['mail']['adminMail'];
         ob_start();
         include 'blog/views/mail/moderationmail.php';
         $body = ob_get_clean();
         if (\tools::sendMail($adminmail, '' . $adminmail . '', '' . $adminmail . '', $titre, $body)) {
             return true;
         } else {
             return false;
         }
     }
     // else config provides mailing after previous approved comment
     if ($configs['previousComment'] == '1' && $vars[':status'] == '1') {
         $titre = utf8_decode('Approved comment for ' . $posttitle . ' (' . $vars[':date'] . ')');
         $message = t('New approved comment on', FALSE) . ' ' . $posttitle;
         $message .= '<br><A href="' . $posturl . '">' . $posturl . '</A><br>';
         $message .= '<br>' . isset($vars[':author']) ? t('Author :') . $author : '' . t('(IP :') . $author_ip . ',' . $remote . ' )';
         if (isset($vars[':author_email'])) {
             $message .= '<br>' . t('E-mail :') . '<A href="mailto:' . $author_email . '">' . $author_email . '</A>';
         }
         $message .= '<br>' . t('Website :') . $author_url;
         $message .= '<br>' . t('Whois :') . '<A href="' . 'http://whois.arin.net/rest/ip/' . $author_ip . '">' . 'http://whois.arin.net/rest/ip/' . $author_ip . '</a>';
         $message .= '<br>' . t('Comment :') . $content . '<br>' . t('ID Comment') . $id_comment;
         $message .= '<br>' . '<A href="' . BASE_PATH . 'index#modules/model/blog/comment">' . BASE_PATH . 'index#modules/model/blog/comment</a>';
         $message .= '<br>' . t('Right now, ' . $holdcomments . ' comments await your approval', false) . '.';
         $message = utf8_decode($message);
         $adminmail = \app::$config['mail']['adminMail'];
         ob_start();
         include 'blog/views/mail/moderationmail.php';
         $body = ob_get_clean();
         if (\tools::sendMail($adminmail, '' . $adminmail . '', '' . $adminmail . '', $titre, $body)) {
             return true;
         } else {
             return false;
         }
     }
 }
示例#9
0
$next_month = $thisMonth + 1;
if ($prev_month <= 0) {
    $prev_month = 12;
    $prev_year = $thisYear - 1;
}
if ($next_month >= 13) {
    $next_month = 1;
    $next_year = $thisYear + 1;
}
$firstDayOfMonth = mktime(0, 0, 0, $thisMonth, 1, $thisYear);
$maxday = date('t', $firstDayOfMonth);
$daysOfThisMonth = array();
for ($i = 1; $i <= $maxday; $i++) {
    $daysOfThisMonth[$i] = 0;
}
$query = \PDOconnection::getDB()->prepare('SELECT publicationGMT FROM ' . PREFIX . 'blog_post WHERE publicationGMT BETWEEN :datestart AND :dateend');
$query->execute(array(':datestart' => gmdate('Y-m-d H:i:s', $firstDayOfMonth), ':dateend' => gmdate('Y-m-d H:i:s', mktime(0, 0, 0, $thisMonth, $maxday, $thisYear))));
$recposts = $query->fetchAll(\PDO::FETCH_ASSOC);
if (!empty($recposts) !== FALSE) {
    foreach ($recposts as $key => $post) {
        $daysOfThisMonth[date('j', strtotime($post['publicationGMT']))]++;
    }
}
?>
<div class="calendar">
    <div class="monthTitle"><?php 
echo t($monthNames[$thisMonth - 1]) . ' ' . $thisYear;
?>
</div>
	<div class="calendarInner">
		<div class="weekTitle">
示例#10
0
 /**
  * Delete in DB 
  * @param int $id
  * @return bool
  */
 public function delete($id, $mainEntity = TRUE)
 {
     if ($this->getRights($_SESSION['id_role']) & DELETE) {
         if ($mainEntity === TRUE) {
             \PDOconnection::getDB()->beginTransaction();
         }
         if ($this->beforeDelete($id) === FALSE) {
             return FALSE;
         }
         $query = 'DELETE FROM ' . PREFIX . $this->_tableName . ' WHERE ' . $this->getId()->name . ' = :id';
         $sth = PDOconnection::getDB()->prepare($query);
         $res = $sth->execute(array(':id' => $id));
         if ($res !== FALSE) {
             $this->afterDelete($id);
             \app::dispatchEvent('afterDelete', array(&$this));
             if (!empty($this->_extends)) {
                 foreach ($this->_extends as $entity) {
                     $resExtend = $entity->delete($id, FALSE);
                     if ($resExtend !== TRUE) {
                         return $resExtend;
                     }
                 }
             }
             if ($mainEntity === TRUE) {
                 \PDOconnection::getDB()->commit();
             }
             return $res;
         }
         \PDOconnection::getDB()->rollBack();
         return FALSE;
     } else {
         throw new \Exception(t('Delete forbidden on ' . $this->_tableName, FALSE));
     }
 }
示例#11
0
 /**
  * Build the query and his PDO statement with SQL infos already set to this object
  * @return bool
  */
 public function buildQuery($forceRebuild = FALSE)
 {
     if (!isset($this->_SQL['stmt']) || $forceRebuild) {
         /* exec query once a page load */
         \app::dispatchEvent('beforeBuildQuery', array());
         /* SELECT */
         $query = 'SELECT ';
         if ($this instanceof \entity) {
             /* only for entity, to define defaults selects && from */
             $this->beforeSelect();
             if (empty($this->_SQL['selects'])) {
                 $this->_SQL['selects'][$this->_tableName . '.*'] = $this->_tableName . '.*';
             }
             $this->_SQL['froms'][$this->_tableName] = $this->_tableName;
             /* FROM for entity */
             /*  extends */
             if (!empty($this->_extends)) {
                 foreach ($this->_extends as $entity) {
                     $foreignFields = $entity->getFields();
                     foreach ($foreignFields as $name => &$field) {
                         if ($name !== $field->name) {
                             /* detect alias */
                             $tableName = $field->getTableName();
                             $aliasName = $name . '_' . $tableName;
                             $this->_SQL['selects'][$aliasName] = $tableName . '.' . $name . ' AS ' . $aliasName;
                         } else {
                             $this->_SQL['selects'][$name] = $field->getTableName() . '.' . $name;
                             /* best than "table.*" which bug when using alias ( duplicate) */
                         }
                     }
                     $foreignTableName = str_replace('\\model\\', '_', get_class($entity));
                     $this->join($this->_tableName . '.' . $this->getId()->name, $foreignTableName . '.' . $entity->getId()->name, 'left outer join');
                 }
             }
         }
         foreach ($this->getFields() as $field) {
             /* TODO IMPROVE */
             if (!$field instanceof \core\fields\alias) {
                 $module = $field->entity->getModule();
                 $entity = $field->entity->getName();
                 $id = $field->entity->getId()->name;
                 if ($field instanceof \field_formasso) {
                     $cutForeign = explode('_', $field->entity_foreign, 2);
                     $foreignEntity = \app::getModule($cutForeign[0])->getEntity($cutForeign[1]);
                     $idNameForeignEntity = $foreignEntity->getId()->name;
                     $this->_SQL['selects'][$field->name] = ' CONCAT(  \'{\', GROUP_CONCAT(CONCAT(\'"\', ' . $field->entity_foreign . '.' . $idNameForeignEntity . ' , \'"\',\':"\',' . $field->entity_foreign . '.' . $foreignEntity->getBehaviorTitle() . ', \'"\')), \'}\') AS ' . $field->name;
                     $this->groupBy($module . '_' . $entity . '.' . $id);
                     $this->join($module . '_' . $entity . '.' . $id, $field->entity_asso . '.' . $field->entity->getId()->name, 'left outer join');
                     $this->join($field->entity_asso . '.' . $idNameForeignEntity, $field->entity_foreign . '.' . $idNameForeignEntity, 'left outer join');
                 } elseif ($this->getField($id) === FALSE) {
                     $this->select($module . '_' . $entity . '.' . $id, TRUE);
                 }
             }
         }
         $query .= implode(',', $this->_SQL['selects']);
         /* FROM */
         if (empty($this->_SQL['joins'])) {
             $query .= ' FROM ' . reset($this->_SQL['froms']);
         } else {
             $firstTable = reset($this->_SQL['joins']);
             $tableLeft = strstr($firstTable['propertyLeft'], '.', true);
             $query .= ' FROM ' . $tableLeft;
             $this->_SQL['froms'][$tableLeft] = $tableLeft;
             //to prefix $tableLeft
             foreach ($this->_SQL['joins'] as $join) {
                 $tableRight = strstr($join['propertyRight'], '.', true);
                 $this->_SQL['froms'][$tableRight] = $tableRight;
                 //to prefix $tableRight
                 $query .= ' ' . $join['type'] . ' ' . $tableRight . ' ON ' . $join['propertyLeft'] . ' = ' . $join['propertyRight'];
             }
         }
         /* WHERE */
         $this->_SQL['vars'] = array();
         // init here for pagination
         if (isset($this->_SQL['wheres'])) {
             $wheres = array();
             foreach ($this->_SQL['wheres'] as $where) {
                 // Frame the "where" if several sql conditions
                 /* For the record if(strstr($where,'&&') || strstr($where,'||') || stristr($where,' or ') || stristr($where,' and ')) $wheres[] = */
                 $wheres[] = '(' . $this->evaluateConditions($where) . ')';
             }
             if (!empty($wheres)) {
                 $query .= ' WHERE ' . implode(' AND ', $wheres);
             }
         }
         /* GROUP BY */
         if (isset($this->_SQL['groupBys'])) {
             $query .= ' GROUP BY ' . implode(' ,', $this->_SQL['groupBys']);
         }
         /* HAVING */
         if (isset($this->_SQL['havings'])) {
             $havings = array();
             foreach ($this->_SQL['havings'] as $having) {
                 // Frame the "having" if several sql conditions
                 $havings[] = '(' . $this->evaluateConditions($having) . ')';
             }
             if (!empty($havings)) {
                 $query .= ' HAVING ' . implode(' AND ', $havings);
             }
         }
         /* ORDER */
         if (isset($this->_SQL['orders'])) {
             $orders = array();
             foreach ($this->_SQL['orders'] as $property => $order) {
                 $orders[] = $property . ' ' . $order;
             }
             $query .= ' ORDER BY ' . implode(',', $orders);
         }
         /* DB PREFIX */
         if (PREFIX !== '') {
             /* must be before pagination */
             $query .= ' ';
             /* tip to replace table name */
             foreach ($this->_SQL['froms'] as $table) {
                 $query = preg_replace('/([,\\s\\(])' . $table . '([\\.\\s])/', '$1' . PREFIX . $table . '$2', $query);
             }
         }
         /* LIMIT */
         if (isset($this->_SQL['limit'])) {
             $limit = ' LIMIT 0,' . $this->_SQL['limit'];
             if (isset($this->_SQL['pagination']) && $this->_SQL['pagination'] !== FALSE) {
                 $this->_SQL['pagination'] = new \pagination($query, $this->_SQL['limit'], $this->_SQL['vars']);
                 $start = $this->_SQL['pagination']->getCurrentPage() * $this->_SQL['limit'] - $this->_SQL['limit'];
                 $limit = ' LIMIT ' . $start . ',' . $this->_SQL['limit'];
             }
             $query .= $limit;
         }
         $this->_SQL['query'] = $query;
     }
     /* EXEC query */
     if (!empty($this->_SQL['vars'])) {
         $this->_SQL['stmt'] = \PDOconnection::getDB()->prepare($this->_SQL['query']);
         $this->_SQL['stmt']->setFetchMode(\PDO::FETCH_INTO, $this);
         $this->_SQL['stmt']->execute($this->_SQL['vars']);
     } else {
         $this->_SQL['stmt'] = \PDOconnection::getDB()->query($this->_SQL['query'], \PDO::FETCH_INTO, $this);
     }
     return $this->_SQL['stmt'];
 }
示例#12
0
 public function getAllValues()
 {
     $table = $this->getTableName();
     $result = \PDOconnection::getDB()->query('select ' . PREFIX . $table . '.' . $this->name . ' from ' . PREFIX . $table . ' group by ' . PREFIX . $table . '.' . $this->name);
     if (is_object($result)) {
         $values = $result->fetchAll(\PDO::FETCH_COLUMN);
         if (is_array($values)) {
             $values = array_combine($values, $values);
             return $values;
         }
     }
     return array();
 }
示例#13
0
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Parsimony to newer
 * versions in the future. If you wish to customize Parsimony for your
 * needs please refer to http://www.parsimony.mobi for more information.
 *
 * @authors Julien Gras et Benoît Lorillot
 * @copyright Julien Gras et Benoît Lorillot
 * 
 * @category Parsimony
 * @package core/fields
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */
echo $this->displayLabel($fieldName);
$foreignID = $this->value;
$sth = PDOconnection::getDB()->query('SELECT * FROM ' . PREFIX . $this->moduleLink . '_' . $this->link);
// used ->getEntity() but there was interference because of cache
if (is_object($sth)) {
    $sth->setFetchMode(PDO::FETCH_OBJ);
    echo '<select name="' . $tableName . '[' . $this->name . ']">';
    if (!$this->required) {
        echo '<option></option>';
    }
    $properties = app::getModule($this->moduleLink)->getEntity($this->link)->getFields();
    foreach ($sth as $key => $row) {
        $text = $this->templatelink;
        foreach ($properties as $key => $field) {
            if (get_class($field) == \app::$aliasClasses['field_ident']) {
                $id = $key;
            }
            if (isset($row->{$key})) {
示例#14
0
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.parsimony.mobi for more information.
 *
 * @authors Julien Gras et Benoît Lorillot
 * @copyright Julien Gras et Benoît Lorillot
 * 
 * @category Parsimony
 * @package blog/blocks
 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */
if ($this->getConfig('items')) {
    $items = $this->getConfig('items');
} else {
    $items = 5;
}
$recposts = \PDOconnection::getDB()->query('select ' . PREFIX . 'blog_post.id_post,' . PREFIX . 'blog_post.title,' . PREFIX . 'blog_post.url from ' . PREFIX . 'blog_post order by ' . PREFIX . 'blog_post.id_post desc LIMIT 0 , ' . $items . '');
if (is_object($recposts)) {
    $recposts = $recposts->fetchAll(\PDO::FETCH_ASSOC);
    ?>
 

<ul>
<?php 
    foreach ($recposts as $key => $recentpost) {
        ?>
	<li class="recentposts">
            <a href="<?php 
        echo BASE_PATH . $recentpost['url'];
        ?>
"><?php 
        echo $recentpost['title'];
示例#15
0
    /**
     * Delete a column 
     * @return bool
     */
    public function deleteColumn()
    {
        return \PDOconnection::getDB()->exec('ALTER TABLE ' . $this->entity->getModule() . '_' . $this->entity->getName() . ' DROP ' . $this->name . ';
			ALTER TABLE ' . $this->entity->getModule() . '_' . $this->entity->getName() . ' DROP ' . $this->name . '_status' . ';
			ALTER TABLE ' . $this->entity->getModule() . '_' . $this->entity->getName() . ' DROP ' . $this->name . '_visibility');
    }